chrome-extension-tools
chrome-extension-tools copied to clipboard
"Extension context invalidated" errors
Build tool
Rollup
Where do you see the problem?
- [x] In the browser
- [ ] In the terminal
Describe the bug
When running npm run dev
(alias to vite
), I often get "Extension context invalidated" errors for all the open tabs. Example:
If this cannot be avoided, is there a recommended way to prevent this, or maybe you can suppress this in the code?
Reproduction
- Create a vite + crxjs extension with content script locally.
- Run
npm run dev
orvite
. - Stop the server and re-run step 2.
- Repeat steps 2-3 enough times and you'll start seeing errors similar to the screenshot above.
Logs
N/A
System Info
System:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 15.23 GB / 31.95 GB
Binaries:
Node: 16.19.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (111.0.1661.44)
Internet Explorer: 11.0.19041.1566
npmPackages:
@crxjs/vite-plugin: ^2.0.0-beta.15 => 2.0.0-beta.15
vite: ^4.2.1 => 4.2.1
Severity
annoyance
Though I haven't looked in detail at your report, I can say that it's normal during extension dev to see a lot of those. When the extension fully reloads all the content scripts running the old version are invalid.
From the error log, it seems this error is related to stale ports -- would it be possible to use the port's disconnect
handler to catch when the extension is unloaded to prevent "Extension context invalidated" errors? Or maybe just suppress the errors altogether. It would be nice not to see the error logs flooded with these errors because they are act as false positives, meaning every time these errors show up, I have to manually go and read the stack trace because I don't know if the error is something in my code, or something that can be safely ignored like "Extension context invalidated" errors.
From the error log, it seems this error is related to stale ports -- would it be possible to use the port's
disconnect
handler to catch when the extension is unloaded to prevent "Extension context invalidated" errors? Or maybe just suppress the errors altogether. It would be nice not to see the error logs flooded with these errors because they are act as false positives, meaning every time these errors show up, I have to manually go and read the stack trace because I don't know if the error is something in my code, or something that can be safely ignored like "Extension context invalidated" errors.
Giải quyết được lỗi này chưa bạn?