Skip to main content
Version: Next

IBrowserPool <Page>

Minimal contract that any object passed to a browser crawler as its browserPool option must satisfy.

Lifecycle (destroy) is the responsibility of whoever owns the pool — since a user-supplied pool is never owned by the crawler, the crawler never tears it down.

Implement this interface to plug a custom page-provisioning strategy into any Crawlee browser crawler — for example a remote browser farm, a session-aware pool that pins pages to fingerprints differently, or a thin wrapper around the built-in BrowserPool.

Implemented by

Index

Methods

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 once the page's session is finished).


    Parameters

    • page: Page

      The page to release back to the pool.

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

        If the error is a SessionError, the session that served the page is finished. A plain SessionError means it was blocked: discard any browser state tied to it. A SessionRetiredError means it merely reached its usage or age limit, so a pool may keep a warm page instead.

    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. The pool decides which browser to use, launching a new one if needed.


    Parameters

    Returns Promise<Page>