31
31
from playwright ._impl ._helper import (
32
32
ColorScheme ,
33
33
ReducedMotion ,
34
+ async_readfile ,
34
35
is_safe_close_error ,
35
36
locals_to_params ,
36
37
)
@@ -106,7 +107,7 @@ async def new_context(
106
107
storageState : Union [StorageState , str , Path ] = None ,
107
108
) -> BrowserContext :
108
109
params = locals_to_params (locals ())
109
- normalize_context_params (self ._connection ._is_sync , params )
110
+ await normalize_context_params (self ._connection ._is_sync , params )
110
111
111
112
channel = await self ._channel .send ("newContext" , params )
112
113
context = from_channel (channel )
@@ -190,7 +191,7 @@ async def stop_tracing(self) -> bytes:
190
191
return base64 .b64decode (encoded_binary )
191
192
192
193
193
- def normalize_context_params (is_sync : bool , params : Dict ) -> None :
194
+ async def normalize_context_params (is_sync : bool , params : Dict ) -> None :
194
195
params ["sdkLanguage" ] = "python" if is_sync else "python-async"
195
196
if params .get ("noViewport" ):
196
197
del params ["noViewport" ]
@@ -214,5 +215,6 @@ def normalize_context_params(is_sync: bool, params: Dict) -> None:
214
215
if "storageState" in params :
215
216
storageState = params ["storageState" ]
216
217
if not isinstance (storageState , dict ):
217
- with open (storageState , "r" ) as f :
218
- params ["storageState" ] = json .load (f )
218
+ params ["storageState" ] = json .loads (
219
+ (await async_readfile (storageState )).decode ()
220
+ )
0 commit comments