(selector: string, limit: number)
| 291 | } |
| 292 | |
| 293 | function buildAgentListScript(selector: string, limit: number): string { |
| 294 | const payload = { selector, limit }; |
| 295 | return buildEvalScript(` |
| 296 | const payload = ${JSON.stringify(payload)}; |
| 297 | let nodes = []; |
| 298 | try { |
| 299 | nodes = Array.from(document.querySelectorAll(payload.selector)); |
| 300 | } catch { |
| 301 | return { ok: false, error: "Invalid selector" }; |
| 302 | } |
| 303 | const maxItems = Math.min(Math.max(1, payload.limit || ${DEFAULT_LIST_LIMIT}), 200); |
| 304 | const items = nodes.slice(0, maxItems).map((element) => ({ |
| 305 | text: (element.innerText || element.textContent || "").trim().slice(0, 200), |
| 306 | tag: (element.tagName || "").toLowerCase(), |
| 307 | ariaLabel: element.getAttribute ? element.getAttribute("aria-label") : null, |
| 308 | })); |
| 309 | return { ok: true, value: { items, count: nodes.length } }; |
| 310 | `); |
| 311 | } |
| 312 | |
| 313 | function buildAgentNthValueScript(selector: string, indexValue: number): string { |
| 314 | const payload = { selector, index: indexValue }; |
no test coverage detected