The best answer I found was a bit interesting and included a message passing between the content scripts and the background.html file.
I will send the code and explain:
Background.html
function updatePageAction(tabId) { chrome.tabs.sendRequest(tabId, {is_content_script: true}, function(response) { if (response.is_content_script) chrome.pageAction.show(tabId); }); }; chrome.tabs.onUpdated.addListener(function(tabId, change, tab) { if (change.status == "complete") { updatePageAction(tabId); } });
content_script.js
// The background page is asking us to find an address on the page. if (window == top) { chrome.extension.onRequest.addListener(function(req, sender, sendResponse) { if (req.is_content_script) start_content_script(); sendResponse({is_content_script: true}); }); };
You want to decide whether to update or re-execute the DOM change script. Fortunately, DOM changes included a URL change (although there were AJAX DOM changes to refresh the page). However, changing the URL raises the onUpdated event. However, each tab fires these βeventsβ, and we want to make sure that we only care about where we also map our content scripts (you can specify a match in the manifest!).
Passing the messgae to the content_script executed on the current tab, we ask: "Are you my content script? If so, please restart it."
source share