Skip to content

Browser profile management: use browser-use style profile handling #123

@wu-changxing

Description

@wu-changxing

Problem

When BrowserAutomation runs inside co ai (uvicorn async server), the browser profile causes two issues:

  1. SingletonLock conflict~/.co/browser_profile/SingletonLock persists after crashes or between sessions, blocking new browser launches with "Failed to create a ProcessSingleton for your profile directory"

  2. Sync Playwright inside async loopsync_playwright() fails with "Playwright Sync API inside the asyncio loop" when called from uvicorn's event loop context on subsequent sessions

The current approach uses launch_persistent_context() with a shared Chrome profile at ~/.co/browser_profile/, which conflicts with the user's running Chrome and doesn't handle concurrent/sequential sessions cleanly.

Proposal

Adopt the same profile management approach as browser-use — proper profile isolation, cleanup, and async-compatible browser lifecycle.

Current behavior

  • First session: browser works (runs in asyncio.to_thread)
  • Second session: SingletonLock from first session blocks launch
  • After lock error: falls back to sync_playwright() which fails in async context
  • No cleanup on agent shutdown

Logs

BrowserType.launch_persistent_context: Failed to create a ProcessSingleton for your profile directory.
...
Error: It looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.

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