Skip to main content
Version: Next

PlaywrightBrowserController

Controller for managing Playwright browser instances and their pages.

It provides methods to control browser instances, manage their pages, and handle context-specific configurations. It enforces limits on the number of open pages and tracks their state.

Hierarchy

Index

Methods

__init__

  • __init__(browser, *, max_open_pages_per_browser, use_incognito_pages, header_generator, fingerprint_generator): None
  • Initialize a new instance.


    Parameters

    • browser: Browser | PlaywrightPersistentBrowser

      The browser instance to control.

    • optionalkeyword-onlymax_open_pages_per_browser: int = 20

      The maximum number of pages that can be open at the same time.

    • optionalkeyword-onlyuse_incognito_pages: bool = False

      By default pages share the same browser context. If set to True each page uses its own context that is destroyed once the page is closed or crashes.

    • optionalkeyword-onlyheader_generator: HeaderGenerator | None = _DEFAULT_HEADER_GENERATOR

      An optional HeaderGenerator instance used to generate and manage HTTP headers for requests made by the browser. By default, a predefined header generator is used. Set to None to disable automatic header modifications.

    • optionalkeyword-onlyfingerprint_generator: FingerprintGenerator | None = None

      An optional instance of implementation of FingerprintGenerator that is used to generate browser fingerprints together with consistent headers.

    Returns None

close

  • async close(*, force): None
  • Close the browser.


    Parameters

    • optionalkeyword-onlyforce: bool = False

      Whether to force close all open pages before closing the browser.

    Returns None

new_page

  • async new_page(browser_new_context_options, proxy_info): Page

register_page_closed

  • register_page_closed(page): None
  • Stop tracking the page as open.

    Implementations must call it from the page's close event. The BrowserPool also calls it when closing the page never finishes, in which case that event never arrives, so it can be called more than once for the same page.


    Parameters

    • page: Page

      The page that is no longer open.

    Returns None

Properties

AUTOMATION_LIBRARY

AUTOMATION_LIBRARY: str | None

The name of the automation library that the controller is using.

browser_type

browser_type: BrowserType

Return the type of the browser.

has_free_capacity

has_free_capacity: bool

Return if the browser has free capacity to open a new page.

idle_time

idle_time: timedelta

Return the idle time of the browser controller.

is_browser_connected

is_browser_connected: bool

Return if the browser is closed.

is_opening_pages

is_opening_pages: bool

Return if the browser has any new_page calls currently in flight.

last_page_opened_at

last_page_opened_at: datetime

Return the time when the last page was opened.

pages

pages: Sequence[Page]

Return the list of opened pages.

pages_count

pages_count: int

Return the number of currently open pages.

total_opened_pages

total_opened_pages: int

Return the total number of pages opened since the browser was launched.