1
1
from __future__ import annotations
2
2
3
3
import logging
4
- from typing import TYPE_CHECKING , Awaitable , Callable
4
+ from typing import TYPE_CHECKING , Any , Awaitable , Callable , Mapping
5
5
6
6
from pydantic import ValidationError
7
7
@@ -71,6 +71,8 @@ def __init__(
71
71
self ,
72
72
browser_pool : BrowserPool | None = None ,
73
73
browser_type : BrowserType | None = None ,
74
+ browser_options : Mapping [str , Any ] | None = None ,
75
+ page_options : Mapping [str , Any ] | None = None ,
74
76
headless : bool | None = None ,
75
77
** kwargs : Unpack [BasicCrawlerOptions [PlaywrightCrawlingContext ]],
76
78
) -> None :
@@ -80,20 +82,30 @@ def __init__(
80
82
browser_pool: A `BrowserPool` instance to be used for launching the browsers and getting pages.
81
83
browser_type: The type of browser to launch ('chromium', 'firefox', or 'webkit').
82
84
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.
83
89
headless: Whether to run the browser in headless mode.
84
90
This option should not be used if `browser_pool` is provided.
85
91
kwargs: Additional keyword arguments to pass to the underlying `BasicCrawler`.
86
92
"""
87
93
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 )) :
90
96
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.'
92
99
)
93
100
94
101
# If browser_pool is not provided, create a new instance of BrowserPool with specified arguments.
95
102
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
+ )
97
109
98
110
self ._browser_pool = browser_pool
99
111
0 commit comments