javascript - Why is getBackgroundPage() not defined in chrome.runtime for me? - Stack Overflow

I am trying to access chrome.runtime.getBackgroundPage() from my content script but I get:Uncaught Type

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
Add a ment  | 

1 Answer 1

Reset to default 7

Most 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信