Skip to content

feat: add Playwright support to browser-use extension - #5

Merged
maks-ivanov merged 1 commit into
mainfrom
browser-playwright
Apr 29, 2026
Merged

feat: add Playwright support to browser-use extension#5
maks-ivanov merged 1 commit into
mainfrom
browser-playwright

Conversation

@maks-ivanov

@maks-ivanov maks-ivanov commented Apr 29, 2026

Copy link
Copy Markdown

Note

Medium Risk
Large behavioral and API change (steps→actions, different ref semantics) plus a new runtime dependency (playwright) and persistent browser lifecycle, which could affect existing integrations and resource cleanup.

Overview
Replaces the browser-use extension’s agent-browser/CLI-based implementation with an in-process Playwright (Chromium) driver that returns a text-only CDP accessibility tree and executes interactions via regenerated ref IDs.

The browser tool API changes from steps to a bounded actions list (1–7) and narrows supported operations to goto, snapshot, click, fill, press, scroll, and wait, updating output formatting to include URL/title/ref count plus the rendered accessibility tree. Lifecycle handling is added to keep a persistent browser across calls and cleanly close it on session_shutdown, and repo dependencies/docs are updated to add playwright and new setup instructions.

Reviewed by Cursor Bugbot for commit 30e4f50. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Partial init failure in ensureDriver leaks Chromium process
    • Wrapped browser initialization in a cleanup catch so partially created Playwright resources are closed before the error is rethrown.

Create PR

Or push these changes by commenting:

@cursor push 337502ca66
Preview (337502ca66)
diff --git a/extensions/browser-use/index.ts b/extensions/browser-use/index.ts
--- a/extensions/browser-use/index.ts
+++ b/extensions/browser-use/index.ts
@@ -284,11 +284,16 @@
 		return { page: state.page, cdp: state.cdp };
 	}
 	state.headed = headed ?? false;
-	state.browser = await chromium.launch({ headless: !state.headed });
-	state.context = await state.browser.newContext();
-	state.page = await state.context.newPage();
-	state.cdp = await state.context.newCDPSession(state.page);
-	return { page: state.page, cdp: state.cdp };
+	try {
+		state.browser = await chromium.launch({ headless: !state.headed });
+		state.context = await state.browser.newContext();
+		state.page = await state.context.newPage();
+		state.cdp = await state.context.newCDPSession(state.page);
+		return { page: state.page, cdp: state.cdp };
+	} catch (error) {
+		await closeDriver(state);
+		throw error;
+	}
 }
 
 async function closeDriver(state: DriverState): Promise<void> {

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 30e4f50. Configure here.

interactive: Type.Optional(Type.Boolean({ description: "Only include interactive elements." })),
urls: Type.Optional(Type.Boolean({ description: "Include href URLs for links in the snapshot." })),
compact: Type.Optional(Type.Boolean({ description: "Remove empty structural elements." })),
depth: Type.Optional(Type.Number({ description: "Optional maximum tree depth.", minimum: 1 })),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial init failure in ensureDriver leaks Chromium process

Low Severity

If chromium.launch succeeds but a subsequent step (newContext, newPage, or newCDPSession) throws, state.browser is set while state.page/state.cdp remain undefined. On the next call, ensureDriver sees the state.page && state.cdp guard as falsy and launches a brand-new browser, overwriting state.browser and orphaning the previous Chromium process. Neither closeDriver nor the session_shutdown handler can ever reach the leaked instance.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 30e4f50. Configure here.

@maks-ivanov
maks-ivanov merged commit 5741d88 into main Apr 29, 2026
5 checks passed
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