Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Browser Environment fails to initialize on macOS with Chromium headless modeΒ #69

@vladzumer

Description

@vladzumer

Browser Environment fails to initialize on macOS with Chromium headless mode

πŸ› Bug Description

AutoAgent fails to start on macOS because Playwright's Chromium browser crashes immediately in headless mode. The error occurs during browser environment initialization.

πŸ’» Environment

  • OS: macOS 26.0 (Build 25A354)
  • Python: 3.12.11 (via pyenv)
  • AutoAgent: 0.1.0
  • Playwright: 1.39.0
  • BrowserGym: 0.13.0
  • browsergym-core: 0.13.0
  • Architecture: ARM64 (Apple Silicon)

πŸ”΄ Error Output

____________________Browser Env____________________
[2025-10-07 00:49:22]
Starting browser env...
Process Process-1:
Traceback (most recent call last):
  File "/Users/vladislaviskov/.pyenv/versions/3.12.11/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/Users/vladislaviskov/.pyenv/versions/3.12.11/lib/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/vladislaviskov/Desktop/agent/AutoAgent/autoagent/environment/browser_env.py", line 475, in browser_process
    obs, info = env.reset()
                ^^^^^^^^^^^
  File "/Users/vladislaviskov/.pyenv/versions/3.12.11/lib/python3.12/site-packages/browsergym/core/env.py", line 221, in reset
    self.browser = pw.chromium.launch(
                   ^^^^^^^^^^^^^^^^^^^
playwright._impl._api_types.Error: Browser closed.
==================== Browser output: ====================
<launching> /Users/vladislaviskov/Library/Caches/ms-playwright/chromium-1084/chrome-mac/Chromium.app/Contents/MacOS/Chromium --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --enable-use-zoom-for-dsf=false --use-angle --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/var/folders/rn/gym3bnf52pg94rdfjjxy6ryw0000gn/T/playwright_chromiumdev_profile-K7Uemr --remote-debugging-pipe --no-startup-window
<launched> pid=79873

πŸ”„ Steps to Reproduce

  1. Install AutoAgent on macOS (Apple Silicon):

    git clone https://github.com/HKUDS/AutoAgent.git
    cd AutoAgent
    pip install -e .
    playwright install
  2. Create .env file with OpenAI API key:

    cp .env.template .env
    # Add OPENAI_API_KEY=your_key
  3. Run AutoAgent:

    COMPLETION_MODEL=gpt-4o auto main
  4. Browser environment fails to initialize

πŸ§ͺ Additional Testing

βœ… What Works:

  • Chromium launches successfully in non-headless mode
  • Running Chromium binary directly: /Users/.../chromium-1084/.../Chromium --version βœ…
  • Firefox launches successfully in headless mode
  • Docker containers created successfully
  • All other components work fine

❌ What Doesn't Work:

  • Chromium in headless mode (--headless flag)
  • Trying Firefox as alternative fails because BrowserGym requires CDP (Chrome DevTools Protocol), which is Chromium-only

Test Results:

# Firefox works but CDP not available
python3 -c "from playwright.sync_api import sync_playwright; p = sync_playwright().start(); browser = p.firefox.launch(headless=True); print('OK'); browser.close()"
# βœ… Output: OK

# But CDP fails with Firefox
playwright._impl._api_types.Error: CDP session is only available in Chromium

πŸ’‘ Potential Causes

This appears to be a macOS security issue with Playwright's Chromium in headless mode on newer macOS versions (especially Apple Silicon). Similar issues reported:

πŸ”§ Attempted Workarounds

1. Removed quarantine attribute:

xattr -d com.apple.quarantine ~/Library/Caches/ms-playwright/chromium-1084/chrome-mac/Chromium.app
# Already no quarantine attribute

2. Tried Firefox:

  • Patched browsergym/core/env.py and browsergym/core/chat.py to use pw.firefox.launch()
  • Firefox launches successfully but fails with: CDP session is only available in Chromium

3. Updated Playwright:

  • Attempted upgrade to 1.55.0 but incompatible with libwebarena/libvisualwebarena requirements

πŸ™ Proposed Solutions

Option 1: Add Firefox Support to BrowserGym

Make BrowserGym work without CDP for Firefox compatibility

Option 2: Optional Browser Environment

Add a flag to disable browser environment for users who don't need web browsing:

web_env = BrowserEnv(..., disable=True)  # Skip browser init

Option 3: Use headed mode on macOS

Add OS detection and use headed mode (with virtual display) on problematic macOS versions

Option 4: Documentation Update

Add clear documentation about:

  • Known issue with macOS 25.0+
  • Recommend Linux/Windows WSL2 for browser-based tasks
  • Workarounds or limitations

πŸ“‹ Workaround for Users

Currently, users on affected macOS versions cannot run AutoAgent with browser environment. Temporary solutions:

  1. Use Linux VM or Docker
  2. Use Windows with WSL2
  3. Wait for fix

πŸ€” Questions

  1. Is there a way to run AutoAgent without browser environment for non-web tasks?
  2. Could we add an environment variable like AUTOAGENT_DISABLE_BROWSER=true?
  3. Any plans to support newer macOS versions or alternative browsers?

Would love to help test any fixes! πŸ™Œ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions