&quot“ chrome.runtime.reload不是函数”尝试livereload我的延长运行时

发布于 2025-01-22 13:25:34 字数 1269 浏览 1 评论 0原文

我正在构建Chrome扩展名,并将其与livereload-js集成在一起。它正在工作,除了调用chrome.runtime.reload()引发了reload不存在chrome.runtime Reload的错误/代码>。这很奇怪,因为文档说该方法应该在那里,并且当我阅读重新加载方法的文档它说该方法应无需任何其他许可即可提供。如果在清单版本第3版中删除了这一点,则尚未在文档中进行解释。

为了简化我已从应用程序中删除了大部分代码,并且只是试图使LiverEload上班。这是我的subtest.json

{
    "name": "Cool AF",
    "description": "something cool",
    "version": "1.1",
    "manifest_version": 3,
    "background": {
        "service_worker": "background.js"
    },
    "content_scripts": [
        {
            "matches": ["https://nevermind/*"],
            "css": ["main.css"],
            "js": ["main.js", "livereload.js"]
        }
    ],
    "host_permissions": ["http://localhost:35729/"],
    "permissions": ["storage", "management", "activeTab", "alarms", "background"]
}

livereload.js中的代码考虑是否是Chrome扩展名,并调用chrome.runtime.reload() ,这引发了错误。除了console.log,我已经从扩展名中删除了所有其他代码,让我知道扩展名正在加载。关于如何获得重新加载函数出现在chrome.runtime对象上的任何想法?

I am building a chrome extension, and have integrated it with livereload-js. It is working, except that the call to chrome.runtime.reload() throws an error that the function reload doesn't exist on the chrome.runtime. This is weird, since the documentation says that this method should be there and when I read the the docs for the reload method it says that this method should be available without any additional permissions needed. If this was removed in Manifest version 3, it hasn't been explained in the docs.

To simplify I have removed most of the code from the app, and am simply trying to get the livereload to work. Here is my manifest.json:

{
    "name": "Cool AF",
    "description": "something cool",
    "version": "1.1",
    "manifest_version": 3,
    "background": {
        "service_worker": "background.js"
    },
    "content_scripts": [
        {
            "matches": ["https://nevermind/*"],
            "css": ["main.css"],
            "js": ["main.js", "livereload.js"]
        }
    ],
    "host_permissions": ["http://localhost:35729/"],
    "permissions": ["storage", "management", "activeTab", "alarms", "background"]
}

The code in livereload.js considers if it is a chrome extension and calls chrome.runtime.reload(), which throws an error. I have removed all other code from the extension besides a console.log that let's me know the extension is loading. Any ideas on how to get the reload function to appear on the chrome.runtime object?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往昔成烟 2025-01-29 13:25:34

chrome.runtime.reload不适合内容脚本。

请参阅文档用于内容脚本可用的方法列表; 一些 chrome.runtime方法是,但不是全部:

Runtime

  • 连接
  • getManifest
  • geturl
  • ID
  • on Connect
  • onMessage
  • sendmessage

惯用方法是消息您的背景脚本要求它执行操作内容脚本。

chrome.runtime.reload isn't available for content scripts.

See documentation for the list of methods available to content scripts; some chrome.runtime methods are, but not all:

runtime:

  • connect
  • getManifest
  • getURL
  • id
  • onConnect
  • onMessage
  • sendMessage

The idiomatic way is to message your background script to request it to perform an operation content scripts aren't allowed to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文