Skip to content

Add persistent browser contexts and Chrome channel support with custom launch args - #3

Draft
EarthmanWeb wants to merge 10 commits into
sailaoda:mainfrom
EarthmanWeb:features
Draft

Add persistent browser contexts and Chrome channel support with custom launch args#3
EarthmanWeb wants to merge 10 commits into
sailaoda:mainfrom
EarthmanWeb:features

Conversation

@EarthmanWeb

@EarthmanWeb EarthmanWeb commented Nov 26, 2025

Copy link
Copy Markdown

Pull Request Summary: Enhanced Browser Features

This allows an end user to achieve, through optional configurations, the end result to be more like the PlaywrightMCP default, allowing password manager, cookie and history retention, while still retaining the great multi-instance features provided in the core.

Overview

Adds persistent browser contexts, Chrome channel support, custom launch arguments, and responsive viewport mode to concurrent-browser-mcp.


1. Persistent Browser Contexts (src/browser-manager.ts, src/types.ts)

New Functionality

  • Persistent mode: Preserve cookies, localStorage, and session data across browser restarts
  • Configuration options:
    • persistent: true → Auto-generated temp directory
    • persistent: "/path/to/profile" → Custom userDataDir path
  • Implementation: Uses Playwright's launchPersistentContext() instead of ephemeral browser.newContext()

Key Changes

  • BrowserInstance.browser now Browser | null (null for persistent contexts)
  • New launchPersistentContext() method handles persistent browser launches
  • closeInstance() and closeAllInstances() updated to handle both browser and context closures

Use Cases

  • Testing with saved passwords/auth sessions
  • Maintaining user state between test runs
  • Chrome extensions requiring profile data

2. Chrome Channel Support (src/types.ts, src/tools.ts)

New Functionality

  • Use installed browsers (Chrome, Edge) instead of bundled Playwright Chromium
  • Supported channels:
    • chrome, chrome-beta, chrome-dev, chrome-canary
    • msedge, msedge-beta, msedge-dev, msedge-canary

Benefits

  • Enables Chrome's built-in password manager
  • Access to installed Chrome extensions
  • More accurate representation of real user environment

3. Custom Launch Arguments (src/types.ts, src/tools.ts, src/browser-manager.ts)

New Parameters

args: string[]

  • Pass custom Chrome/browser flags
  • Example: ["--disable-extensions", "--start-maximized"]
  • Merged with existing headless/proxy args

ignoreDefaultArgs: string[]

  • Critical addition: Remove problematic Playwright default flags
  • Example: ["--enable-automation", "--no-sandbox"]
  • Why needed:
    • --enable-automation disables password save prompts
    • --no-sandbox unsupported on some macOS versions

Implementation

  • Args passed to both launchBrowser() and launchPersistentContext()
  • Properly merged with conditional headless/proxy args

4. Responsive Viewport Mode (src/types.ts, src/tools.ts, src/browser-manager.ts)

New Functionality

  • responsive: true → Passes viewport: null to Playwright
  • Allows browser to use its natural window size
  • Overrides fixed viewport dimensions when enabled

Implementation

viewport: args.responsive ? null : (args.viewport || { width: 1280, height: 720 })

5. Tool Schema Updates (src/tools.ts)

Added Parameters to browser_create_instance

  • responsive (boolean, default: false)
  • channel (enum: Chrome/Edge channels)
  • args (string array)
  • ignoreDefaultArgs (string array)
  • persistent (boolean | string, default: false)

Updated Descriptions

  • Clarified viewport behavior with responsive mode
  • Added channel documentation
  • Explained ignoreDefaultArgs use case

6. Bug Fixes & Improvements

Instance Creation (src/browser-manager.ts)

  • Fixed page reference for persistent contexts: context.pages()[0] || context.newPage()
  • Added return metadata: responsive, channel, persistent fields
  • Proper directory creation for persistent profiles with fs.mkdirSync()

Proxy Handling

  • Consistent proxy application across both ephemeral and persistent contexts

Args Management

  • Unified args array building in both launchBrowser() and launchPersistentContext()
  • Proper conditional arg addition (headless, proxy, custom)

Configuration Example

Enable Password Manager with Persistent Profile

{
  headless: false,
  channel: "chrome",
  responsive: true,
  persistent: "/tmp/test-profile",
  args: [
    "--password-store=basic",
    "--use-mock-keychain"  // macOS
  ],
  ignoreDefaultArgs: [
    "--enable-automation",      // Blocks password prompts
    "--no-sandbox",             // macOS incompatible
    "--disable-setuid-sandbox"
  ]
}

Testing Recommendations

  1. Persistent contexts: Verify profile reuse across restarts
  2. Chrome channels: Test password manager prompts with channel: "chrome"
  3. Custom args: Validate arg merging doesn't conflict with Playwright defaults
  4. Responsive mode: Confirm viewport behavior with responsive: true
  5. ignoreDefaultArgs: Verify flags actually removed via chrome://version

Breaking Changes

None - All additions are backward compatible with optional parameters.

EarthmanWeb and others added 10 commits November 25, 2025 17:49
Adds persistent flag to browser_create_instance to use Playwright's
launchPersistentContext() instead of ephemeral newContext(). This preserves
cookies, localStorage, IndexedDB, and session data across browser restarts.

- persistent: true = auto temp directory
- persistent: "/path" = custom userDataDir path

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Combines responsive viewport and persistent context features.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Adds ability to use installed browsers (Chrome, Edge) instead of bundled
Playwright Chromium. Enables features like password manager that are
disabled in automation builds.

New parameters for browser_create_instance:
- channel: 'chrome' | 'msedge' | etc. - Use installed browser
- args: string[] - Custom browser launch arguments

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Combines channel/args support with responsive/persistent features.

New parameters for browser_create_instance:
- channel: Use installed browser (Chrome/Edge) with password manager
- args: Custom browser launch arguments
- persistent: Persistent context (from features branch)
- responsive: Null viewport support (from features branch)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@EarthmanWeb

Copy link
Copy Markdown
Author

This needs more testing, running into overloaded context with the change

@EarthmanWeb
EarthmanWeb marked this pull request as draft November 26, 2025 09:09
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