可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I want to run a content script on an iframe with a chrome-extension:// URL. I added a line to my manifest.json that I copied out of the documentation http://code.google.com/chrome/extensions/match_patterns.html
chrome-extension://*/*
But when I reload my extension I get an alert:
Could not load extension from '/work/sirius/extension'. Invalid value for 'content_scripts[2].matches[0]': Invalid scheme.
Any idea how to get this to worK?
回答1:
I'm having the exact same problem, look at the API http://code.google.com/chrome/extensions/match_patterns.html it says clearly that they accept chrome-extension://*/*
yet they don't.
They need to update the API so as not to confuse people.
回答2:
No. Only ftp:
, file:
, http:
and https:
can be matched by a content script declaration.
Invalid URL patterns at any of the matches
and exclude_matches
fields are rejected (generating an error when trying to load the extension).
Invalid patterns at the permissions
option in the manifest file are ignored.
If you want to run a script on a tab from your extension, use chrome.extension.getViews
in your background script. Even better, design your extension's pages such that they effectively communicate with each other (example).
回答3:
It seems that Chrome authors have silently removed the ability for content scripts to be injected into chrome-extension:
pages. Documentation still says that it works and even contains examples with chrome-extension: scheme but actually it doesn't work. So now only http:
, https:
and ftp:
work "from the box" and file:
can work if user of your extension has enabled this on Extensions (chrome://extensions/) page.
Update: now documentation referred above is updated and says nothing about ability to inject content scripts to chrome-extension:
pages.