@crawlee/browser-pool 4.0.0-beta.13 → 4.0.0-beta.131
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 +17 -13
- 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 +211 -83
- 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 +10 -11
- 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 +20 -10
- 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 +164 -0
- package/remote-browser-pool.js +192 -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/tsconfig.build.tsbuildinfo +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;
|
|
@@ -263,6 +266,7 @@ export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoo
|
|
|
263
266
|
pageCounter: number;
|
|
264
267
|
pages: Map<string, PageReturn>;
|
|
265
268
|
pageIds: WeakMap<PageReturn, string>;
|
|
269
|
+
startingBrowserControllers: Set<BrowserControllerReturn>;
|
|
266
270
|
activeBrowserControllers: Set<BrowserControllerReturn>;
|
|
267
271
|
retiredBrowserControllers: Set<BrowserControllerReturn>;
|
|
268
272
|
pageToBrowserController: WeakMap<PageReturn, BrowserControllerReturn>;
|
|
@@ -270,13 +274,23 @@ export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoo
|
|
|
270
274
|
fingerprintGenerator?: FingerprintGenerator;
|
|
271
275
|
fingerprintCache?: QuickLRU<string, BrowserFingerprintWithHeaders>;
|
|
272
276
|
private browserKillerInterval?;
|
|
273
|
-
private browserRetireInterval?;
|
|
274
|
-
private limiter;
|
|
275
277
|
constructor(options: Options & BrowserPoolHooks<BrowserControllerReturn, LaunchContextReturn, PageReturn>);
|
|
276
278
|
/**
|
|
277
279
|
* Opens a new page in one of the running browsers or launches
|
|
278
280
|
* a new browser and opens a page there, if no browsers are active,
|
|
279
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.
|
|
280
294
|
*/
|
|
281
295
|
newPage(options?: BrowserPoolNewPageOptions<PageOptions, BrowserPlugins[number]>): Promise<PageReturn>;
|
|
282
296
|
/**
|
|
@@ -334,7 +348,7 @@ export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoo
|
|
|
334
348
|
* until it's closed.
|
|
335
349
|
*/
|
|
336
350
|
getPageId(page: PageReturn): string | undefined;
|
|
337
|
-
private
|
|
351
|
+
private createPageForBrowser;
|
|
338
352
|
/**
|
|
339
353
|
* Removes a browser controller from the pool. The underlying
|
|
340
354
|
* browser will be closed after all its pages are closed.
|
|
@@ -346,6 +360,43 @@ export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoo
|
|
|
346
360
|
* closed after all its pages are closed.
|
|
347
361
|
*/
|
|
348
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>;
|
|
349
400
|
/**
|
|
350
401
|
* Removes all active browsers from the pool. The browsers will be
|
|
351
402
|
* closed after all their pages are closed.
|
|
@@ -360,28 +411,58 @@ export declare class BrowserPool<Options extends BrowserPoolOptions = BrowserPoo
|
|
|
360
411
|
* Closes all managed browsers and tears down the pool.
|
|
361
412
|
*/
|
|
362
413
|
destroy(): Promise<void>;
|
|
363
|
-
private
|
|
364
|
-
private
|
|
365
|
-
private
|
|
414
|
+
private teardown;
|
|
415
|
+
private getAllBrowserControllers;
|
|
416
|
+
private launchBrowser;
|
|
366
417
|
/**
|
|
367
418
|
* Picks plugins round robin.
|
|
368
419
|
* @private
|
|
369
420
|
*/
|
|
370
|
-
private
|
|
371
|
-
private
|
|
372
|
-
private
|
|
373
|
-
private
|
|
374
|
-
private
|
|
375
|
-
private
|
|
376
|
-
|
|
377
|
-
|
|
421
|
+
private pickBrowserPlugin;
|
|
422
|
+
private pickBrowserWithFreeCapacity;
|
|
423
|
+
private closeInactiveRetiredBrowsers;
|
|
424
|
+
private overridePageClose;
|
|
425
|
+
private executeHooks;
|
|
426
|
+
private closeRetiredBrowserWithNoPages;
|
|
427
|
+
/**
|
|
428
|
+
* Returns `true` if the pool can accept a new browser launch without exceeding
|
|
429
|
+
* {@link BrowserPoolOptions.maxOpenBrowsers}. Counts starting, active, and retired browsers.
|
|
430
|
+
*/
|
|
431
|
+
hasFreeBrowserSlot(): boolean;
|
|
432
|
+
/**
|
|
433
|
+
* Returns `true` if any active browser has room for another page.
|
|
434
|
+
*/
|
|
435
|
+
hasActiveBrowserWithFreeCapacity(): boolean;
|
|
436
|
+
private initializeFingerprinting;
|
|
437
|
+
private addFingerprintHooks;
|
|
378
438
|
}
|
|
379
|
-
export interface BrowserPoolNewPageOptions<PageOptions, BP extends BrowserPlugin> {
|
|
439
|
+
export interface BrowserPoolNewPageOptions<PageOptions, BP extends BrowserPlugin> extends NewPageOptions {
|
|
440
|
+
/**
|
|
441
|
+
* The proxy URL the pool uses internally to route the page: it keys browser
|
|
442
|
+
* reuse (with `browserPerProxy`, only a browser already on this proxy is
|
|
443
|
+
* reused), configures the launched browser, and is applied to incognito
|
|
444
|
+
* pages. When omitted, it is derived from the
|
|
445
|
+
* {@link NewPageOptions.session|session}'s `proxyInfo`; an explicit value
|
|
446
|
+
* here takes precedence.
|
|
447
|
+
*
|
|
448
|
+
* This is an implementation detail of the built-in `BrowserPool`'s proxy
|
|
449
|
+
* handling and is intentionally not part of the {@link IBrowserPool}
|
|
450
|
+
* contract — through that interface the proxy is supplied via the session.
|
|
451
|
+
*/
|
|
452
|
+
proxyUrl?: string;
|
|
380
453
|
/**
|
|
381
|
-
*
|
|
382
|
-
*
|
|
454
|
+
* Disable TLS certificate verification for MITM proxies. Applied both when
|
|
455
|
+
* launching a new browser and when creating a page in an existing one. When
|
|
456
|
+
* omitted, it is derived from the
|
|
457
|
+
* {@link NewPageOptions.session|session}'s `proxyInfo`; an explicit value
|
|
458
|
+
* here takes precedence.
|
|
459
|
+
*
|
|
460
|
+
* This is an implementation detail of the built-in `BrowserPool` and is
|
|
461
|
+
* intentionally not part of the {@link IBrowserPool} contract — through
|
|
462
|
+
* that interface, configure it via the session's `proxyInfo` or through the
|
|
463
|
+
* browser's `launchOptions`.
|
|
383
464
|
*/
|
|
384
|
-
|
|
465
|
+
ignoreTlsErrors?: boolean;
|
|
385
466
|
/**
|
|
386
467
|
* Some libraries (Playwright) allow you to open new pages with specific
|
|
387
468
|
* options. Use this property to set those options.
|
|
@@ -396,14 +477,6 @@ export interface BrowserPoolNewPageOptions<PageOptions, BP extends BrowserPlugin
|
|
|
396
477
|
* see the `newPageInNewBrowser` function.
|
|
397
478
|
*/
|
|
398
479
|
browserPlugin?: BP;
|
|
399
|
-
/**
|
|
400
|
-
* Proxy URL.
|
|
401
|
-
*/
|
|
402
|
-
proxyUrl?: string;
|
|
403
|
-
/**
|
|
404
|
-
* Proxy tier.
|
|
405
|
-
*/
|
|
406
|
-
proxyTier?: number;
|
|
407
480
|
}
|
|
408
481
|
export interface BrowserPoolNewPageInNewBrowserOptions<PageOptions, BP extends BrowserPlugin> {
|
|
409
482
|
/**
|
|
@@ -434,4 +507,3 @@ export interface BrowserPoolNewPageInNewBrowserOptions<PageOptions, BP extends B
|
|
|
434
507
|
*/
|
|
435
508
|
launchOptions?: BP['launchOptions'];
|
|
436
509
|
}
|
|
437
|
-
//# sourceMappingURL=browser-pool.d.ts.map
|