Skip to main content

PlaywrightBrowserController

Controller for managing Playwright browser instances and their pages.

This class provides methods to manage pages within a browser instance, ensuring that the number of open pages does not exceed the specified limit and tracking the state of the pages.

Hierarchy

Index

Methods

__init__

  • __init__(*, browser, max_open_pages_per_browser, header_generator): None
  • A default constructor.


    Parameters

    • optionalkeyword-onlybrowser: Browser

      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-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.

    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(*, page_options, proxy_info): Page
  • Create a new page with the given context options.


    Parameters

    • optionalkeyword-onlypage_options: Mapping[str, Any] | None = None

      Options to configure the new page.

    • optionalkeyword-onlyproxy_info: ProxyInfo | None = None

      The proxy configuration to use for the new page.

    Returns Page

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.

last_page_opened_at

last_page_opened_at: datetime

Return the time when the last page was opened.

pages

pages: list[Page]

Return the list of opened pages.

pages_count

pages_count: int

Returns the number of currently open pages.