@@ -91,20 +91,6 @@ async def _get_context_creation_lock(self) -> Lock:
9191 self ._context_creation_lock = Lock ()
9292 return self ._context_creation_lock
9393
94- async def _get_browser_context (
95- self ,
96- browser_new_context_options : Mapping [str , Any ] | None = None ,
97- proxy_info : ProxyInfo | None = None ,
98- ) -> BrowserContext :
99- """Ensure that the browser context is set."""
100- async with await self ._get_context_creation_lock ():
101- if not self ._browser_context :
102- self ._browser_context = await self ._create_browser_context (
103- browser_new_context_options = browser_new_context_options ,
104- proxy_info = proxy_info ,
105- )
106- return self ._browser_context
107-
10894 @property
10995 @override
11096 def pages (self ) -> list [Page ]:
@@ -176,8 +162,13 @@ async def new_page(
176162 )
177163 page = await new_context .new_page ()
178164 else :
179- _browser_context = await self ._get_browser_context ()
180- page = await _browser_context .new_page ()
165+ async with await self ._get_context_creation_lock ():
166+ if not self ._browser_context :
167+ self ._browser_context = await self ._create_browser_context (
168+ browser_new_context_options = browser_new_context_options ,
169+ proxy_info = proxy_info ,
170+ )
171+ page = await self ._browser_context .new_page ()
181172
182173 # Handle page close event
183174 page .on (event = 'close' , f = self ._on_page_close )
0 commit comments