Skip to main content
Version: Next

RemoteBrowserPool <Page>

An IBrowserPool implementation for remote browser services.

Unlike configuring a remote browser through a crawler's launchContext, this pool is the single owner of all remote-session concerns:

  • endpoint resolution — static URL, per-launch function, or RemoteBrowserProvider;
  • release lifecyclerelease() fires exactly once per session on close/crash/teardown (no leaks, no double-release);
  • concurrencymaxOpenBrowsers is enforced inside newPage, which waits for a free slot rather than overshooting.

The wrapped BrowserPool and its plugin only perform the library-specific connect() call.

Pass an instance as the crawler's browserPool option:

import { PlaywrightPlugin, RemoteBrowserPool } from '@crawlee/browser-pool';
import { PlaywrightCrawler } from 'crawlee';
import playwright from 'playwright';

const browserPool = new RemoteBrowserPool({
browserPlugins: [new PlaywrightPlugin(playwright.chromium)],
endpoint: 'wss://production-sfo.browserless.io?token=xxx',
maxOpenBrowsers: 2,
});

const crawler = new PlaywrightCrawler({ browserPool });

Implements

Index

Constructors

constructor

Properties

readonlybrowserPool

browserPool: BrowserPool<BrowserPoolOptions<BrowserPlugin<CommonLibrary, undefined | Dictionary, CommonBrowser, unknown, CommonPage>>, never, never, never, never, never>

The wrapped pool that performs the remote connections and serves pages.

Accessors

maxOpenBrowsers

  • get maxOpenBrowsers(): number
  • set maxOpenBrowsers(value): void
  • Maximum number of remote browsers that may be open at the same time.


    Returns number

  • Parameters

    • value: number

    Returns void

Methods

[asyncDispose]

  • [asyncDispose](): Promise<void>
  • Returns Promise<void>

closePage

  • closePage(page, options): Promise<void>
  • Signals the pool that the caller is done with the page. The pool is responsible for closing the page and performing any necessary cleanup (e.g. retiring the underlying browser when a session has gone bad).


    Parameters

    • page: Page

      The page to release back to the pool.

    • optionaloptions: { error?: Error }
      • optionalerror: Error

        If the page is being released because of an error, pass the error here. In particular, if the error is a SessionError, implementations should treat it as a signal to purge all state associated with the session (e.g. discard any browser that served the page).

    Returns Promise<void>

destroy

  • destroy(): Promise<void>
  • Closes all browsers, releases any still-open remote sessions, and tears down the wrapped pool.


    Returns Promise<void>

extractPageState

  • Extracts the relevant state from a page so the caller can persist it — for example, back-propagating cookies into the crawling session.


    Parameters

    • page: Page

      The page to read state from.

    Returns Promise<PageState>

injectPageState

  • injectPageState(page, state): Promise<void>
  • Injects state (currently just cookies) into a page. This is the counterpart to IBrowserPool.extractPageState and lets the caller set up a page — for example, seeding it with the crawling session's cookies before navigation.

    As with IBrowserPool.newPage, the caller decides what state to inject, while the pool decides how.

    Isolation between pages is best-effort: depending on the pool implementation and its configuration, multiple pages may share a browsing context, so injected state (such as cookies) can bleed across pages served by the same underlying browser.


    Parameters

    • page: Page

      The page to inject state into.

    • state: PageState

      The state to inject.

    Returns Promise<void>

newPage

  • newPage(options): Promise<Page>
  • Opens a new page, waiting first until maxOpenBrowsers allows it (either a new browser slot is free, or an active browser still has page capacity).


    Parameters

    Returns Promise<Page>