Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Extension context invalidated #41

Open
Bighamster opened this issue Oct 12, 2022 · 2 comments
Open

Question: Extension context invalidated #41

Bighamster opened this issue Oct 12, 2022 · 2 comments

Comments

@Bighamster
Copy link

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?

@zikaari
Copy link
Collaborator

zikaari commented Oct 20, 2022

What version of webext-bridge are you using?

@zikaari
Copy link
Collaborator

zikaari commented Oct 20, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants