(args: z.infer<typeof EvaluateArgs>, _ctx: ToolContext)
| 255 | argsSchema = EvaluateArgs; |
| 256 | |
| 257 | async execute(args: z.infer<typeof EvaluateArgs>, _ctx: ToolContext): Promise<ToolResult> { |
| 258 | try { |
| 259 | const s = await getSession(); |
| 260 | // Wrap so the user can use `return` naturally in their script. |
| 261 | const fn = new Function('arg', args.script); |
| 262 | const result = await s.page.evaluate(fn.toString(), args.arg); |
| 263 | const formatted = typeof result === 'object' ? JSON.stringify(result, null, 2) : String(result); |
| 264 | return { content: `Result:\n${formatted.slice(0, 5000)}${formatted.length > 5000 ? '\n…[truncated]' : ''}` }; |
| 265 | } catch (e: any) { |
| 266 | return { content: `[BROWSER_ERROR] evaluate failed: ${e?.message ?? String(e)}`, isError: true }; |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | const GetTextArgs = z.object({ |
nothing calls this directly
no test coverage detected