(args: z.infer<typeof GetTextArgs>, _ctx: ToolContext)
| 281 | argsSchema = GetTextArgs; |
| 282 | |
| 283 | async execute(args: z.infer<typeof GetTextArgs>, _ctx: ToolContext): Promise<ToolResult> { |
| 284 | try { |
| 285 | const s = await getSession(); |
| 286 | const maxChars = args.max_chars ?? 5000; |
| 287 | let text: string; |
| 288 | if (args.selector) { |
| 289 | const el = await s.page.$(args.selector); |
| 290 | if (!el) return { content: `[BROWSER_ERROR] selector not found: ${args.selector}`, isError: true }; |
| 291 | text = await el.innerText(); |
| 292 | } else { |
| 293 | text = await s.page.innerText('body'); |
| 294 | } |
| 295 | const truncated = text.length > maxChars; |
| 296 | return { |
| 297 | content: `${text.slice(0, maxChars)}${truncated ? `\n…[truncated, ${text.length - maxChars} more chars]` : ''}`, |
| 298 | metadata: { fullLength: text.length }, |
| 299 | }; |
| 300 | } catch (e: any) { |
| 301 | return { content: `[BROWSER_ERROR] get_text failed: ${e?.message ?? String(e)}`, isError: true }; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | const WaitForArgs = z.object({ |
nothing calls this directly
no test coverage detected