Skip to content

[CB-0] [sdk-superfan] Add a working browser-use example - #215

Closed
spicysouvlaki wants to merge 1 commit into
mainfrom
wschmitt/browser-use-example
Closed

spicysouvlaki wants to merge 1 commit into
mainfrom
wschmitt/browser-use-example

Conversation

@spicysouvlaki

@spicysouvlaki spicysouvlaki commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What happened. In #144, the BrowserUse docs example failed with:

File ".../playwright/_impl/_connection.py", line 393, in dispatch
    error["error"], format_call_log(msg.get("log"))
KeyError: 'error'

Why. The log line Connecting to remote browser via WSS comes from browser-use 0.1.x BrowserConfig(wss_url=...) (browser_use/browser/browser.py:124 in 0.1.40). That path calls playwright.chromium.connect(), which speaks Playwright's wire protocol. connect_url speaks CDP, so Playwright misparses the first CDP error. The docs moved to BrowserProfile(cdp_url=...), but browser-use 1.0 removed BrowserProfile, so today's docs snippet fails with an ImportError.

Fix. Adds examples/browser_use_basic.py. It uses Browser(cdp_url=session.connect_url) (browser-use ≥1.0.6, SDK ≥1.26.0) and releases the session afterwards, because Browser.stop() never ends a cdp_url browser. The example is a PEP 723 script because browser-use needs Python ≥3.11 and this repo's lint runs on 3.9.

Tests.

  • Live dev session with a scripted LLM: connected over CDP, read HN's top story, and the session ended COMPLETED.
  • Old path against a live session (playwright 1.51.0 connect()): reproduced KeyError: 'error' at _connection.py:393.
  • ./scripts/lint passes.
  • Not run: a real-LLM run (no Anthropic key), and an e2e test (needs 3.11 and an LLM key in CI).

Risk and rollout. Example only. examples/ is never regenerated, and no generated files changed. The docs page still needs the same Browser(cdp_url=...) change.

Refs #144

🤖 Generated with Claude Code

Issue #144: the docs' browser-use snippet failed with Playwright's
`KeyError: 'error'` in _connection.py dispatch. The reporter's log shows
"Connecting to remote browser via WSS", which is browser-use 0.1.x's
BrowserConfig(wss_url=...) path (browser_use/browser/browser.py:124 in
0.1.40). It calls playwright.chromium.connect(), which speaks Playwright's
own wire protocol. A Browserbase connect_url speaks CDP, so the first reply
is a CDP error object with no nested "error" field and Playwright's
dispatch() raises KeyError. Reproduced on a live dev session with
playwright 1.51.0. cdp_url (connect_over_cdp) was the right option.

The docs have since switched to Browser(browser_profile=BrowserProfile(
cdp_url=...)), but browser-use 1.0 removed BrowserProfile, so that snippet
now fails with ImportError. 1.0 takes Browser(cdp_url=...).

browser-use 1.0 needs Python >= 3.11 and this repo's dev env and lint run
on 3.9, so the example is a PEP 723 script with its own deps, and file-level
mypy/pyright directives keep ./scripts/lint green without installing it.

Browser.stop() never ends a cdp_url browser, so the example releases the
session with REQUEST_RELEASE instead of leaving it billing until timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@spicysouvlaki
spicysouvlaki marked this pull request as ready for review November 16, 2026 20:47
@spicysouvlaki
spicysouvlaki requested a review from a team as a code owner November 16, 2026 20:47
@spicysouvlaki

Copy link
Copy Markdown
Collaborator Author

Closing: we're not shipping a browser-use example in the SDK.

@spicysouvlaki
spicysouvlaki deleted the wschmitt/browser-use-example branch November 16, 2026 20:59
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