admin管理员组文章数量:1432620
I am trying to access chrome.runtime.getBackgroundPage()
from my content script but I get:
Uncaught TypeError: chrome.runtime.getBackgroundPage is not a function(anonymous function) @ VM11844:1InjectedScript._evaluateOn @ VM11665:883InjectedScript._evaluateAndWrap @ VM11665:816InjectedScript.evaluateOnCallFrame @ VM11665:942window.onload @ run.js:101
Here's what my manifest.json looks like:
{
"background": {
"scripts": ["background.js"],
"persistent": true
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["run.js"],
"run_at": "document_start"
}],
"description": "Hello world!",
"homepage_url": "",
"icons": {
"16": "icons/16x16.png"
},
"manifest_version": 2,
"name": "Hello world",
"permissions": ["storage", "management"],
"version": "v0.1",
"web_accessible_resources": ["html/*"]
}
Am I missing something? Perhaps a permission?
Thanks!
I am trying to access chrome.runtime.getBackgroundPage()
from my content script but I get:
Uncaught TypeError: chrome.runtime.getBackgroundPage is not a function(anonymous function) @ VM11844:1InjectedScript._evaluateOn @ VM11665:883InjectedScript._evaluateAndWrap @ VM11665:816InjectedScript.evaluateOnCallFrame @ VM11665:942window.onload @ run.js:101
Here's what my manifest.json looks like:
{
"background": {
"scripts": ["background.js"],
"persistent": true
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["run.js"],
"run_at": "document_start"
}],
"description": "Hello world!",
"homepage_url": "https://tryprospect.",
"icons": {
"16": "icons/16x16.png"
},
"manifest_version": 2,
"name": "Hello world",
"permissions": ["storage", "management"],
"version": "v0.1",
"web_accessible_resources": ["html/*"]
}
Am I missing something? Perhaps a permission?
Thanks!
Share Improve this question asked May 2, 2015 at 23:35 Curtis SaccoCurtis Sacco 211 silver badge3 bronze badges 1- Could you post the bit when you're calling the function? – Samurai Commented May 2, 2015 at 23:52
1 Answer
Reset to default 7Most chrome.* APIs are not available to content scripts. They can only be used from background or event pages, popups, or other extension views you define.
In particular you can't use chrome.runtime.getBackgroundPage()
because the window objects for the extension live in a different process than the content script. The only way to municate between content scripts and the rest of your extension is via messaging or storage.
本文标签: javascriptWhy is getBackgroundPage() not defined in chromeruntime for meStack Overflow
版权声明:本文标题:javascript - Why is getBackgroundPage() not defined in chrome.runtime for me? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745455112a2659066.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论