Repository: apify/crawlee-python
File: src/crawlee/browsers/_base_browser_controller.py (Python)

Code before:

    @property
    @abstractmethod
    def has_free_capacity(self) -> bool:
        """Return if the browser has free capacity to open a new page."""

    @property
    @abstractmethod
    def is_browser_connected(self) -> bool:
        """Return if the browser is closed."""

    @property
    @abstractmethod
    def browser_type(self) -> BrowserType:
        """Return the type of the browser."""

    @abstractmethod
    async def new_page(
        self,
        browser_new_context_options: Mapping[str, Any] | None = None,
        proxy_info: ProxyInfo | None = None,
    ) -> Page:
        """Create a new page with the given context options.

        Args:
            browser_new_context_options: Options to configure the new context used for creating new page.
            proxy_info: The proxy configuration to use for the new page.

        Returns:
            Page: The newly created page.

        Raises:
            ValueError: If the browser has reached the maximum number of open pages.
        """

    @abstractmethod
    async def close(self, *, force: bool = False) -> None:
        """Close the browser.

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

        Raises:
            ValueError: If there are still open pages when trying to close the browser.
        """


Review comment (suggestion):
Could we use the same docstring as in the PW crawler (except for the "This option should not be used if `browser_pool` is provided.")? This is also end-user interface.

Code after:

    @property
    @abstractmethod
    def has_free_capacity(self) -> bool:
        """Return if the browser has free capacity to open a new page."""

    @property
    @abstractmethod
    def is_browser_connected(self) -> bool:
        """Return if the browser is closed."""

    @property
    @abstractmethod
    def browser_type(self) -> BrowserType:
        """Return the type of the browser."""

    @abstractmethod
    async def new_page(
        self,
        browser_new_context_options: Mapping[str, Any] | None = None,
        proxy_info: ProxyInfo | None = None,
    ) -> Page:
        """Create a new page with the given context options.

        Args:
            browser_new_context_options: Keyword arguments to pass to the browser new context method. These options
                are provided directly to Playwright's `browser.new_context` method. For more details, refer to the
                Playwright documentation: https://playwright.dev/python/docs/api/class-browser#browser-new-context.
            proxy_info: The proxy configuration to use for the new page.

        Returns:
            Page: The newly created page.

        Raises:
            ValueError: If the browser has reached the maximum number of open pages.
        """

    @abstractmethod
    async def close(self, *, force: bool = False) -> None:
        """Close the browser.

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

        Raises:
            ValueError: If there are still open pages when trying to close the browser.
        """