fix(capture): retry content-script message on one-click auto-capture#11
Merged
Conversation
One-click capture fires immediately when the editor opens, before the target tab's content script has registered its message listener — so SB_GET_PAGE_METRICS rejected with "Could not establish connection. Receiving end does not exist." ensureInjectable swallowed its own failure and there was no retry, so the capture aborted (the manual button worked only because the user clicks seconds later, once the script is ready). Add sendToContentScript: send, and on a no-receiver error re-inject content.js and retry with a short backoff up to N times. Use it for the racy metrics call. This also fixes capturing tabs that were already open before the extension was (re)loaded, which never received the static content script. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 27, 2026
DCCA
added a commit
that referenced
this pull request
Jun 27, 2026
- CLAUDE.md: content.ts message set (SB_CAPTURE_*), capture.ts retry helpers/guards (activateTab, sendToContentScript, isTabsBusyError, isNoReceiverError), the on-page notice flow, and wslPath/feedback helpers. - README: one-click capture, capture notice, and Copy for Claude Code in the feature list. - todo: drop the removed popup from the manual QA list; add one-click + notice QA items. - Add .docs/done/2026-06-27-one-click-capture-reliability/ change record (PRs #11-#14). 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.
Symptom
After enabling one-click capture (#8), clicking the toolbar icon opened the editor but capture failed with:
The manual Capture Page button still worked.
Root cause
One-click auto-capture fires immediately on editor load.
captureFullPagesendsSB_GET_PAGE_METRICSto the target tab's content script — but that listener hasn't registered yet that early, sochrome.tabs.sendMessagerejects with the no-receiver error.ensureInjectableswallowed its own injection error and there was no retry, so capture aborted. The manual button "worked" only because the user clicks seconds later, by which point the script is ready.This also affected tabs that were already open before the extension was (re)loaded — static
content_scriptsdon't run on pre-existing tabs, so they relied entirely on the one-shot programmatic injection.Fix
sendToContentScript(tabId, message, { retries, delayMs }): send the message; on a no-receiver error, re-injectcontent.jsand retry with a short backoff (up to 6 times), rethrowing any other error immediately. Used for the racy metrics call.isNoReceiverErroris extracted and pure.Verification
tests/capture.test.ts): first-try success, retry-then-succeed (asserts re-injection count), immediate rethrow of unrelated errors, give-up after exhausting retries, plusisNoReceiverErrormatching. 48 tests pass (was 42).npm run typecheck,npm run lint,npm run format:check,npm run buildgreen.dist/assets/editor.js.🤖 Generated with Claude Code