pilot_evaluate
Execute JavaScript expressions on web pages to retrieve results, supporting asynchronous operations for dynamic content interaction.
Instructions
Run a JavaScript expression on the page and return the result. Supports await.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | JavaScript expression to evaluate |
Implementation Reference
- src/tools/inspection.ts:89-99 (handler)The handler for the 'pilot_evaluate' tool, which evaluates a JS expression in the browser.
async ({ expression }) => { await bm.ensureBrowser(); try { const wrapped = wrapForEvaluate(expression); const result = await bm.getPage().evaluate(wrapped); const text = typeof result === 'object' ? JSON.stringify(result, null, 2) : String(result ?? ''); return { content: [{ type: 'text' as const, text }] }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } - src/tools/inspection.ts:85-100 (registration)Tool registration for 'pilot_evaluate' in src/tools/inspection.ts.
server.tool( 'pilot_evaluate', 'Run a JavaScript expression on the page and return the result. Supports await.', { expression: z.string().describe('JavaScript expression to evaluate') }, async ({ expression }) => { await bm.ensureBrowser(); try { const wrapped = wrapForEvaluate(expression); const result = await bm.getPage().evaluate(wrapped); const text = typeof result === 'object' ? JSON.stringify(result, null, 2) : String(result ?? ''); return { content: [{ type: 'text' as const, text }] }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } );