0

I want to make my Google Chrome Extension disabled by default and then enable it based on the content flow , how could I achieve it ?

Here is the API to make the extension disabled , I need that by default . https://developer.chrome.com/extensions/browserAction#method-disable

URL87
  • 10,667
  • 35
  • 107
  • 174
  • See [this answer](https://stackoverflow.com/a/64475504), it shows how to do it via page_action which is basically the same thing as browser_action but more suited for your use case. Depending on what "content flow" is there could be different solutions. – wOxxOm Oct 25 '20 at 08:26

1 Answers1

0

In your background page (as configured in manifest.json e.g.):

"background": {
    "scripts": [
        "js/background.js"
    ]
}

You can do the following to disable the extension each time a tab is opened::

chrome.tabs.onCreated.addListener(() => {
    chrome.browserAction.disable();
});

Then later, based on flow call chrome.browserAction.enable();

Benny Halperin
  • 1,872
  • 3
  • 13
  • 18
  • I got error: > Error in event handler: TypeError: Cannot read properties of undefined (reading 'disable')... – Marcin Jul 14 '23 at 09:17
  • @Marcin - "TypeError: Cannot read properties of undefined (reading 'disable')" - This error means that whatever is to the left of `.disable()` is undefined. In this case, that's `chrome.action`. So you either haven't defined an action in manifest.json, or you're trying to call `chrome.action.disable()` in a content script. See [Content scripts > Understand content script capabilities](https://developer.chrome.com/docs/extensions/mv3/content_scripts/#capabilities) – Thomas Mueller Jul 14 '23 at 12:32