Such an API is not provided. But there are two possible workarounds:
I. You can use the flag variable "disabled" and update it from your background page.
Background page:
function disableExtension(disabled) { chrome.windows.getAll({populate : true}, function (window_list) { for (var i = 0; i < window_list.length; ++i) { var window = window_list[i]; for (var j = 0; j < window.tabs.length; ++j) { var tab = window.tabs[j]; if (checkContentScriptExists(tab)) { chrome.tabs.executeScript(tab.id, {code : "disabled = " + disabled + ";"}, allTabs: true) } } }
A content script should check the status before running
if (!disabled) doSomething();
II. Controversial Approach to Keeping a Disable Variable in the Background Content of Age
Background page:
function disableExtension(disabled) { global.disabled = disabled; } chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { if (request.msg == "getDisabled") { sendResponse({disabled: global.disabled}); return true; } });
and the content script should request the current disabled status before executing
chrome.runtime.sendMessage({msg: "getDisabled"}, function(response) { if (!response.disabled) doSomething(); });
source share