将扩展内容脚本绑定到 Chrome 的起始页?

Binding extension content scripts to Chrome's start page?

有什么方法可以将内容脚本绑定到 Chrome 的起始页吗?

我尝试将 matches 设置为 "*",但它甚至没有 运行。 "*://*/*" 不绑定。

不,你不能*。从技术上讲,起始页面是 chrome://newtab/,出于安全原因,Chrome 扩展无法访问 chrome:// 页面,即使具有最广泛的 "<all_urls>" 权限也是如此。

您唯一的希望是 make your own New Tab page,尽管很难复制所有默认功能(例如热门网站的缩略图)。


* 可以使用 Chrome 标志启用此功能:chrome://flags/#extensions-on-chrome-urls 但这仅适用于扩展供个人使用且存在潜在安全风险的情况。

是的! Chrome 的起始页(现在?)具有隐藏的 URL 形式:

https://www.google.com/_/chrome/newtab?espv=2&ie=UTF-8

以及带有 manifest.json 的扩展名,如:

{
    "manifest_version": 2,
    "content_scripts": [ {
        "js":               [ "HelloWorld.js" ],
        "matches":          [ "*://*/_/chrome/newtab*" ]
    } ],
    "name":         "Chrome start test",
    "description":  "Runs on the Chrome Start page",
    "version":      "1"
}

...运行 在起始页上非常好。