@@ -35,26 +35,26 @@ def __init__(
35
35
self ,
36
36
* ,
37
37
browser_type : BrowserType = 'chromium' ,
38
- browser_options : Mapping [str , Any ] | None = None ,
39
- page_options : Mapping [str , Any ] | None = None ,
38
+ browser_launch_options : Mapping [str , Any ] | None = None ,
39
+ browser_new_context_options : Mapping [str , Any ] | None = None ,
40
40
max_open_pages_per_browser : int = 20 ,
41
41
) -> None :
42
42
"""A default constructor.
43
43
44
44
Args:
45
45
browser_type: The type of browser to launch ('chromium', 'firefox', or 'webkit').
46
- browser_options : Keyword arguments to pass to the browser launch method. These options are provided
46
+ browser_launch_options : Keyword arguments to pass to the browser launch method. These options are provided
47
47
directly to Playwright's `browser_type.launch` method. For more details, refer to the Playwright
48
48
documentation: https://playwright.dev/python/docs/api/class-browsertype#browser-type-launch.
49
- page_options : Keyword arguments to pass to the page object is set at the playwright context level.
50
- These options are provided directly to Playwright's `browser.new_context` method. For more details,
51
- refer to the Playwright documentation: https://playwright.dev/python/docs/api/class-browser#browser-new-context.
49
+ browser_new_context_options : Keyword arguments to pass to the browser new context method. These options
50
+ are provided directly to Playwright's `browser.new_context` method. For more details, refer to the
51
+ Playwright documentation: https://playwright.dev/python/docs/api/class-browser#browser-new-context.
52
52
max_open_pages_per_browser: The maximum number of pages that can be opened in a single browser instance.
53
53
Once reached, a new browser instance will be launched to handle the excess.
54
54
"""
55
55
self ._browser_type = browser_type
56
- self ._browser_options = browser_options or {}
57
- self ._page_options = page_options or {}
56
+ self ._browser_launch_options = browser_launch_options or {}
57
+ self ._browser_new_context_options = browser_new_context_options or {}
58
58
self ._max_open_pages_per_browser = max_open_pages_per_browser
59
59
60
60
self ._playwright_context_manager = async_playwright ()
@@ -75,13 +75,25 @@ def browser_type(self) -> BrowserType:
75
75
76
76
@property
77
77
@override
78
- def browser_options (self ) -> Mapping [str , Any ]:
79
- return self ._browser_options
78
+ def browser_launch_options (self ) -> Mapping [str , Any ]:
79
+ """Return the options for the `browser.launch` method.
80
+
81
+ Keyword arguments to pass to the browser launch method. These options are provided directly to Playwright's
82
+ `browser_type.launch` method. For more details, refer to the Playwright documentation:
83
+ https://playwright.dev/python/docs/api/class-browsertype#browser-type-launch.
84
+ """
85
+ return self ._browser_launch_options
80
86
81
87
@property
82
88
@override
83
- def page_options (self ) -> Mapping [str , Any ]:
84
- return self ._page_options
89
+ def browser_new_context_options (self ) -> Mapping [str , Any ]:
90
+ """Return the options for the `browser.new_context` method.
91
+
92
+ Keyword arguments to pass to the browser new context method. These options are provided directly to Playwright's
93
+ `browser.new_context` method. For more details, refer to the Playwright documentation:
94
+ https://playwright.dev/python/docs/api/class-browser#browser-new-context.
95
+ """
96
+ return self ._browser_new_context_options
85
97
86
98
@property
87
99
@override
@@ -117,11 +129,11 @@ async def new_browser(self) -> PlaywrightBrowserController:
117
129
raise RuntimeError ('Playwright browser plugin is not initialized.' )
118
130
119
131
if self ._browser_type == 'chromium' :
120
- browser = await self ._playwright .chromium .launch (** self ._browser_options )
132
+ browser = await self ._playwright .chromium .launch (** self ._browser_launch_options )
121
133
elif self ._browser_type == 'firefox' :
122
- browser = await self ._playwright .firefox .launch (** self ._browser_options )
134
+ browser = await self ._playwright .firefox .launch (** self ._browser_launch_options )
123
135
elif self ._browser_type == 'webkit' :
124
- browser = await self ._playwright .webkit .launch (** self ._browser_options )
136
+ browser = await self ._playwright .webkit .launch (** self ._browser_launch_options )
125
137
else :
126
138
raise ValueError (f'Invalid browser type: { self ._browser_type } ' )
127
139
0 commit comments