在 Google Chrome 中检测空的新标签页开口

Detect empty, new tab openings in Google Chrome

我刚刚发布了一个 Google Chrome 扩展程序,可以将背景图像加载到新的空白选项卡中。该插件位于 Chrome Web Store.

为了检测新的和空的标签,我需要在扩展的 manifest.json 中请求 "tab" 权限。但是,这会授予扩展程序读取浏览器历史记录的权限。并非所有用户都想要这个,我们实际上也不需要它。有没有办法在没有此权限要求的情况下检测空标签?目前我们的支票是这样的:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
    if (changeInfo.status == "loading" && tab.url == 'chrome://newtab/')
    { /* load background into tab */ }
});

如果您想自定义新标签页,您应该将其添加到您的清单中:

"chrome_url_overrides": {
   "newtab": "newtab.html"
}

然后将您当前注入新标签页的脚本作为 <script> 标记放入 newtab.html 文件中。这不会导致该许可消息。