0

I need to enable my chrome extension for all urls and have a list of exceptions for which the chrome extension is disabled.

I am able to create a list of urls for which the extension is enabled with the following code.

chrome.declarativeContent.onPageChanged.addRules([{
      conditions: [
        new chrome.declarativeContent.PageStateMatcher({pageUrl: {hostContains: host},})
      ],
      actions: [
        new chrome.declarativeContent.ShowPageAction()
      ]
    }]);

This is the white list approach.

I can't figure out how to implement the black list approach. Can someone help?

Thanks!

Aditi
  • 1,188
  • 2
  • 16
  • 44
  • There's no such feature in the API so you'll have to imitate it. For example, change the icon ([example](https://stackoverflow.com/a/64475504)) and depending on what your code does perform an explicit check for the URL before processing or whatever it is you do. – wOxxOm Mar 15 '21 at 12:45
  • @wOxxOm i am able to perform an explicit check for the url but can't figure out how to disable the extension programatically. Any idea how that is done? – Aditi Mar 16 '21 at 13:51
  • It depends on what the extension does and what exactly you mean by "disable the extension". – wOxxOm Mar 16 '21 at 14:03
  • @wOxxOm I just need to prevent the popup from showing up. Similar to the behaviour that we would get when `new chrome.declarativeContent.PageStateMatcher({pageUrl: {hostContains: host},})` is false – Aditi Mar 16 '21 at 17:27
  • You'll have to manually call chrome.pageAction.hide inside a listener like chrome.tabs.onUpdated or chrome.webNavigation.onCommitted (better because it accepts a url filter); – wOxxOm Mar 16 '21 at 17:31

0 Answers0