MCPcopy
hub / github.com/omkarcloud/botasaurus / runPlaywright

Function runPlaywright

js/botasaurus-js/src/playwright.ts:202–335  ·  view source on GitHub ↗
(
            data: any,
            retryAttempt: number,
            retryDriver: PlaywrightChrome | null = null
        )

Source from the content-addressed store, hash-verified

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 }

Callers 1

performPlaywrightFunction · 0.85

Calls 15

_getCachePathFunction · 0.90
_hasFunction · 0.90
_getFunction · 0.90
createPlaywrightChromeFunction · 0.90
isDontCacheFunction · 0.90
_removeFunction · 0.90
writeJsonFunction · 0.90
isErrorsInstanceFunction · 0.90
saveErrorLogsFunction · 0.90
formatExcFunction · 0.90
printExcFunction · 0.90
sleepFunction · 0.90

Tested by

no test coverage detected