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

Function buildAgentListScript

src/agent-backend.ts:293–311  ·  view source on GitHub ↗
(selector: string, limit: number)

Source from the content-addressed store, hash-verified

291}
292
293function 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
313function buildAgentNthValueScript(selector: string, indexValue: number): string {
314 const payload = { selector, index: indexValue };

Callers 1

agentQueryFunction · 0.85

Calls 1

buildEvalScriptFunction · 0.85

Tested by

no test coverage detected