问题
Is there any way to bind a content script to Chrome's start page?
I tried setting matches
to "*"
, but it doesn't even run. With "*://*/*"
it does not bind.
回答1:
No, you cannot*. Technically, the start page is chrome://newtab/
, and Chrome Extensions cannot access chrome://
pages for security reasons, not even with the widest "<all_urls>"
permission.
Your only hope is to make your own New Tab page, though it would be hard to replicate all of the default functionality (e.g. thumbnails of top sites).
* One can enable this with Chrome Flags: chrome://flags/#extensions-on-chrome-urls
But this is only applicable if the extension is for personal use and is a potential security risk.
回答2:
Yes! Chrome's Start page (¿now?) has the hidden URL of the form:
https://www.google.com/_/chrome/newtab?espv=2&ie=UTF-8
And extensions with manifest.json
s like:
{
"manifest_version": 2,
"content_scripts": [ {
"js": [ "HelloWorld.js" ],
"matches": [ "*://*/_/chrome/newtab*" ]
} ],
"name": "Chrome start test",
"description": "Runs on the Chrome Start page",
"version": "1"
}
...run perfectly well on the Start page.
来源:https://stackoverflow.com/questions/28152205/binding-extension-content-scripts-to-chromes-start-page