@@ -65,6 +65,7 @@ def __init__(
65
65
self , parent : "BrowserType" , type : str , guid : str , initializer : Dict
66
66
) -> None :
67
67
super ().__init__ (parent , type , guid , initializer )
68
+ self ._browser_type : Optional ["BrowserType" ] = None
68
69
self ._is_connected = True
69
70
self ._should_close_connection_on_close = False
70
71
self ._cr_tracing_path : Optional [str ] = None
@@ -105,7 +106,10 @@ def _did_create_context(self, context: BrowserContext) -> None:
105
106
106
107
def _setup_browser_context (self , context : BrowserContext ) -> None :
107
108
context ._tracing ._traces_dir = self ._traces_dir
108
- self ._browser_type ._playwright .selectors ._contexts_for_selectors .add (context )
109
+ if self ._browser_type :
110
+ self ._browser_type ._playwright .selectors ._contexts_for_selectors .add (
111
+ context
112
+ )
109
113
110
114
def _on_close (self ) -> None :
111
115
self ._is_connected = False
@@ -117,6 +121,10 @@ def contexts(self) -> List[BrowserContext]:
117
121
118
122
@property
119
123
def browser_type (self ) -> "BrowserType" :
124
+ if not self ._browser_type :
125
+ raise RuntimeError (
126
+ "_browser_type is not set. Make sure _connect_to_browser_type() is called on initialization."
127
+ )
120
128
return self ._browser_type
121
129
122
130
def is_connected (self ) -> bool :
@@ -162,7 +170,8 @@ async def new_context(
162
170
clientCertificates : List [ClientCertificate ] = None ,
163
171
) -> BrowserContext :
164
172
params = locals_to_params (locals ())
165
- await self ._browser_type ._prepare_browser_context_params (params )
173
+ if self ._browser_type :
174
+ await self ._browser_type ._prepare_browser_context_params (params )
166
175
167
176
channel = await self ._channel .send ("newContext" , params )
168
177
context = cast (BrowserContext , from_channel (channel ))
0 commit comments