nodecode-playwright
A headless browser for the agent through Playwright: check that a page loads, read it as an accessibility tree, pull text, attributes or links out of it, screenshot it, print it to PDF, and (when the operator allows it) evaluate JavaScript in it. Written for Nodecode around the Playwright library you install; the cell ships its own small driver script and no Playwright code or browser.
Get it
Tell the agent "add the playwright cell", or run nodecode add nc://playwright.
Set it up
- Install Node.js 18 or later.
- Install Playwright and a browser:
npm install -g playwright, thennpx playwright install chromium(on Linux,npx playwright install --with-deps chromiumalso installs the system libraries the browser needs). Playwright installed in a project folder works too: name that folder inmodule_path. - Run
/playwright. It answers node's version, Playwright's version, whether the browser is downloaded, and the two gates below.
See config.example.jsonc:
| Key | Default | What it does |
|---|---|---|
node |
"node" |
The node binary: a name on PATH or an absolute path. |
module_path |
"" |
The folder Playwright is installed in (a project folder, or npm's global node_modules). Empty looks in NODE_PATH, the working folder and npm root -g. |
browser |
"chromium" |
The browser every call opens: chromium, firefox or webkit. |
timeout_seconds |
30 |
How long one step (opening, waiting, reading) may take. |
max_chars |
30000 |
How many characters of page text one answer carries. |
viewport_width |
1280 |
The browser window's width in CSS pixels. |
viewport_height |
800 |
The browser window's height in CSS pixels. |
allowed_hosts |
[] |
The only hosts (app.example.com) and *.domains a page or its iframes may open or move to. Empty lets in any http(s) host. |
allow_eval |
false |
Let playwright_eval run the model's JavaScript in pages. |
Use it
| Tool | For |
|---|---|
playwright_open |
Whether a URL loads: HTTP status, the URL it ended on, title, load time, and the errors its scripts logged. |
playwright_snapshot |
The page, or the part a CSS selector names, as an accessibility tree: headings, links, buttons, form fields, text. |
playwright_extract |
The text, one attribute, or the links of each element a CSS selector matches (up to 500). |
playwright_screenshot |
A PNG or JPEG of the page (first screen or full_page) or of one element, written to a file. |
playwright_pdf |
The page printed to a PDF file (A4, Letter, Legal, A3 or Tabloid; portrait or landscape). Chromium only. |
playwright_eval |
A JavaScript expression's value in the page, as JSON. A function (() => ...) is called. Only with allow_eval. |
Every tool takes url, plus wait_until (load, domcontentloaded, networkidle or commit) and wait_for (a CSS selector to wait for, for content that renders late). A screenshot or PDF goes to the absolute path the call names, in a folder that exists, or to a new file under the system's temp folder.
> playwright_extract {"url": "https://example.com", "selector": "a", "links": true}
200 https://example.com/ - Example Domain
1 element matched a; their links:
[1] Learn more -> https://iana.org/help/example-domains
What each call can reach
- Every call is a fresh headless browser with a fresh context: no cookies, no logins, no storage carried between calls, downloads refused, service workers blocked. The browser closes when the call answers.
- Only
http://andhttps://URLs open.file:,data:,javascript:and the browser's own pages are refused, by the cell and again by the driver, and so is a URL carryinguser@or a backslash, so the host checked is the host opened. - With
allowed_hostsset, every document stays on those hosts: the page and each iframe in it, through the first URL, every redirect hop (checked before the browser follows it, a malformedLocationrefused) and any navigation a script starts, also while waiting forwait_for. An iframe that would leave is left empty and the page goes on; the page itself leaving fails the call. A*.example.orgentry covers the names underexample.org, notexample.orgitself; an IPv6 address may be written with or without brackets. Scripts, images, styles and fetches from other hosts still load: the list bounds which documents open, not what a document includes. playwright_evalis off until the operator setsallow_eval.playwright_snapshotandplaywright_extractread pages without running the model's code.- One call is bounded twice: the driver stops itself 15 seconds past
timeout_seconds, and the cell stops the driver 30 seconds past it.
How it runs
Each tool call writes one JSON job on the standard input of node driver.mjs. driver.mjs is this cell's own script: it finds Playwright where you installed it (module_path, NODE_PATH, the working folder, and only when none of those has it, npm root -g), opens the page, does the one thing asked, prints one JSON line and exits. Nothing of the call rides the command line.
Test
.github/test-cell.sh tools/nodecode-playwright
The tests run offline: the driver is stubbed through the cell's *run* seam, so the URL and allowed_hosts checks, each tool's job, the output paths, the eval and PDF gates, the answers and the failure words are asserted without a browser. When node is on PATH, driver.mjs itself is run for the checks it makes before it loads Playwright.
License
MIT. See LICENSE. Playwright is under the Apache License 2.0 and is not included.