Skip to content
Advertisement

Disable / Enable Chrome Extension Via Browser Action / Icon

The chrome extension I am developing inserts content scripts and css onto every page of a website. However, the user may have a certain page or pages he or she does not want the extension to run on, so it would be great if I could set up the browser action as basically a toggle on / off.

What I’d like to do is something like this:

JavaScript

Any help would be greatly appreciated!

Advertisement

Answer

Such API is not provided. But two possible workarounds exist:

I. You can use the “disabled” flag variable and update it from your background page.

Background page:

JavaScript

And content script should check the condition before the run

JavaScript

II. A controversial approach to save disable variable within background page content

Background page:

JavaScript

and the content script should query currently disabled status before execution

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement