Chrome 程序化扩展 CSS 活动选项卡注入错误

Chrome extension programmatic CSS injection error into active tab

我想在满足特定条件时将 CSS 文件注入活动选项卡。 我设法仅通过向清单添加 "<all_urls>" 权限来使其工作,尽管在文档中写道 "activeTab" 应该足够了:https://developer.chrome.com/extensions/activeTab#what-activeTab-allows

使用下面的代码我得到

Cannot access contents of the page. Extension manifest must request permission to access the respective host.

虽然将 "activeTab" 替换为 "<all_urls>" 效果很好。 这是为什么?

manifest.json

...
"permissions": [
    "activeTab"
],

"content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["contentScript.js"]
    }
]

contentScript.js

...
chrome.runtime.sendMessage({injectCSS: true});

background.js

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    if (request.injectCSS) {
        chrome.tabs.insertCSS(null, {
            file: 'syle.css'
        });
    }
});

The activeTab permission gives an extension temporary access to the currently active tab when the user invokes the extension - for example by clicking its browser action. Access to the tab lasts while the user is on that page, and is revoked when the user navigates away or closes the tab.

This serves as an alternative for many uses of , but displays no warning message during installation

使用 activeTab 时,您必须调用扩展程序才能访问选项卡。

https://developer.chrome.com/extensions/activeTab