Binding extension content scripts to Chrome's start page?

…衆ロ難τιáo~ 提交于 2020-01-15 12:15:05

问题


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



来源:https://stackoverflow.com/questions/28152205/binding-extension-content-scripts-to-chromes-start-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!