如何使用Chrome扩展模仿调试控制台的功能。

huangapple go评论112阅读模式
英文:

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

  1. {
  2. "manifest_version": 3,
  3. "name": "hoge",
  4. "version": "1.0",
  5. "action": {
  6. "default_popup": "popup.html"
  7. },
  8. "permissions": [
  9. "scripting"
  10. ],
  11. "host_permissions": [
  12. "<all_urls>"
  13. ]
  14. }

popup.html

  1. <html>
  2. <body>
  3. <script src="popup.js"></script>
  4. </body>
  5. </html>

popup.js

  1. hoge = () => {
  2. Calc.setExpression({ "id": "0", "latex": "x = y" })
  3. }
  4. chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
  5. chrome.scripting.executeScript(
  6. {
  7. target: { tabId: tabs[0].id },
  8. world: "MAIN",
  9. func: hoge
  10. }
  11. );
  12. });
英文:

Here is a sample of it.

manifest.json

  1. {
  2. &quot;manifest_version&quot;: 3,
  3. &quot;name&quot;: &quot;hoge&quot;,
  4. &quot;version&quot;: &quot;1.0&quot;,
  5. &quot;action&quot;: {
  6. &quot;default_popup&quot;: &quot;popup.html&quot;
  7. },
  8. &quot;permissions&quot;: [
  9. &quot;scripting&quot;
  10. ],
  11. &quot;host_permissions&quot;: [
  12. &quot;&lt;all_urls&gt;&quot;
  13. ]
  14. }

popup.html

  1. &lt;html&gt;
  2. &lt;body&gt;
  3. &lt;script src=&quot;popup.js&quot;&gt;&lt;/script&gt;
  4. &lt;/body&gt;
  5. &lt;/html&gt;

popup.js

  1. hoge = () =&gt; {
  2. Calc.setExpression({ &quot;id&quot;: &quot;0&quot;, &quot;latex&quot;: &quot;x = y&quot; })
  3. }
  4. chrome.tabs.query({ active: true, currentWindow: true }, (tabs) =&gt; {
  5. chrome.scripting.executeScript(
  6. {
  7. target: { tabId: tabs[0].id },
  8. world: &quot;MAIN&quot;,
  9. func: hoge
  10. }
  11. );
  12. });

huangapple
  • 本文由 发表于 2023年5月7日 15:14:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192630.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定