Browser Automation (CDP)¶
Recommended verification path¶
Before trying complex multi-step flows, first:
- run
loopforge doctor - confirm browser checks are healthy
- start with one simple navigate/read/screenshot task
Use browser tools when web_fetch isn't enough (JS-rendered pages, multi-step flows, forms, screenshots).
For copy-paste recipes, see: Browser Use Cases.
Default backend: CDP (no Python)¶
LoopForge launches a local Chromium-based browser (Chrome / Chromium / Edge) and drives it via Chrome DevTools Protocol (CDP).
Prerequisites¶
- Install a Chromium-based browser (Chrome/Chromium/Edge).
- If LoopForge can’t find it, set
LOOPFORGE_BROWSER_CHROME_PATHto the browser executable path.
Remote CDP (optional)¶
If you already have a browser running with a remote debugging port (or you run one in Docker), point LoopForge at it:
By default, LoopForge only allows loopback CDP endpoints. To attach to a non-loopback CDP URL, you must explicitly opt in:
For a copy/paste Docker GUI sandbox (Chromium + noVNC) that exposes CDP on 127.0.0.1:9222, run:
Then follow: Baidu Weather.
Headless vs GUI¶
By default, LoopForge launches the browser in headless mode.
To show the browser window (local debugging / demos), set headless=false on the first browser_navigate call:
You can also set LOOPFORGE_BROWSER_HEADLESS=0 to make GUI mode the default when headless is not provided.
Optional backend: Playwright bridge (legacy)¶
If you prefer Playwright (or you’re in an environment where CDP is hard), switch the backend:
Then install Playwright (Python):
If your Python executable isn't python3, set LOOPFORGE_BROWSER_PYTHON (example: python).
Tool set¶
browser_navigate— open a URL (SSRF-protected by default)browser_back— go back in historybrowser_scroll— scroll the pagebrowser_click— click by CSS selector (best-effort text fallback)browser_type— fill an inputbrowser_press_key— press a key (example:Enterto submit a form)browser_wait— wait for a selector (compat)browser_wait_for— wait for a selector/text to appearbrowser_read_page— return{title,url,content}(content is truncated)browser_run_js— evaluate a JS expression and return the resultbrowser_screenshot— write a PNG to a workspace-relative pathbrowser_close— close the session (idempotent)
Recommended loop¶
browser_navigateto the entry pagebrowser_read_pageto confirm state- One small action:
browser_clickorbrowser_type - If you need to submit a form, use
browser_press_keywithEnter. - If the page updates async, use
browser_wait_for(selector/text) to wait for the new state browser_read_pageagain to confirm the page changed- Repeat until done, then
browser_screenshotfor evidence andbrowser_close
Selector tips¶
Prefer stable attributes over text that may change:
#id[name="q"][data-testid="submit"]button[type="submit"]
If a CSS selector fails, browser_click will try a best-effort visible-text fallback. Be specific (avoid short ambiguous words like “OK”).
Prompt template (copy/paste)¶
Use this as a starting point for agent prompts:
Example run:
Security notes¶
browser_navigatedenies loopback/private targets by default. Useallow_private=trueonly for local/private testing.browser_read_pageandbrowser_screenshotalso enforce the same loopback/private protection (unless you enabledallow_private).- Browser tools only allow
http(s)URLs (schemes likefile:,data:,chrome:are blocked). browser_screenshotonly writes to workspace-relative paths (no absolute paths, no.., no symlink escapes).
Troubleshooting¶
- Error mentions Chrome/Chromium not found: install a browser or set
LOOPFORGE_BROWSER_CHROME_PATH. - Error mentions CDP sandbox issues in Docker: set
LOOPFORGE_BROWSER_NO_SANDBOX=1(only in trusted sandbox envs). - Error mentions Playwright missing: set
LOOPFORGE_BROWSER_BACKEND=playwrightand install Playwright. - Error mentions
python3missing (Playwright backend): setLOOPFORGE_BROWSER_PYTHON=python. - No browser window appears: it's headless by default; use
headless=false(or setLOOPFORGE_BROWSER_HEADLESS=0). - Error mentions session not started: call
browser_navigatefirst.