Problem
When BrowserAutomation runs inside co ai (uvicorn async server), the browser profile causes two issues:
-
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"
-
Sync Playwright inside async loop — sync_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.
Problem
When
BrowserAutomationruns insideco ai(uvicorn async server), the browser profile causes two issues:SingletonLock conflict —
~/.co/browser_profile/SingletonLockpersists after crashes or between sessions, blocking new browser launches with "Failed to create a ProcessSingleton for your profile directory"Sync Playwright inside async loop —
sync_playwright()fails with "Playwright Sync API inside the asyncio loop" when called from uvicorn's event loop context on subsequent sessionsThe 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
asyncio.to_thread)SingletonLockfrom first session blocks launchsync_playwright()which fails in async contextLogs