To provide more context, this is what I have in the background script:
let timeout = null;
chrome.runtime.onInstalled.addListener(async () => {
for (const cs of chrome.runtime.getManifest().content_scripts) {
for (const tab of await chrome.tabs.query({url: cs.matches})) {
if (tab.url.match(/(chrome|chrome-extension):\/\//gi)) {
continue;
}
chrome.scripting.executeScript({
files: cs.js,
target: {tabId:
tab.id, allFrames: cs.all_frames},
injectImmediately: cs.run_at === 'document_start',
});
}
}
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status == 'complete' && tab.active) {
chrome.storage.local.get(['nextAction', 'startups', 'key', 'teammate', 'startup'], (request) => {
console.log(request);
chrome.storage.local.set({ nextAction: null }, () => {
if (request.startups !== undefined && request.nextAction !== null) {
console.log('start');
setTimeout(() => {
startDoing(request.startups[request.key], tabId, request.key, request.startups.length);
}, 7000);
}
});
});
}
});
function startDoing(startup, tabId, key, total) {
console.log('startDoing');
chrome.tabs.sendMessage(tabId, { command: 'Do Startup', url: startup.url, key: key, total: total });
}
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
triggerAction(msg,
sender.tab.id);
});
and on the content script:
function doStartupProfile(url, key, total) {
console.log('doStartupProfile');
//contact hte background script to test
chrome.runtime.sendMessage({'action': 'test'});
// rest of the script
}
As you can see, I'm sending a message to the background script once my doStartupProfile is triggered, just to see if it received it. From the console of the browser, i don't see anything, and the 'dostartupProfile' is not displayed (and the rest of the script is not triggered), but I received the 'test' action in the listener, that triggered the triggerAction action (it logged the test action in the background script in the service worker)
I don't understand this behavior, how is it possible that my background script received that test action, while the front did not do anything? It's probably interacting with a different tab ... but I have not other tab active. DO you know where this can be coming from?
Many thanks