fix(capture): retry tab activation when the tab strip is busy#12
Merged
Conversation
One-click auto-capture runs while the just-opened editor tab is still being
inserted into the tab strip, so chrome.tabs.update(target, {active:true})
rejected with "Tabs cannot be edited right now (user may be dragging a
tab)." and capture aborted. Manual capture avoids it because the strip has
settled by the time the user clicks.
Add activateTab(): retry chrome.tabs.update on this transient error with a
short backoff, rethrowing unrelated errors. Use it to activate the target
tab and to restore the previously-active tab (best-effort). isTabsBusyError
is extracted and pure; both covered by unit tests.
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 the content-script retry fix (#11), one-click capture now fired but failed with:
Root cause
Auto-capture runs the instant the editor tab opens — while that tab is still being inserted into the tab strip.
captureFullPagecallschrome.tabs.update(targetTab, { active: true })to bring the page forward forcaptureVisibleTab, and Chrome transiently rejects tab edits during that window. Manual capture never hit it because the strip had long settled by click time.Fix
activateTab(tabId, { retries, delayMs }): retrychrome.tabs.update(..., { active: true })on the transient "tabs cannot be edited"/"dragging a tab" error with a short backoff (default 8×150ms), rethrowing any unrelated error. Used to activate the target tab, and to restore the previously-active tab infinally(best-effort, so a restore failure can't mask the capture).isTabsBusyErroris extracted and pure.This is the same defensive pattern as #11, applied to the other Chrome API the auto-capture path races.
Verification
tests/capture.test.ts): first-try, retry-then-succeed, immediate rethrow of unrelated errors, give-up after retries, plusisTabsBusyErrormatching. 54 tests pass (was 48).npm run typecheck,npm run lint,npm run format:check,npm run buildgreen.🤖 Generated with Claude Code