fix(extension): stop answering pings after the extension is uninstalled#30
Merged
Merged
Conversation
When the extension is uninstalled (or reloaded), its content script keeps running in already-open pages as an orphan: the window message listener stays alive, and since the ping handler touches no extension API, it kept answering — so the SDK's isAvailable() reported true until the page was refreshed (and an actual pick then failed with a misleading "cancelled"). Guard the message listener: when the extension context is invalidated (browser.runtime.id gone, or touching browser.runtime throws), unhook and go silent. An unanswered ping times out in the SDK, so isAvailable() correctly reports false with no page refresh — the uninstall-side twin of the install-time backfill. A re-install injects a fresh isolated world and answers instead; the dead context can no longer double-answer. Bumps the extension to 0.3.3. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
After uninstalling (or reloading) the extension, its content script keeps running in already-open pages as an orphan: the
windowmessage listener stays alive, and since the ping handler touches no extension API, it kept answering — so the SDK'sisAvailable()reported true until the page was refreshed, and an actualpickthen failed with a misleadingcancelled.How
content/index.tsx—extensionAlive()(browser.runtime?.id, try/catch since touchingbrowser.runtimecan throw in an invalidated context) + a guard at the top of the window message listener: once the extension is gone, unhook and go silent. An unanswered ping times out in the SDK →isAvailable()correctly reportsfalsewith no page refresh — the uninstall-side twin of the install-time backfill (feat(extension): inject content script into open tabs on install #29). A re-install injects a fresh isolated world and answers instead; the dead context can no longer double-answer.Verification
typecheck✅ ·biome check✅ ·vitest run✅ 110 passed ·wxt zip✅ (openpickerextension-0.3.3-chrome.zip)🤖 Generated with Claude Code