11from __future__ import annotations
22
33import logging
4- from typing import TYPE_CHECKING , Awaitable , Callable
4+ from typing import TYPE_CHECKING , Any , Awaitable , Callable , Mapping
55
66from pydantic import ValidationError
77
@@ -71,6 +71,8 @@ def __init__(
7171 self ,
7272 browser_pool : BrowserPool | None = None ,
7373 browser_type : BrowserType | None = None ,
74+ browser_options : Mapping [str , Any ] | None = None ,
75+ page_options : Mapping [str , Any ] | None = None ,
7476 headless : bool | None = None ,
7577 ** kwargs : Unpack [BasicCrawlerOptions [PlaywrightCrawlingContext ]],
7678 ) -> None :
@@ -80,20 +82,30 @@ def __init__(
8082 browser_pool: A `BrowserPool` instance to be used for launching the browsers and getting pages.
8183 browser_type: The type of browser to launch ('chromium', 'firefox', or 'webkit').
8284 This option should not be used if `browser_pool` is provided.
85+ browser_options: Keyword arguments to pass to the browser launch method.
86+ This option should not be used if `browser_pool` is provided.
87+ page_options: Keyword arguments to pass to the new page method.
88+ This option should not be used if `browser_pool` is provided.
8389 headless: Whether to run the browser in headless mode.
8490 This option should not be used if `browser_pool` is provided.
8591 kwargs: Additional keyword arguments to pass to the underlying `BasicCrawler`.
8692 """
8793 if browser_pool :
88- # Raise an exception if browser_pool is provided together with headless or browser_type arguments.
89- if headless is not None or browser_type is not None :
94+ # Raise an exception if browser_pool is provided together with other browser-related arguments.
95+ if any ( param is not None for param in ( headless , browser_type , browser_options , page_options )) :
9096 raise ValueError (
91- 'You cannot provide `headless` or `browser_type` arguments when `browser_pool` is provided.'
97+ 'You cannot provide `headless`, `browser_type`, `browser_options` or `page_options` '
98+ 'arguments when `browser_pool` is provided.'
9299 )
93100
94101 # If browser_pool is not provided, create a new instance of BrowserPool with specified arguments.
95102 else :
96- browser_pool = BrowserPool .with_default_plugin (headless = headless , browser_type = browser_type )
103+ browser_pool = BrowserPool .with_default_plugin (
104+ headless = headless ,
105+ browser_type = browser_type ,
106+ browser_options = browser_options ,
107+ page_options = page_options ,
108+ )
97109
98110 self ._browser_pool = browser_pool
99111
0 commit comments