(
data: any,
retryAttempt: number,
retryDriver: PlaywrightChrome | null = null
)
| 200 | } |
| 201 | |
| 202 | async function runPlaywright( |
| 203 | data: any, |
| 204 | retryAttempt: number, |
| 205 | retryDriver: PlaywrightChrome | null = null |
| 206 | ): Promise<any> { |
| 207 | let path: string | undefined; |
| 208 | |
| 209 | if (cache === true) { |
| 210 | path = _getCachePath(fn_name, data); |
| 211 | if (_has(path)) { |
| 212 | try { |
| 213 | return _get(path); |
| 214 | } catch (error) { |
| 215 | if (!(error instanceof CacheMissException)) throw error; |
| 216 | } |
| 217 | } |
| 218 | } else if (cache === "REFRESH") { |
| 219 | path = _getCachePath(fn_name, data); |
| 220 | } |
| 221 | |
| 222 | let result: any; |
| 223 | const evaluated_headless = typeof headless === "function" ? headless(data) : headless; |
| 224 | const evaluated_userAgent = typeof userAgent === "function" ? userAgent(data) : userAgent; |
| 225 | // @ts-ignore |
| 226 | let driver: PlaywrightChrome | null = null; |
| 227 | try { |
| 228 | if (retryDriver !== null) { |
| 229 | driver = retryDriver; |
| 230 | } else if (reuseDriver && _driverPool.length > 0) { |
| 231 | driver = (_driverPool.pop() || null) as PlaywrightChrome; |
| 232 | } else { |
| 233 | driver = await createPlaywrightChrome(evaluated_headless, evaluated_userAgent); |
| 234 | globalChromes.add(driver); |
| 235 | } |
| 236 | |
| 237 | if (maxRetry !== undefined && maxRetry !== null) { |
| 238 | // Set retry-related configurations |
| 239 | // ... |
| 240 | } |
| 241 | |
| 242 | result = await run({ data, metadata, taskId, parentTaskId, isAborted, pushData, ...driver }); |
| 243 | if (result === undefined) { |
| 244 | result = null; |
| 245 | } |
| 246 | |
| 247 | if (reuseDriver) { |
| 248 | _driverPool.push(driver); |
| 249 | } else { |
| 250 | await closeDriver(driver); |
| 251 | } |
| 252 | |
| 253 | if (cache === true || cache === "REFRESH") { |
| 254 | if (isDontCache(result)) { |
| 255 | _remove(path!); |
| 256 | } else { |
| 257 | writeJson(result, path!); |
| 258 | } |
| 259 | } |
no test coverage detected