@@ -1211,7 +1211,10 @@ def start_devtools(self):
1211
1211
raise RuntimeError ("CDP support for Firefox has been removed. Please switch to WebDriver BiDi." )
1212
1212
self ._websocket_connection = WebSocketConnection (ws_url )
1213
1213
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
1215
1218
session = self ._websocket_connection .execute (self ._devtools .target .attach_to_target (target_id , True ))
1216
1219
self ._websocket_connection .session_id = session
1217
1220
return self ._devtools , self ._websocket_connection
@@ -1232,7 +1235,10 @@ async def bidi_connection(self):
1232
1235
devtools = cdp .import_devtools (version )
1233
1236
async with cdp .open_cdp (ws_url ) as conn :
1234
1237
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
1236
1242
async with conn .open_session (target_id ) as session :
1237
1243
yield BidiConnection (session , cdp , devtools )
1238
1244
@@ -1423,7 +1429,7 @@ def _get_cdp_details(self):
1423
1429
try :
1424
1430
if self .caps .get ("browserName" ) == "chrome" :
1425
1431
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" ) :
1427
1433
debugger_address = self .caps .get ("ms:edgeOptions" ).get ("debuggerAddress" )
1428
1434
except AttributeError :
1429
1435
raise WebDriverException ("Can't get debugger address." )
0 commit comments