I'm working on an extension that includes certain developer tools, such as the ability to alter cookies or DOM elements. The popup.html page contains all the options for the current page, and when I select one of them, the content.js file receives a message to run a script.
However, the issue is that when I reinstall the extension or refresh it, I must first refresh the page that is already open.
Imagine that a user install my addon after having several browser tabs open. Then, in order to inject the "content.js" script, he or she must reload each tab.
I thinking of injecting the content.js file by using this chrome API:
chrome.scripting.executeScript(
{
target: {tabId: tabId},
files: ['script.js'],
},
() => { ... });
But how can you tell if the content.js file is already active on the page and there is no need to inject the script?
How can I find out if the "content.js" script is currently running on the current page? Or if anyone knows of a better way to solve this.