英文:
How to mimic the capability of the debug console with a chrome extension
问题
我正在尝试开发一个Chrome扩展,用于Desmos。我的扩展需要一种方法来更新左侧的方程单元格。手动执行此操作的一种方法是打开Chrome开发者工具控制台,并与预定义变量Calc
进行交互(尝试Calc.setExpression({"id": "0", "latex": "x = y"})
)。理想情况下,我想要在我的Chrome扩展中使用类似的功能,但我还没有找到如何实现的方法。我尝试查看了API,但它只在将Desmos图嵌入您自己的网站时才有用。我应该如何做到这一点?
英文:
I am trying to develop a chrome extension for Desmos. My extension needs a way to update the equation cells on the left. One way to do this manually is to open the chrome devtools console and interface with a predefined variable Calc
(try Calc.setExpression({"id": "0", "latex": "x = y"})
). Ideally, I want to have some sort of a similar functionality that I can use in my chrome extension but I have not found a way to do so. I tried looking through the api, but it is only useful if you are embedding Desmos graphs in your own website. How should I do this?
答案1
得分: 1
以下是您提供的内容的中文翻译:
manifest.json
{
"manifest_version": 3,
"name": "hoge",
"version": "1.0",
"action": {
"default_popup": "popup.html"
},
"permissions": [
"scripting"
],
"host_permissions": [
"<all_urls>"
]
}
popup.html
<html>
<body>
<script src="popup.js"></script>
</body>
</html>
popup.js
hoge = () => {
Calc.setExpression({ "id": "0", "latex": "x = y" })
}
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.scripting.executeScript(
{
target: { tabId: tabs[0].id },
world: "MAIN",
func: hoge
}
);
});
英文:
Here is a sample of it.
manifest.json
{
"manifest_version": 3,
"name": "hoge",
"version": "1.0",
"action": {
"default_popup": "popup.html"
},
"permissions": [
"scripting"
],
"host_permissions": [
"<all_urls>"
]
}
popup.html
<html>
<body>
<script src="popup.js"></script>
</body>
</html>
popup.js
hoge = () => {
Calc.setExpression({ "id": "0", "latex": "x = y" })
}
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.scripting.executeScript(
{
target: { tabId: tabs[0].id },
world: "MAIN",
func: hoge
}
);
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论