The declarativeContent
API in chrome extension is expected to disable the extension icon in toolbar if the page condition is not met, but I'm not able to get this working.
I picked the exact example from documentation.
// manifest.json
{
"name": "test-ext",
"version": "1.0",
"manifest_version": 3,
"action": {
"default_popup": "popup.html"
},
"background": {
"service_worker": "serviceWorker.js"
},
"permissions": [
"declarativeContent"
]
}
// serviceWorker.js
const rule = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostSuffix: ".google", schemes: ["https"] },
}),
],
actions: [new chrome.declarativeContent.ShowAction()],
};
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([rule]);
});
});
// popup.html
<!doctype html>
<html lang="en">
<body>
<div id="root">POPUP</div>
</body>
</html>
The extension icon is available as active on all pages regardless of whether I visit or
or any other page. Also, I'm able to click it and open the popup in all pages. What am I doing wrong?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744326125a4568655.html
评论列表(0条)