(opts: {
wsUrl: string;
expression: string;
awaitPromise?: boolean;
returnByValue?: boolean;
})
| 157 | }; |
| 158 | |
| 159 | export 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 | |
| 189 | export type AriaSnapshotNode = { |
| 190 | ref: string; |
no test coverage detected