@@ -1211,7 +1211,10 @@ def start_devtools(self):
12111211 raise RuntimeError ("CDP support for Firefox has been removed. Please switch to WebDriver BiDi." )
12121212 self ._websocket_connection = WebSocketConnection (ws_url )
12131213 targets = self ._websocket_connection .execute (self ._devtools .target .get_targets ())
1214- target_id = targets [0 ].target_id
1214+ for target in targets :
1215+ if target .target_id == self .current_window_handle :
1216+ target_id = target .target_id
1217+ break
12151218 session = self ._websocket_connection .execute (self ._devtools .target .attach_to_target (target_id , True ))
12161219 self ._websocket_connection .session_id = session
12171220 return self ._devtools , self ._websocket_connection
@@ -1232,7 +1235,10 @@ async def bidi_connection(self):
12321235 devtools = cdp .import_devtools (version )
12331236 async with cdp .open_cdp (ws_url ) as conn :
12341237 targets = await conn .execute (devtools .target .get_targets ())
1235- target_id = targets [0 ].target_id
1238+ for target in targets :
1239+ if target .target_id == self .current_window_handle :
1240+ target_id = target .target_id
1241+ break
12361242 async with conn .open_session (target_id ) as session :
12371243 yield BidiConnection (session , cdp , devtools )
12381244
@@ -1423,7 +1429,7 @@ def _get_cdp_details(self):
14231429 try :
14241430 if self .caps .get ("browserName" ) == "chrome" :
14251431 debugger_address = self .caps .get ("goog:chromeOptions" ).get ("debuggerAddress" )
1426- elif self .caps .get ("browserName" ) == "MicrosoftEdge" :
1432+ elif self .caps .get ("browserName" ) in ( "MicrosoftEdge" , "webview2" ) :
14271433 debugger_address = self .caps .get ("ms:edgeOptions" ).get ("debuggerAddress" )
14281434 except AttributeError :
14291435 raise WebDriverException ("Can't get debugger address." )
0 commit comments