Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

chrome.declarativeContent.ShowAction does not disable popup action for unmatched pages

49 views
Skip to first unread message

Vaibhav Nigam

unread,
Mar 22, 2025, 3:55:25 AMMar 22
to Chromium Extensions
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?
Reply all
Reply to author
Forward
0 new messages