Skip to content

fix: sync MCP download and extension profile handling - #136

Merged
JustasMonkev merged 3 commits into
mainfrom
monitor/playwright-mcp-download-profile
Jul 23, 2026
Merged

JustasMonkev merged 3 commits into
mainfrom
monitor/playwright-mcp-download-profile

Conversation

@JustasMonkev

@JustasMonkev JustasMonkev commented Jul 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Mirrors microsoft/playwright#41933 and its merged commit: only an explicit Download is starting navigation error is treated as a download, so unrelated Chromium net::ERR_ABORTED failures return immediately instead of waiting up to three seconds.
  • Mirrors microsoft/playwright#41939 and its merged commit: extension mode now launches the Chrome profile that contains the Playwright bridge extension when --user-data-dir contains multiple profiles, preferring Chrome's last-used profile.
  • Documents the profile-selection behavior and adds focused regression coverage.

Why this matters

The navigation path used a broad Chromium error heuristic that delayed genuine failures and could misclassify aborted navigations. Extension mode passed the user-data directory without a profile, so Chrome could open Default even when the extension had been validated or installed in another profile, leaving the connection waiting indefinitely.

Validation

  • npm test -- tests/tab.test.ts tests/extension-protocol.test.ts (39 tests)
  • npm run lint
  • npm run build
  • npm test (34 files, 372 tests)
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Browser extension mode now automatically selects the Chrome profile containing the extension when multiple profiles are available, prioritizing Chrome’s last-used profile.
  • Bug Fixes

    • Improved navigation handling for downloads so unrelated aborted navigations correctly report errors instead of being mistaken for downloads.
    • Download navigation now waits for the confirmed download event before continuing.
  • Documentation

    • Clarified Chrome profile selection behavior when using --user-data-dir.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@JustasMonkev, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ed1af463-29db-4a37-86f7-cc00f36ea118

📥 Commits

Reviewing files that changed from the base of the PR and between 8d02a53 and 0f48ede.

📒 Files selected for processing (4)
  • src/extension/cdpRelay.ts
  • src/tab.ts
  • tests/extension-protocol.test.ts
  • tests/tab.test.ts
📝 Walkthrough

Walkthrough

The PR adds Chrome profile discovery for extension launches and updates Tab.navigate to handle download-start errors separately from unrelated aborted navigations, with tests and browser extension documentation.

Changes

Extension profile selection

Layer / File(s) Summary
Profile discovery and browser launch
src/extension/cdpRelay.ts
CDPRelayServer asynchronously scans Chrome profiles, prioritizes Local State.profile.last_used, detects the relay extension, and passes --profile-directory when matched.
Profile selection documentation and validation
tests/extension-protocol.test.ts, README.md
The extension protocol test verifies profile selection and initialization; browser extension documentation describes the automatic selection behavior.

Download navigation handling

Layer / File(s) Summary
Download navigation behavior
src/tab.ts, tests/tab.test.ts
Tab.navigate waits for downloads only when the error says “Download is starting” and rethrows unrelated ERR_ABORTED failures; tests cover both cases.

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

Sequence Diagram(s)

sequenceDiagram
  participant MCPContext
  participant CDPRelayServer
  participant ChromeProfileFilesystem
  participant PlaywrightChrome
  MCPContext->>CDPRelayServer: ensureExtensionConnectionForMCPContext
  CDPRelayServer->>CDPRelayServer: await _connectBrowser
  CDPRelayServer->>ChromeProfileFilesystem: findPlaywrightExtensionProfile(userDataDir)
  ChromeProfileFilesystem-->>CDPRelayServer: matching profile directory
  CDPRelayServer->>PlaywrightChrome: launch with selected Chrome profile
Loading

Possibly related PRs

Suggested reviewers: claude

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes to download handling and extension profile selection.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch monitor/playwright-mcp-download-profile

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.

@JustasMonkev
JustasMonkev marked this pull request as ready for review July 23, 2026 14:59

@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: 8d02a5344b

ℹ️ 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/cdpRelay.ts Resolved

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/extension/cdpRelay.ts (1)

103-143: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Honor cancellation before spawning Chrome.

