Binding extension content scripts to Chrome's

2019-08-15 06:53发布

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.

2条回答
神经病院院长
2楼-- · 2019-08-15 06:56

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.

查看更多
萌系小妹纸
3楼-- · 2019-08-15 07:03

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.jsons 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.

查看更多
登录 后发表回答