Evaluate JavaScript
browser_evaluateRuns JavaScript in the current browser page to extract data or inspect elements, optionally targeting a ref or selector, and returns the JSON-serialized result.
Instructions
Run JavaScript in the page. Provide an expression or a function body; with ref/selector the function receives the element as its argument. Returns the JSON-serialised result.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"expression": "<expression>"
},
"name": "browser_evaluate"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ref | No | Element ref from browser_snapshot, e.g. "e12" | |
| selector | No | Playwright selector (CSS, text=..., role=..., xpath=...) used when no ref is given | |
| expression | Yes | e.g. "document.title" or "(el) => el.textContent" |