webext-bridge
webext-bridge copied to clipboard
Question: Extension context invalidated
Within content-script I keep alive service-worker
setInterval(() => sendMessage("WORKER_KEEP_ALIVE_MESSAGE", ''),5000);
When the extension is updated, the content-script loses connection to the background and generates an error "Extension context invalidated".
How can I fix it?
What version of webext-bridge
are you using?
Plus I don't think any of the "keepalive" techniques advocated across the internet actually work reliably.
Here is how I confirmed if keepalives were working (they were not after all):
// background.js
// if your keepalive is really working, then this value should always be the same indefinitely
const startTime = Date.now()
// this rig is just to have the value printable in the console by some content script
chrome.runtime.onMessage.addListener(() => chrome.runtime.sendMessage(startTime))
// ... whatever keepalive method you are using
// content-script
// should indefinitely print the same value, even hours later
chrome.runtime.onMessage.addListener((v) => console.log(v))
setInterval(() => chrome.runtime.sendMessage(''), 3000)
// ... whatever keepalive method you are using
You can read about my experience with this issue here.