Chrome 扩展:如何使用 <all_urls> 将 HTML 注入任何选项卡 w/o

Chrome extension: How to inject HTML into any tab w/o using <all_urls>

我正在尝试在计时器完成后将内容脚本注入用户的当前选项卡。因此,我的清单是:

"content_scripts": [{
    "matches": ["<all_urls>"],
    "js": ["jquery-3.5.1.min.js", "flipclock-min.js", "content.js"],
    "css": ["normalize.min.css", "styles2.css", "flipclock.css", "css.css"]
}]

根据网上商店发布流程:

Instead of requesting broad host permissions, consider using the activeTab permission, or specify the sites that your extension needs access to. Both options are more secure than allowing full access to an indeterminate number of sites, and they may help to minimise review times.

The activeTab permission allows access to a tab in response to an explicit user gesture.

{
...
"permissions": ["activeTab"]
}

我改用 activeTab 很有意义。但是,正如他们提到的,我可以在不 content_scripts 的许可下使用它,否则我会得到:

Invalid value for 'content_scripts[0].matches[1]': Missing scheme separator.

我该怎么办?

activeTab 无法完全自动使用计时器,因为它需要 明确的用户操作 :用户必须单击您的扩展程序图标(或通过 commands API hotkey, a contextMenus API menu, or an omnibox API keyword, more info in the documentation) 启动或设置定时器。

通过这样的用户操作 activeTab 将授予对当前选项卡的访问权限,以便您的后台脚本可以使用 chrome.tabs.executeScript 注入脚本(每个脚本调用一次)。

然后,删除 manifest.json 中的 content_scripts