(
evaluatable: Evaluatable,
fnString: string,
args: Array<JSHandle<unknown>>,
response: Response,
options?: {filePath: string; context: Context},
)
| 135 | }); |
| 136 | |
| 137 | const performEvaluation = async ( |
| 138 | evaluatable: Evaluatable, |
| 139 | fnString: string, |
| 140 | args: Array<JSHandle<unknown>>, |
| 141 | response: Response, |
| 142 | options?: {filePath: string; context: Context}, |
| 143 | ) => { |
| 144 | const fn = await evaluatable.evaluateHandle(`(${fnString})`); |
| 145 | try { |
| 146 | const result = await evaluatable.evaluate( |
| 147 | async (fn, ...args) => { |
| 148 | // @ts-expect-error no types for function fn |
| 149 | return JSON.stringify(await fn(...args)); |
| 150 | }, |
| 151 | fn, |
| 152 | ...args, |
| 153 | ); |
| 154 | if (options?.filePath) { |
| 155 | const data = new TextEncoder().encode(result ?? 'undefined'); |
| 156 | const {filename} = await options.context.saveFile( |
| 157 | data, |
| 158 | options.filePath, |
| 159 | '.json', |
| 160 | ); |
| 161 | response.appendResponseLine( |
| 162 | `Script ran on page. Output saved to ${filename}.`, |
| 163 | ); |
| 164 | } else { |
| 165 | response.appendResponseLine('Script ran on page and returned:'); |
| 166 | response.appendResponseLine('```json'); |
| 167 | response.appendResponseLine(`${result}`); |
| 168 | response.appendResponseLine('```'); |
| 169 | } |
| 170 | } finally { |
| 171 | void fn.dispose(); |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | const getPageOrFrame = async ( |
| 176 | page: Page, |
no test coverage detected
searching dependent graphs…