Skip to content

Fix orphaned extension reconnect seed tab - #133

Merged
JustasMonkev merged 3 commits into
mainfrom
fix/extension-seed-tab-cleanup
Jul 19, 2026
Merged

JustasMonkev merged 3 commits into
mainfrom
fix/extension-seed-tab-cleanup

Conversation

@JustasMonkev

@JustasMonkev JustasMonkev commented Jul 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • remove the token-bypass connect.html?mcpRelayUrl= seed tab after its replacement target is attached
  • keep cleanup scoped to the Playwright extension relay so normal browser tabs and other run modes are unchanged
  • add focused protocol-v2 regression coverage

Upstream context

Upstream issue: microsoft/playwright#41864

Playwright reports that after an extension reconnect, making browser_tabs { action: "new" } the first tool call creates a second target and leaves the connection seed page orphaned. This repository has the same protocol-v2 flow: token bypass adopts the seed page, then BrowserModel.createTarget() attached the requested page without retiring the infrastructure tab.

The fix removes only other known tabs with the exact extension seed URL, and only after the replacement target attaches. This resolves the locally reproducible cause without changing general tab behavior or attempting to patch the separate competing-tab-group race owned by the browser extension.

Closes #132

Validation

  • real protocol-v2 extension + headed Chromium reproduction on current main
  • npm test -- tests/extension-protocol.test.ts
  • npm run lint
  • npm test (34 files, 368 tests)
  • npm run build
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes

    • Automatically closes obsolete extension connect-page tabs when creating a new browser target, based on a computed connect-page prefix.
    • Ensures best-effort cleanup removes only the intended relay’s connect page, without affecting other connect-page tabs.
  • Tests

    • Added a new protocol v2 test to verify correct tab removal behavior across multiple connect-page tabs, including when the removal targets are already closed.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0e1049aa-d392-4616-8df1-1a418660bec7

📥 Commits

Reviewing files that changed from the base of the PR and between 8bf74a8 and 5a6f613.

📒 Files selected for processing (4)
  • src/extension/browserModel.ts
  • src/extension/cdpRelay.ts
  • src/extension/cdpRelayV2.ts
  • tests/extension-protocol.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/extension-protocol.test.ts

📝 Walkthrough

Walkthrough

CDPRelayServer now propagates a stable extension connect-page prefix through protocol v2. BrowserModel.createTarget() uses it to identify and remove stale matching seed tabs, with coverage for selective, best-effort removal.

Changes

Extension tab cleanup

Layer / File(s) Summary
Connect-page prefix plumbing
src/extension/cdpRelay.ts, src/extension/cdpRelayV2.ts, src/extension/browserModel.ts
CDPRelayServer caches the connect-page URL prefix, reuses it for navigation, and passes it through ExtensionProtocolV2 into BrowserModel.
Stale seed cleanup and validation
src/extension/browserModel.ts, tests/extension-protocol.test.ts
createTarget() queries matching known tabs and removes those whose target URLs still use the relay prefix; the test verifies only the intended seed tab is removed when tab removal throws.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CDPRelayServer
  participant ExtensionProtocolV2
  participant BrowserModel
  participant ChromeTabs
  CDPRelayServer->>ExtensionProtocolV2: Pass cached connect-page prefix
  ExtensionProtocolV2->>BrowserModel: Initialize with prefix
  BrowserModel->>BrowserModel: Create target and inspect known matching tabs
  BrowserModel->>ChromeTabs: Remove matching stale seed tab
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds local URL-based cleanup for orphaned seed tabs, but issue #132 explicitly asked not to add that workaround yet. Remove the local cleanup workaround or revise the issue scope once upstream ownership and cleanup semantics are decided.
Out of Scope Changes check ⚠️ Warning The relay-side URL-based tab cleanup implements a workaround that the linked issue said not to add, making it outside the requested scope. Limit the change to tracking or deferring the fix, or update the scope if the workaround is now intended.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the reconnect seed-tab cleanup fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/extension-seed-tab-cleanup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/extension/browserModel.ts`:
- Around line 119-123: Update the orphaned-tab cleanup in the target creation
flow to use Promise.allSettled instead of Promise.all, while preserving the
existing filtering and _sendToExtension calls. Cleanup rejections must be
tolerated so createTarget still returns the newly created target result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 756bf674-9c34-46e9-80a8-019f15f64440

📥 Commits

Reviewing files that changed from the base of the PR and between a9ea1ab and 8bf74a8.

📒 Files selected for processing (2)
  • src/extension/browserModel.ts
  • tests/extension-protocol.test.ts

Comment thread src/extension/browserModel.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8bf74a8a16

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/extension/browserModel.ts Resolved
Comment thread src/extension/browserModel.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31e38ad635

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/extension/browserModel.ts Resolved
@JustasMonkev
JustasMonkev merged commit 7e06ea1 into main Jul 19, 2026
@JustasMonkev
JustasMonkev deleted the fix/extension-seed-tab-cleanup branch July 19, 2026 10:38
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.

Track extension reconnect seed-tab handling

1 participant