(selector: string, indexValue: number)
| 361 | } |
| 362 | |
| 363 | function buildAgentOuterHtmlScript(selector: string, indexValue: number): string { |
| 364 | const payload = { selector, index: indexValue }; |
| 365 | return buildEvalScript(` |
| 366 | const payload = ${JSON.stringify(payload)}; |
| 367 | let nodes = []; |
| 368 | try { |
| 369 | nodes = Array.from(document.querySelectorAll(payload.selector)); |
| 370 | } catch { |
| 371 | return { ok: false, error: "Invalid selector" }; |
| 372 | } |
| 373 | const element = nodes[payload.index]; |
| 374 | if (!element) return { ok: false, error: "Element not found" }; |
| 375 | return { ok: true, value: element.outerHTML }; |
| 376 | `); |
| 377 | } |
| 378 | |
| 379 | function ensureEvalResult(result: any, fallback: string): any { |
| 380 | if (!result || typeof result !== "object" || result.ok !== true) { |
no test coverage detected