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

The declarativeContent API in chrome extension is expected to disable the extension icon in toolbar if

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信