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

Function buildAgentNthAttributeScript

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

Source from the content-addressed store, hash-verified

328}
329
330function buildAgentNthAttributeScript(selector: string, indexValue: number, attribute: string): string {
331 const payload = { selector, index: indexValue, attribute };
332 return buildEvalScript(`
333 const payload = ${JSON.stringify(payload)};
334 let nodes = [];
335 try {
336 nodes = Array.from(document.querySelectorAll(payload.selector));
337 } catch {
338 return { ok: false, error: "Invalid selector" };
339 }
340 const element = nodes[payload.index];
341 if (!element) return { ok: false, error: "Element not found" };
342 const value = element.getAttribute ? element.getAttribute(payload.attribute) : null;
343 return { ok: true, value };
344 `);
345}
346
347function buildAgentNthPropertyScript(selector: string, indexValue: number, property: string): string {
348 const payload = { selector, index: indexValue, property };

Callers 1

agentQueryFunction · 0.85

Calls 1

buildEvalScriptFunction · 0.85

Tested by

no test coverage detected