MCPcopy Create free account
hub / github.com/different-ai/opencode-browser / buildAgentNthValueScript

Function buildAgentNthValueScript

src/agent-backend.ts:313–328  ·  view source on GitHub ↗
(selector: string, indexValue: number)

Source from the content-addressed store, hash-verified

311}
312
313function buildAgentNthValueScript(selector: string, indexValue: number): string {
314 const payload = { selector, index: indexValue };
315 return buildEvalScript(`
316 const payload = ${JSON.stringify(payload)};
317 let nodes = [];
318 try {
319 nodes = Array.from(document.querySelectorAll(payload.selector));
320 } catch {
321 return { ok: false, error: "Invalid selector" };
322 }
323 const element = nodes[payload.index];
324 if (!element) return { ok: false, error: "Element not found" };
325 const value = element.value !== undefined ? element.value : "";
326 return { ok: true, value: typeof value === "string" ? value : String(value ?? "") };
327 `);
328}
329
330function buildAgentNthAttributeScript(selector: string, indexValue: number, attribute: string): string {
331 const payload = { selector, index: indexValue, attribute };

Callers 1

agentQueryFunction · 0.85

Calls 1

buildEvalScriptFunction · 0.85

Tested by

no test coverage detected