web_evaluate_js — Claude Code prompt: what it does, how to install
web_evaluate_js — a prompt for Claude Code runs JavaScript code on the current web page and returns the collected data as JSON.
Apache-2.0 ★ 9,488 updated 2026-11-16
.claude/commands/web_evaluate_js.mdWhat web_evaluate_js does
The script executes inside the live page context to read DOM elements using queries like querySelectorAll and textContent. Network access, form submissions, DOM mutations, cookies, and local storage access remain blocked during execution. Fields resembling credentials, tokens, and payment cards are automatically masked.
The execution time is bounded, and the output string length has a strict character limit. A dedicated state object preserves data across calls on the same page and resets when the page changes. Since network requests fail, data loaded via page APIs requires the web_capture tool instead.
Installation in Claude Code is done by placing the file at .claude/commands/web_evaluate_js.md in the project directory.
What it helps with
- execute JavaScript inside the current web page DOM
- mask sensitive credentials and tokens automatically
- persist state variables across script calls on the same page
- limit execution time and result string length
Example prompts for the agent
- Run
web_evaluate_jsto extract text contents from the current DOM - Execute
web_evaluate_jsto read page data as JSON
How to install web_evaluate_js
Manually: put the files in place
.claude/commands/web_evaluate_js.mdHow to use
Paste the text at the start of a chat or into project instructions
Questions about web_evaluate_js
How to install web_evaluate_js in Claude Code?
Place the prompt file at .claude/commands/web_evaluate_js.md in your project repository.
What does web_evaluate_js do?
It executes JavaScript against the live page DOM, returning masked data as JSON while blocking network requests.
What limitations apply to the script?
The script cannot use the network, modify elements, access cookies, or read password and card input fields.
Source text
web_evaluate_js.md · Apache-2.0
Read data from the current web page with JavaScript, and get the result back as JSON (default time limit {{default_seconds}} s, result at most {{result_max}} characters; values that look like credentials or tokens are masked). The script runs inside the real page and sees the live DOM, but it can only read: document, window, location and getComputedStyle are read-only views of the page (querySelectorAll, getAttribute, textContent, getBoundingClientRect and the like work; setting a property, adding or removing elements, click(), focus(), submit(), opening windows or navigating fail with read_only). Password, hidden, one-time-code and card fields read as ***, and cookies and local storage cannot be read. It cannot use the network: fetch, XMLHttpRequest, sendBeacon, WebSocket and loading images or scripts fail with blocked_network; it only reads what the page already has (to read data the page loaded from its APIs, use web_capture). Also available: sleep(ms), URL, URLSearchParams, plain JavaScript (JSON, Math, Array…), and state, an object that keeps what you put in it across calls on the same page (state="new" in the result means it was just created, e.g. after the page changed). script is one expression or the body of an async function that uses return; return plain data (strings, numbers, arrays, objects), not elements. To act on the page use the action tools.
© wangzan101 · Apache-2.0 · wangzan101/Mika