Skip to content

fix(capture): retry tab activation when the tab strip is busy#12

Merged
DCCA merged 1 commit into
mainfrom
fix/capture-tab-activation-race
Jun 27, 2026
Merged

fix(capture): retry tab activation when the tab strip is busy#12
DCCA merged 1 commit into
mainfrom
fix/capture-tab-activation-race

Conversation

@DCCA

@DCCA DCCA commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Symptom

After the content-script retry fix (#11), one-click capture now fired but failed with:

Tabs cannot be edited right now (user may be dragging a tab).

Root cause

Auto-capture runs the instant the editor tab opens — while that tab is still being inserted into the tab strip. captureFullPage calls chrome.tabs.update(targetTab, { active: true }) to bring the page forward for captureVisibleTab, 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 }): retry chrome.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 in finally (best-effort, so a restore failure can't mask the capture). isTabsBusyError is extracted and pure.

This is the same defensive pattern as #11, applied to the other Chrome API the auto-capture path races.

Verification

  • New unit tests (tests/capture.test.ts): first-try, retry-then-succeed, immediate rethrow of unrelated errors, give-up after retries, plus isTabsBusyError matching. 54 tests pass (was 48).
  • npm run typecheck, npm run lint, npm run format:check, npm run build green.
  • Live confirmation (icon → auto-capture completes) to be done by @DCCA after reload.

🤖 Generated with Claude Code

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>
@DCCA
DCCA merged commit 3881d49 into main Jun 27, 2026
2 checks passed
@DCCA
DCCA deleted the fix/capture-tab-activation-race branch June 27, 2026 21:00
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

Successfully merging this pull request may close these issues.

1 participant