If the signal aborts while awaiting profile discovery, Chrome is still spawned. The subsequent abort listener is registered after the event fired, so this call can then wait indefinitely. Pass the signal into _connectBrowser and recheck it immediately after findPlaywrightExtensionProfile() and before spawn().

Proposed fix
-      await this._connectBrowser(clientInfo);
+      await this._connectBrowser(clientInfo, abortSignal);

-  private async _connectBrowser(clientInfo: ClientInfo) {
+  private async _connectBrowser(clientInfo: ClientInfo, abortSignal: AbortSignal) {
     // ...
     if (this._userDataDir) {
       args.push(`--user-data-dir=${this._userDataDir}`);
       const profileDirectory = await findPlaywrightExtensionProfile(this._userDataDir);
+      if (abortSignal.aborted)
+        throw abortSignal.reason;
       if (profileDirectory)
         args.push(`--profile-directory=${profileDirectory}`);
     }
🤖 Prompt for 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.

In `@src/extension/cdpRelay.ts` around lines 103 - 143, Pass the existing abort
signal from the connection flow into _connectBrowser, then recheck it
immediately after findPlaywrightExtensionProfile() and again before spawning
Chrome. Ensure an already-aborted signal exits or rejects before spawn,
preventing the subsequent connection wait from hanging.
🧹 Nitpick comments (1)
tests/extension-protocol.test.ts (1)

277-295: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the test prove last-used preference.

Profile 1 is the only profile containing the extension, so the assertion passes even if Local State.profile.last_used is never applied. Install the extension in Default too; without the preference logic, deterministic ordering would then choose Default.

Proposed test adjustment
-    await fs.mkdir(path.join(userDataDir, 'Default'), { recursive: true });
+    await fs.mkdir(path.join(userDataDir, 'Default', 'Extensions', EXTENSION_ID), { recursive: true });
🤖 Prompt for 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.

In `@tests/extension-protocol.test.ts` around lines 277 - 295, The test setup
around ensureExtensionConnectionForMCPContext must install the extension in both
the Default and Profile 1 directories, while keeping Local
State.profile.last_used set to Profile 1. This ensures the existing
--profile-directory=Profile 1 assertion specifically verifies last-used profile
selection rather than merely finding the only profile containing the extension.
🤖 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/tab.ts`:
- Around line 188-192: Bound the await of downloadEvent in the navigation
error-handling flow so it uses a finite timeout instead of waiting indefinitely.
When the timeout expires or no download is received, rethrow the original error
e, while preserving the existing handling for a valid download event.

---

Outside diff comments:
In `@src/extension/cdpRelay.ts`:
- Around line 103-143: Pass the existing abort signal from the connection flow
into _connectBrowser, then recheck it immediately after
findPlaywrightExtensionProfile() and again before spawning Chrome. Ensure an
already-aborted signal exits or rejects before spawn, preventing the subsequent
connection wait from hanging.

---

Nitpick comments:
In `@tests/extension-protocol.test.ts`:
- Around line 277-295: The test setup around
ensureExtensionConnectionForMCPContext must install the extension in both the
Default and Profile 1 directories, while keeping Local State.profile.last_used
set to Profile 1. This ensures the existing --profile-directory=Profile 1
assertion specifically verifies last-used profile selection rather than merely
finding the only profile containing the extension.
🪄 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 Plus

Run ID: 10ffb944-abd7-408a-9a2d-73a4b3342988

📥 Commits

Reviewing files that changed from the base of the PR and between f92b089 and 8d02a53.

📒 Files selected for processing (5)
  • README.md
  • src/extension/cdpRelay.ts
  • src/tab.ts
  • tests/extension-protocol.test.ts
  • tests/tab.test.ts

Comment thread src/tab.ts Resolved

Copy link
Copy Markdown
Owner Author

@codex review

@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: 5573f9dcec

ℹ️ 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/cdpRelay.ts Resolved
Comment thread src/tab.ts Resolved

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 0f48ede67f

ℹ️ 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".

@JustasMonkev
JustasMonkev merged commit 87b1fed into main Jul 23, 2026
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