I'm writing a screen capture chrome extension and it takes screenshots on the document "onClick" event.
Currently, I'm sending an event from my "popup script" and receiving it in the content script as you can see.
but after reloading the extension or updating it, I get the Extension context invalidated on each document click. reloading the tab will fix it but it's not the desired solution. this is my content script:
const sendMessage = (e) => {
try {
chrome.runtime.sendMessage({
type: "screenshot"
});
} catch (e) {
console.log("error", e);
}
};
const handleClick = (e) => {
e.stopImmediatePropagation();
sendMessage(e);
};
const handleMessage = (request) => {
document.addEventListener("click", handleClick, true);
};
chrome.runtime.onMessage.addListener(handleMessage);
I tried every solution that I find but didn't work perfectly. and I think this is a chrome bug, why they don't fix it?