@crawlee/browser-pool 4.0.0-beta.14 → 4.0.0-beta.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/abstract-classes/browser-controller.d.ts +70 -13
- package/abstract-classes/browser-controller.js +21 -22
- package/abstract-classes/browser-plugin.d.ts +48 -15
- package/abstract-classes/browser-plugin.js +69 -11
- package/anonymize-proxy.d.ts +5 -2
- package/anonymize-proxy.js +9 -5
- package/browser-pool.d.ts +100 -28
- package/browser-pool.js +198 -77
- package/container-proxy-server.d.ts +0 -1
- package/container-proxy-server.js +0 -1
- package/events.d.ts +2 -3
- package/events.js +0 -1
- package/fingerprinting/hooks.d.ts +0 -1
- package/fingerprinting/hooks.js +26 -10
- package/fingerprinting/types.d.ts +2 -3
- package/fingerprinting/types.js +0 -1
- package/fingerprinting/utils.d.ts +0 -1
- package/fingerprinting/utils.js +5 -6
- package/index.d.ts +14 -7
- package/index.js +5 -3
- package/launch-context.d.ts +20 -5
- package/launch-context.js +21 -10
- package/package.json +9 -9
- package/playwright/playwright-browser.d.ts +2 -6
- package/playwright/playwright-browser.js +16 -17
- package/playwright/playwright-controller.d.ts +0 -1
- package/playwright/playwright-controller.js +6 -3
- package/playwright/playwright-plugin.d.ts +10 -7
- package/playwright/playwright-plugin.js +40 -16
- package/proxy-server.d.ts +0 -1
- package/proxy-server.js +0 -1
- package/puppeteer/puppeteer-controller.d.ts +0 -1
- package/puppeteer/puppeteer-controller.js +16 -9
- package/puppeteer/puppeteer-plugin.d.ts +5 -3
- package/puppeteer/puppeteer-plugin.js +83 -46
- package/remote-browser-pool.d.ts +165 -0
- package/remote-browser-pool.js +195 -0
- package/remote-browser-provider.d.ts +83 -0
- package/remote-browser-provider.js +67 -0
- package/utils.d.ts +7 -1
- package/utils.js +19 -1
- package/abstract-classes/browser-controller.d.ts.map +0 -1
- package/abstract-classes/browser-controller.js.map +0 -1
- package/abstract-classes/browser-plugin.d.ts.map +0 -1
- package/abstract-classes/browser-plugin.js.map +0 -1
- package/anonymize-proxy.d.ts.map +0 -1
- package/anonymize-proxy.js.map +0 -1
- package/browser-pool.d.ts.map +0 -1
- package/browser-pool.js.map +0 -1
- package/container-proxy-server.d.ts.map +0 -1
- package/container-proxy-server.js.map +0 -1
- package/events.d.ts.map +0 -1
- package/events.js.map +0 -1
- package/fingerprinting/hooks.d.ts.map +0 -1
- package/fingerprinting/hooks.js.map +0 -1
- package/fingerprinting/types.d.ts.map +0 -1
- package/fingerprinting/types.js.map +0 -1
- package/fingerprinting/utils.d.ts.map +0 -1
- package/fingerprinting/utils.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/launch-context.d.ts.map +0 -1
- package/launch-context.js.map +0 -1
- package/logger.d.ts +0 -3
- package/logger.d.ts.map +0 -1
- package/logger.js +0 -5
- package/logger.js.map +0 -1
- package/playwright/playwright-browser.d.ts.map +0 -1
- package/playwright/playwright-browser.js.map +0 -1
- package/playwright/playwright-controller.d.ts.map +0 -1
- package/playwright/playwright-controller.js.map +0 -1
- package/playwright/playwright-plugin.d.ts.map +0 -1
- package/playwright/playwright-plugin.js.map +0 -1
- package/proxy-server.d.ts.map +0 -1
- package/proxy-server.js.map +0 -1
- package/puppeteer/puppeteer-controller.d.ts.map +0 -1
- package/puppeteer/puppeteer-controller.js.map +0 -1
- package/puppeteer/puppeteer-plugin.d.ts.map +0 -1
- package/puppeteer/puppeteer-plugin.js.map +0 -1
- package/utils.d.ts.map +0 -1
- package/utils.js.map +0 -1
package/browser-pool.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IBrowserPool, NewPageOptions, PageState } from '@crawlee/types';
|
|
1
2
|
import type { BrowserFingerprintWithHeaders } from 'fingerprint-generator';
|
|
2
3
|
import { FingerprintGenerator } from 'fingerprint-generator';
|
|
3
4
|
import { FingerprintInjector } from 'fingerprint-injector';
|
|
@@ -246,9 +247,11 @@ export interface BrowserPoolHooks<BC extends BrowserController, LC extends Launc
|
|
|
246
247
|
* });
|
|
247
248
|
* ```
|
|
248
249
|
*/
|
|
249
|
-
export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoolOptions, BrowserPlugins extends BrowserPlugin[] = InferBrowserPluginArray<Options['browserPlugins']>, BrowserControllerReturn extends BrowserController = ReturnType<BrowserPlugins[number]['createController']>, LaunchContextReturn extends LaunchContext = ReturnType<BrowserPlugins[number]['createLaunchContext']>, PageOptions = Parameters<BrowserControllerReturn['newPage']>[0], PageReturn extends UnwrapPromise<ReturnType<BrowserControllerReturn['newPage']>> = UnwrapPromise<ReturnType<BrowserControllerReturn['newPage']>>> extends TypedEmitter<BrowserPoolEvents<BrowserControllerReturn, PageReturn>> {
|
|
250
|
+
export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoolOptions, BrowserPlugins extends BrowserPlugin[] = InferBrowserPluginArray<Options['browserPlugins']>, BrowserControllerReturn extends BrowserController = ReturnType<BrowserPlugins[number]['createController']>, LaunchContextReturn extends LaunchContext = ReturnType<BrowserPlugins[number]['createLaunchContext']>, PageOptions = Parameters<BrowserControllerReturn['newPage']>[0], PageReturn extends UnwrapPromise<ReturnType<BrowserControllerReturn['newPage']>> = UnwrapPromise<ReturnType<BrowserControllerReturn['newPage']>>> extends TypedEmitter<BrowserPoolEvents<BrowserControllerReturn, PageReturn>> implements IBrowserPool<PageReturn> {
|
|
251
|
+
#private;
|
|
250
252
|
browserPlugins: BrowserPlugins;
|
|
251
253
|
maxOpenPagesPerBrowser: number;
|
|
254
|
+
maxOpenBrowsers: number;
|
|
252
255
|
retireBrowserAfterPageCount: number;
|
|
253
256
|
operationTimeoutMillis: number;
|
|
254
257
|
closeInactiveBrowserAfterMillis: number;
|
|
@@ -271,13 +274,23 @@ export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoo
|
|
|
271
274
|
fingerprintGenerator?: FingerprintGenerator;
|
|
272
275
|
fingerprintCache?: QuickLRU<string, BrowserFingerprintWithHeaders>;
|
|
273
276
|
private browserKillerInterval?;
|
|
274
|
-
private browserRetireInterval?;
|
|
275
|
-
private limiter;
|
|
276
277
|
constructor(options: Options & BrowserPoolHooks<BrowserControllerReturn, LaunchContextReturn, PageReturn>);
|
|
277
278
|
/**
|
|
278
279
|
* Opens a new page in one of the running browsers or launches
|
|
279
280
|
* a new browser and opens a page there, if no browsers are active,
|
|
280
281
|
* or their page limits have been exceeded.
|
|
282
|
+
*
|
|
283
|
+
* **Session injection (best-effort):** When a {@link NewPageOptions.session|session} is
|
|
284
|
+
* provided, this implementation uses it as a cache key for browser fingerprints (when
|
|
285
|
+
* fingerprinting is enabled) and reads
|
|
286
|
+
* {@link ProxyInfo.url|session.proxyInfo.url} /
|
|
287
|
+
* {@link ProxyInfo.ignoreTlsErrors|session.proxyInfo.ignoreTlsErrors} as defaults
|
|
288
|
+
* for `proxyUrl` and `ignoreTlsErrors` respectively. Explicit `proxyUrl` /
|
|
289
|
+
* `ignoreTlsErrors` values in the options take precedence.
|
|
290
|
+
*
|
|
291
|
+
* Beyond fingerprint caching and proxy configuration, no other session
|
|
292
|
+
* properties are consumed — cookie and header injection remain the
|
|
293
|
+
* crawler's responsibility.
|
|
281
294
|
*/
|
|
282
295
|
newPage(options?: BrowserPoolNewPageOptions<PageOptions, BrowserPlugins[number]>): Promise<PageReturn>;
|
|
283
296
|
/**
|
|
@@ -335,7 +348,7 @@ export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoo
|
|
|
335
348
|
* until it's closed.
|
|
336
349
|
*/
|
|
337
350
|
getPageId(page: PageReturn): string | undefined;
|
|
338
|
-
private
|
|
351
|
+
private createPageForBrowser;
|
|
339
352
|
/**
|
|
340
353
|
* Removes a browser controller from the pool. The underlying
|
|
341
354
|
* browser will be closed after all its pages are closed.
|
|
@@ -347,6 +360,43 @@ export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoo
|
|
|
347
360
|
* closed after all its pages are closed.
|
|
348
361
|
*/
|
|
349
362
|
retireBrowserByPage(page: PageReturn): void;
|
|
363
|
+
/**
|
|
364
|
+
* Releases a page back to the pool. The page is closed and, if the
|
|
365
|
+
* optional `error` is a {@link SessionError}, the browser controller
|
|
366
|
+
* that served the page is retired so that its tainted state (cookies,
|
|
367
|
+
* storage, etc.) cannot leak into future sessions.
|
|
368
|
+
*
|
|
369
|
+
* This is the primary way the crawler should return pages to the pool.
|
|
370
|
+
*
|
|
371
|
+
* @param page The page to release.
|
|
372
|
+
* @param options.error The error that caused the page to be released, if any.
|
|
373
|
+
*/
|
|
374
|
+
closePage(page: PageReturn, options?: {
|
|
375
|
+
error?: Error;
|
|
376
|
+
}): Promise<void>;
|
|
377
|
+
/**
|
|
378
|
+
* Extracts the relevant state (currently just cookies) from a page via its
|
|
379
|
+
* owning {@link BrowserController}. Returns empty state when the page is
|
|
380
|
+
* no longer associated with a controller.
|
|
381
|
+
*
|
|
382
|
+
* As with {@link BrowserPool.injectPageState}, cookies are isolated per
|
|
383
|
+
* page only when the pool is configured with `useIncognitoPages: true`.
|
|
384
|
+
* With the default `useIncognitoPages: false`, the extracted cookies
|
|
385
|
+
* include those set by any sibling page sharing the same browser.
|
|
386
|
+
*/
|
|
387
|
+
extractPageState(page: PageReturn): Promise<PageState>;
|
|
388
|
+
/**
|
|
389
|
+
* Injects state into a page via its owning {@link BrowserController}.
|
|
390
|
+
*
|
|
391
|
+
* No-op when the page is no longer associated with a controller.
|
|
392
|
+
*
|
|
393
|
+
* Note that cookies are isolated per page only when the pool is configured
|
|
394
|
+
* with `useIncognitoPages: true` — each page then gets its own browser
|
|
395
|
+
* context. With the default `useIncognitoPages: false`, all pages in a
|
|
396
|
+
* browser share a single context, so injected cookies are visible to every
|
|
397
|
+
* page served by that browser.
|
|
398
|
+
*/
|
|
399
|
+
injectPageState(page: PageReturn, state: PageState): Promise<void>;
|
|
350
400
|
/**
|
|
351
401
|
* Removes all active browsers from the pool. The browsers will be
|
|
352
402
|
* closed after all their pages are closed.
|
|
@@ -357,32 +407,63 @@ export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoo
|
|
|
357
407
|
* @return {Promise<void>}
|
|
358
408
|
*/
|
|
359
409
|
closeAllBrowsers(): Promise<void>;
|
|
410
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
360
411
|
/**
|
|
361
412
|
* Closes all managed browsers and tears down the pool.
|
|
362
413
|
*/
|
|
363
414
|
destroy(): Promise<void>;
|
|
364
|
-
private
|
|
365
|
-
private
|
|
366
|
-
private
|
|
415
|
+
private teardown;
|
|
416
|
+
private getAllBrowserControllers;
|
|
417
|
+
private launchBrowser;
|
|
367
418
|
/**
|
|
368
419
|
* Picks plugins round robin.
|
|
369
420
|
* @private
|
|
370
421
|
*/
|
|
371
|
-
private
|
|
372
|
-
private
|
|
373
|
-
private
|
|
374
|
-
private
|
|
375
|
-
private
|
|
376
|
-
private
|
|
377
|
-
|
|
378
|
-
|
|
422
|
+
private pickBrowserPlugin;
|
|
423
|
+
private pickBrowserWithFreeCapacity;
|
|
424
|
+
private closeInactiveRetiredBrowsers;
|
|
425
|
+
private overridePageClose;
|
|
426
|
+
private executeHooks;
|
|
427
|
+
private closeRetiredBrowserWithNoPages;
|
|
428
|
+
/**
|
|
429
|
+
* Returns `true` if the pool can accept a new browser launch without exceeding
|
|
430
|
+
* {@link BrowserPoolOptions.maxOpenBrowsers}. Counts starting, active, and retired browsers.
|
|
431
|
+
*/
|
|
432
|
+
hasFreeBrowserSlot(): boolean;
|
|
433
|
+
/**
|
|
434
|
+
* Returns `true` if any active browser has room for another page.
|
|
435
|
+
*/
|
|
436
|
+
hasActiveBrowserWithFreeCapacity(): boolean;
|
|
437
|
+
private initializeFingerprinting;
|
|
438
|
+
private addFingerprintHooks;
|
|
379
439
|
}
|
|
380
|
-
export interface BrowserPoolNewPageOptions<PageOptions, BP extends BrowserPlugin> {
|
|
440
|
+
export interface BrowserPoolNewPageOptions<PageOptions, BP extends BrowserPlugin> extends NewPageOptions {
|
|
441
|
+
/**
|
|
442
|
+
* The proxy URL the pool uses internally to route the page: it keys browser
|
|
443
|
+
* reuse (with `browserPerProxy`, only a browser already on this proxy is
|
|
444
|
+
* reused), configures the launched browser, and is applied to incognito
|
|
445
|
+
* pages. When omitted, it is derived from the
|
|
446
|
+
* {@link NewPageOptions.session|session}'s `proxyInfo`; an explicit value
|
|
447
|
+
* here takes precedence.
|
|
448
|
+
*
|
|
449
|
+
* This is an implementation detail of the built-in `BrowserPool`'s proxy
|
|
450
|
+
* handling and is intentionally not part of the {@link IBrowserPool}
|
|
451
|
+
* contract — through that interface the proxy is supplied via the session.
|
|
452
|
+
*/
|
|
453
|
+
proxyUrl?: string;
|
|
381
454
|
/**
|
|
382
|
-
*
|
|
383
|
-
*
|
|
455
|
+
* Disable TLS certificate verification for MITM proxies. Applied both when
|
|
456
|
+
* launching a new browser and when creating a page in an existing one. When
|
|
457
|
+
* omitted, it is derived from the
|
|
458
|
+
* {@link NewPageOptions.session|session}'s `proxyInfo`; an explicit value
|
|
459
|
+
* here takes precedence.
|
|
460
|
+
*
|
|
461
|
+
* This is an implementation detail of the built-in `BrowserPool` and is
|
|
462
|
+
* intentionally not part of the {@link IBrowserPool} contract — through
|
|
463
|
+
* that interface, configure it via the session's `proxyInfo` or through the
|
|
464
|
+
* browser's `launchOptions`.
|
|
384
465
|
*/
|
|
385
|
-
|
|
466
|
+
ignoreTlsErrors?: boolean;
|
|
386
467
|
/**
|
|
387
468
|
* Some libraries (Playwright) allow you to open new pages with specific
|
|
388
469
|
* options. Use this property to set those options.
|
|
@@ -397,14 +478,6 @@ export interface BrowserPoolNewPageOptions<PageOptions, BP extends BrowserPlugin
|
|
|
397
478
|
* see the `newPageInNewBrowser` function.
|
|
398
479
|
*/
|
|
399
480
|
browserPlugin?: BP;
|
|
400
|
-
/**
|
|
401
|
-
* Proxy URL.
|
|
402
|
-
*/
|
|
403
|
-
proxyUrl?: string;
|
|
404
|
-
/**
|
|
405
|
-
* Proxy tier.
|
|
406
|
-
*/
|
|
407
|
-
proxyTier?: number;
|
|
408
481
|
}
|
|
409
482
|
export interface BrowserPoolNewPageInNewBrowserOptions<PageOptions, BP extends BrowserPlugin> {
|
|
410
483
|
/**
|
|
@@ -435,4 +508,3 @@ export interface BrowserPoolNewPageInNewBrowserOptions<PageOptions, BP extends B
|
|
|
435
508
|
*/
|
|
436
509
|
launchOptions?: BP['launchOptions'];
|
|
437
510
|
}
|
|
438
|
-
//# sourceMappingURL=browser-pool.d.ts.map
|