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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745455112a4628450.html
评论列表(0条)