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.com", schemes: ["https"] },
}),
],
actions: [new chrome.declarativeContent.ShowAction()],
};
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([rule]);
});
});
```
The extension icon is available as active on all pages regardless of whether I visit
https://www.google.com or
https://example.com or any other page. Also, I'm able to click it and open the popup in all pages. What am I doing wrong?