MCPcopy Create free account
hub / github.com/beita6969/ScienceClaw / evaluateJavaScript

Function evaluateJavaScript

src/browser/cdp.ts:159–187  ·  view source on GitHub ↗
(opts: {
  wsUrl: string;
  expression: string;
  awaitPromise?: boolean;
  returnByValue?: boolean;
})

Source from the content-addressed store, hash-verified

157};
158
159export async function evaluateJavaScript(opts: {
160 wsUrl: string;
161 expression: string;
162 awaitPromise?: boolean;
163 returnByValue?: boolean;
164}): Promise<{
165 result: CdpRemoteObject;
166 exceptionDetails?: CdpExceptionDetails;
167}> {
168 return await withCdpSocket(opts.wsUrl, async (send) => {
169 await send("Runtime.enable").catch(() => {});
170 const evaluated = (await send("Runtime.evaluate", {
171 expression: opts.expression,
172 awaitPromise: Boolean(opts.awaitPromise),
173 returnByValue: opts.returnByValue ?? true,
174 userGesture: true,
175 includeCommandLineAPI: true,
176 })) as {
177 result?: CdpRemoteObject;
178 exceptionDetails?: CdpExceptionDetails;
179 };
180
181 const result = evaluated?.result;
182 if (!result) {
183 throw new Error("CDP Runtime.evaluate returned no result");
184 }
185 return { result, exceptionDetails: evaluated.exceptionDetails };
186 });
187}
188
189export type AriaSnapshotNode = {
190 ref: string;

Callers 4

snapshotDomFunction · 0.85
getDomTextFunction · 0.85
querySelectorFunction · 0.85
cdp.test.tsFile · 0.85

Calls 2

withCdpSocketFunction · 0.85
sendFunction · 0.70

Tested by

no test coverage detected