Skip to content

[Bug] Browser.new_context: Browser closed when using WebSurfer with docker browser #478

@sunnykim1206

Description

@sunnykim1206

Describe the bug

When I try to use the WebSurfer (Fara) agent in Magentic UI, the Playwright browser starts and Magentic UI logs Connected to browser, but then immediately fails with:

TargetClosedError: Browser.new_context: Browser closed

From the UI perspective, the web browsing run fails and the agent returns an error.

This does not look like a firewall issue: the WebSocket connection to ws://127.0.0.1:<port>/... is successfully established, and the browser Docker container stays in Up state. The failure happens when creating a new browser context.


Environment

  • Magentic UI version: 0.1.6
  • Install method: cloned from GitHub + pip install into a virtualenv
  • Playwright Python version: 1.51.0
  • Python version: 3.12 (virtualenv)
  • OS: Ubuntu 24.04 / WSL2 on Windows 11>
  • Docker:
    • Docker version: Docker version 29.1.2, build 890dcca
    • Browser image: ghcr.io/microsoft/magentic-ui-browser:0.0.2

How I installed

I followed your instruction on Readmd.md for FARA-7B.
But my VRAM size does not meet the spec, so I used llama_cpp_python instead of vLLM.

How to reproduce

Activate the virtualenv:

cd ~/Magentic_Fara
source .venv/bin/activate

Start llama_cpp

python -m llama_cpp.server --model models/microsoft_Fara-7B-Q4_K_M.gguf --host 0.0.0.0 --port 5000 --n_ctx 32000 --n_gpu_layers 999

Start Magentic UI (default/docker mode):

magentic-ui --fara --port 8081 --config fara_config.yaml

Open the web UI in a browser ( 127.0.0.1:8081) and start a new session with WebSurfer/Fara.

Select one of the sampel questions.

Observe that:

The browser Docker container starts.

Magentic UI logs show Browser started at ws://127.0.0.1:/... and Connected to browser.

Shortly after, the run fails with TargetClosedError: Browser.new_context: Browser closed.

Expected behavior

WebSurfer should successfully create a browser context and be able to navigate to the requested pages using the dockerized Playwright browser.

The run should complete normally and return browsing results.

Actual behavior

Host-side logs (Magentic UI):

2025-12-12 16:42:38.409 | INFO     | magentic_ui.backend.web.routes.ws:run_websocket:44 - WebSocket connection established for run 4
2025-12-12 16:42:38.506 | INFO     | magentic_ui.backend.web.routes.ws:run_websocket:53 - Received start request for run 4
2025-12-12 16:42:38.515 | INFO     | magentic_ui.backend.teammanager.teammanager:prepare_run_paths:101 - Creating run dirs: /home/<USER>/.magentic_ui/files/user/<EMAIL>/4/4 and /home/<USER>/.magentic_ui/files/user/<EMAIL>/4/4
INFO:     127.0.0.1:57830 - "PUT /api/sessions/4?user_id=<EMAIL> HTTP/1.1" 200 OK
INFO:     127.0.0.1:57830 - "GET /api/sessions/?user_id=<EMAIL> HTTP/1.1" 200 OK
2025-12-12 16:42:38.951 | INFO     | magentic_ui.tools.playwright.browser.base_playwright_browser:_start:186 - Browser started at ws://127.0.0.1:56271/27c5f429a370f283812ceb9f210aecf8
2025-12-12 16:42:39.174 | INFO     | magentic_ui.tools.playwright.browser.base_playwright_browser:_start:189 - Connecting to browser at ws://127.0.0.1:56271/27c5f429a370f283812ceb9f210aecf8
2025-12-12 16:42:39.187 | INFO     | magentic_ui.tools.playwright.browser.base_playwright_browser:connect_browser_with_retry:32 - Trying to establish connection to browser at ws://127.0.0.1:56271/27c5f429a370f283812ceb9f210aecf8...
2025-12-12 16:42:44.193 | WARNING  | magentic_ui.tools.playwright.browser.base_playwright_browser:connect_browser_with_retry:35 - Retrying connection in 5 seconds: : WebSocket error: read ECONNRESET
...
2025-12-12 16:42:59.337 | INFO     | magentic_ui.tools.playwright.browser.base_playwright_browser:_start:193 - Connected to browser
ERROR:autogen_core:Error processing publish message for web_surfer_... 
...
  File ".../magentic_ui/tools/playwright/browser/base_playwright_browser.py", line 194, in _start
    self._context = await self._browser.new_context()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../playwright/async_api/_generated.py", line 13930, in new_context
    await self._impl_obj.new_context(
  File ".../playwright/_impl/_browser.py", line 131, in new_context
    channel = await self._channel.send("newContext", params)
  File ".../playwright/_impl/_connection.py", line 528, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.TargetClosedError: Browser.new_context: Browser closed

ERROR:magentic_ui.backend.web.managers.connection:Stream error for run 4: TargetClosedError: Browser.new_context: Browser closed
...
RuntimeError: TargetClosedError: Browser.new_context: Browser closed

Docker containers:

$ docker ps --format 'table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}'
CONTAINER ID   IMAGE                                         STATUS          NAMES
96fe37649a68   ghcr.io/microsoft/magentic-ui-browser:0.0.2   Up 6 seconds    magentic-ui-vnc-browser_d65aa72219eb0f62f8772b312be8aaa5_56645
3b2a8d531f82   ghcr.io/microsoft/magentic-ui-browser:0.0.2   Up 38 minutes   magentic-ui-vnc-browser_850e6f011abb7efd93ac922cf2b498d8_52823

Docker logs for the active browser container (ID 96fe37649a68):

Starting services...
DISPLAY=:99
2025-12-12 08:15:52,783 CRIT Supervisor is running as root. ...
2025-12-12 08:15:52,796 INFO supervisord started with pid 1
2025-12-12 08:15:53,804 INFO spawned: 'x11setup' with pid 11
2025-12-12 08:15:53,809 INFO spawned: 'x11vnc' with pid 13
2025-12-12 08:15:53,815 INFO spawned: 'playwright-server' with pid 15
2025-12-12 08:15:53,820 INFO spawned: 'novnc' with pid 17
2025-12-12 08:15:53,824 INFO spawned: 'openbox' with pid 20
2025-12-12 08:15:53,829 INFO spawned: 'xvfb' with pid 23
...
Starting Playwright server...
2025-12-12 08:15:56,872 INFO success: x11vnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
Playwright server running: ws://localhost:59023/d65aa72219eb0f62f8772b312be8aaa5

Note: the browser container keeps running; it does not immediately exit/crash at the Docker level.

Additional context

When I test without docker ( magentic-ui --fara --port 8081 --config fara_config.yaml --run-without-docker ) it runs well.

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