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

Function buildAgentOuterHtmlScript

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

Source from the content-addressed store, hash-verified

361}
362
363function 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
379function ensureEvalResult(result: any, fallback: string): any {
380 if (!result || typeof result !== "object" || result.ok !== true) {

Callers 1

agentQueryFunction · 0.85

Calls 1

buildEvalScriptFunction · 0.85

Tested by

no test coverage detected