I'm writing a google chrome extension which could click links and buttons. I have to revoke the extension using the background script once the redirect button/link is clicked and the page is changed. The issue is the message indicates only one sent in the background script, but the onMessage listener in the content script receives two messages. How could this be fixed?
background.js
chrome.webNavigation.onCompleted.addListener((details) => {
chrome.tabs &&
chrome.tabs.query({ active: true, currentWindow: true }, () => {
setTimeout(() => {
const storage = chrome.storage.local;
storage.get("activeProcess", (result) => {
let activeProcess = Object.values(result)[0];
if (activeProcess && details.frameType === "outermost_frame") {
const tabId = details.tabId;
storage.get("message", (result) => {
result.message.url = details.url;
result.message.source = "background";
console.log("message sent");
chrome.tabs.sendMessage(tabId, result.message, (res) => {
console.log(res);
});
});
}
});
}, 100);
});
return true;
});
message sent
content.js
chrome.runtime.onMessage.addListener(messagesListener);
async function messagesListener(message, sender, response) {
await processMessage(message, sender, response);
}
export const processMessage = async (message, sender, response) => {
console.log("message received")
}
message received message received