browser-use/browsercode/browser-execute
- community
Checking that the SKILL.md file is still in the repository.
Use ONLY when calling the `browser_execute` tool or driving a real browser via the Chrome DevTools Protocol. Required reading before the first `browser_execute` call in a session. Covers the three connection methods (local Chrome with remote debugging, isolated debug-port profile, Browser Use cloud), the in-process `session` / `console` snippet model, attaching to a page target, common CDP commands, the per-project `.bcode/agent-workspace/` for reusable scripts, and screenshot auto-attachment.
Install
npx vskill@latest install browser-use/browsercode/browser-executeSKILL.md
The browser_execute tool evaluates JavaScript against a connected browser session via the Chrome DevTools Protocol. The snippet runs in-process; session is bound to a long-lived CDP Session that persists. There is no helper namespace, just session, console, and standard JS globals.
Workspace: <projectRoot>/.bcode/agent-workspace/. Read/write your reusable scripts here. Skills: {{SKILLS_DIR}}/. Read-only browser execute reference docs.
Connecting
In Browser Use Cloud API V4, browser_execute automatically connects and attaches the existing page once when the fresh run first uses this tool; do not call session.connect() or session.use() before driving it. Otherwise, call session.connect(...) once at the start of your work. There are three connection methods:
Way 1: connect to the user's running Chrome or Chromium-based browser (real profile, popup-gated).
Choose when the task involves the user's logged-in sites, current browser state, cookies, saved data, etc.
For this to work the user must have navigated to chrome://inspect/#remote-debugging in their target Chrome and ticked "Allow remote debugging for this browser instance". This setting is per-profile and persists across every future launch of that profile. On Chrome 144 and later, the first attach also triggers an in-browser "Allow remote debugging?" popup that the user must click "Allow" on. The popup may reappear on later attaches under conditions that are not fully characterized — browser restart, time elapsed, new CDP session. Ask the user to click Allow again if a previously working connection starts 403'ing.
Failure modes:
connect()throws "No running browser with remote debugging detected". The checkbox atchrome://inspect/#remote-debugginghas not been ticked in any running Chrome profile, or no Chrome is running.connect()throws with "403" / "permission" / "WS closed before open". The checkbox is ticked but the user hasn't clicked Allow on the popup yet. By defaultconnect()errors in 5s; pass{ timeoutMs: 30000 }to wait up to 30s for the click.
Way 2: connect to a Chrome or Chromium-based browser launched with a debug port (isolated profile, no popups).
Choose for unattended automation, or for an isolated browser.
Launch Chrome with --remote-debugging-port=<port> --user-data-dir=<path>. Pick a directory you can access — e.g., a project-local one like ./.bcode/chrome-data-dir.
--user-data-dir must not be Chrome's platform default. Chrome 136 and later silently no-ops the --remote-debugging-port flag when --user-data-dir is the platform default. The platform defaults are %LOCALAPPDATA%\Google\Chrome\User Data on Windows, ~/Library/Application Support/Google/Chrome on macOS, ~/.config/google-chrome on Linux. You cannot reuse the user's everyday Chrome profile by copying its files into a custom directory.
Failure modes:
- Chrome's launch log prints
DevTools listening on ws://...:<port>/...immediately followed bybind() failed: Address already in useand Chrome exits. Confirm the port is actually open withcurl http://127.0.0.1:<port>/json/versionbefore connecting. { profileDir }raises ENOENT onDevToolsActivePort. Chrome 147+ doesn't write this file under custom--user-data-dir; use the/json/versionroute above instead.- Launch silently no-ops
--remote-debugging-port. Launching a second Chrome that points at a--user-data-dirmatching a running process ignores--remote-debugging-port.
Way 3: provision and connect to a Browser Use cloud browser.
Choose when the computer has no browser or to work in the background.
A cloud browser is a paid service and requires BROWSER_USE_API_KEY to be set in the environment. Browser Use cloud browsers auto-solve captchas. When you land on one, just stop driving and await new Promise(r => setTimeout(r, 10000)); the solver runs server-side and the page advances on its own. Browser Use has a free tier gated for intelligent and powerful agents. Unlimited free browsers and proxies, limited to 3 concurrent browsers. Agents can sign up and receive a key fully autonomously, but must pass a proof-of-agent-capability challenge. In can be done without any browser. To begin, post or webfetch https://browser-use.com and solve the challenge (see https://browser-use.com/llms.txt or POST https://api.browser-use.com/cloud/signup.).
Way 4: user-preconfigured endpoint
Not a method you choose — a way for the user to hand you a pre-set endpoint. When V4_RUN_ID and BU_CDP_WS (or its alias BU_CDP_URL) are both set, browser_execute connects to that endpoint and attaches its existing non-internal page once before the first snippet. Go straight to driving it. Other environments keep the explicit connection flow, and explicit { wsUrl } / { profileDir } calls still connect to the requested endpoint instead. If that fixed endpoint closes or repeatedly fails its WebSocket upgrade, reconnecting to the same URL cannot recover it; the endpoint owner must replace it.
Attaching to a target
After connecting manually, attach to a page target before driving the browser. A preconfigured endpoint is already attached automatically:
If a target-scoped command throws CdpError code -32001 (Session with given id not found), the browser connection is still usable but the target session is stale. List targets again, session.use(...) the intended page, and retry the rejected command once. Calling session.connect() without arguments is a no-op while connected; it does not replace a stale target session.
If a tab or Chrome crashes, recover with a fresh tab or the available browser-replacement API instead of repeatedly retrying the dead page, and verify previous submissions before repeating them.
Every explicit reconnect or browser switch retires the previous socket and clears its active target attachment. Re-list targets, call session.use(...), and rediscover DOM nodes and Runtime objects before continuing.
Opening a tab creates a new page target but does not switch the active attachment. Call Target.getTargets again and session.use(targetId) when continuing there.
Driving a page
Domain methods follow session.<Domain>.<method>(params) and return Promises. The full surface (652 commands) is the Chrome DevTools Protocol. Object.keys(session.domains).sort() lists every CDP domain bound on the session; Object.keys(session.Page).sort() lists the methods for Page. For unknown param shapes, call with {} and inspect the thrown CdpError — .data carries the missing-field detail.
Common moves:
Page.navigate can return a non-empty errorText instead of throwing. Treat it as a failed navigation. If ERR_TUNNEL_CONNECTION_FAILED persists, reloading, reattaching, or reconnecting to the same endpoint cannot change its proxy route; use another source or replace the cloud browser instead of retrying it.
Not auto-attaching a screenshot: attachment is keyed on the Page.captureScreenshot response; pixels that arrive as an event are never attached.
Reusing code
The agent-workspace is per-project: ./.bcode/agent-workspace/. Use this to write memory files, scripts, and helper functions. Imports work at any depth; pick whatever layout makes the project easiest to navigate.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 91 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpackages/bcode-browser/skills/browser-execute/SKILL.md
Popularity
- Repository stars
- 119
- Repository forks
- 19
- 7-day trend score
- 24
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/browser-use/browsercode/browser-execute)