开发者

Chrome extension: content script to run on all pages, and another to only run on one page

I'm writing a Chrome extension that needs to do the following:

  • inject a content script into the current (any) page when the popup fires
  • inject a different content script into all pages of a specific domain, always

So far I have the first one implemented, by calling chrome.tabs.executeScript() in the popup.html file and having the following in the manifest to allow the script to run on any page:

"permissions": [
  "tabs", "http://*/*"
],

Now, according to http://code.google.com/chrome/extensions/content_scripts.html, if I want a content script to always run on a specific page, I must declare it in the manifest and set permissions to include only pages that the code should run on. However, this will break the first part.

How do I solve this? The only way I can think of is to always call some kind of "caller" script which then does its own checking and loading of other scripts, but that j开发者_运维技巧ust seems very messy, and i assume there has to be a better way.


{
  "content_scripts": [
    {
      "matches": ["http://www.google.com/*"],
      "js": ["myscript.js"]
    }
  ],
  "permissions": [
     "tabs", "http://*/*"
  ]
}

myscript.js is automatically injected to google.com, you can still manually inject to http://*/*.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