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