&quot“ chrome.runtime.reload不是函数”尝试livereload我的延长运行时
我正在构建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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
chrome.runtime.reload
不适合内容脚本。请参阅文档用于内容脚本可用的方法列表; 一些
chrome.runtime
方法是,但不是全部:惯用方法是消息您的背景脚本要求它执行操作内容脚本。
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:The idiomatic way is to message your background script to request it to perform an operation content scripts aren't allowed to do.