| 1249 | raise WebDriverException("You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'") |
| 1250 | |
| 1251 | def start_devtools(self) -> tuple[Any, WebSocketConnection]: |
| 1252 | global cdp |
| 1253 | import_cdp() |
| 1254 | if self.caps.get("se:cdp"): |
| 1255 | ws_url = self.caps.get("se:cdp") |
| 1256 | cdp_version = self.caps.get("se:cdpVersion") |
| 1257 | if cdp_version is None: |
| 1258 | raise WebDriverException("CDP version not found in capabilities") |
| 1259 | version = cdp_version.split(".")[0] |
| 1260 | else: |
| 1261 | version, ws_url = self._get_cdp_details() |
| 1262 | |
| 1263 | if not ws_url: |
| 1264 | raise WebDriverException("Unable to find url to connect to from capabilities") |
| 1265 | |
| 1266 | if cdp is None: |
| 1267 | raise WebDriverException("CDP module not loaded") |
| 1268 | |
| 1269 | self._devtools = cdp.import_devtools(version) |
| 1270 | if self._websocket_connection: |
| 1271 | return self._devtools, self._websocket_connection |
| 1272 | if self.caps["browserName"].lower() == "firefox": |
| 1273 | raise RuntimeError("CDP support for Firefox has been removed. Please switch to WebDriver BiDi.") |
| 1274 | if not isinstance(self.command_executor, RemoteConnection): |
| 1275 | raise WebDriverException("command_executor must be a RemoteConnection instance for CDP support") |
| 1276 | self._websocket_connection = WebSocketConnection(ws_url, self.command_executor.client_config.websocket_timeout) |
| 1277 | targets = self._websocket_connection.execute(self._devtools.target.get_targets()) |
| 1278 | for target in targets: |
| 1279 | if target.target_id == self.current_window_handle: |
| 1280 | target_id = target.target_id |
| 1281 | break |
| 1282 | session = self._websocket_connection.execute(self._devtools.target.attach_to_target(target_id, True)) |
| 1283 | self._websocket_connection.session_id = session |
| 1284 | return self._devtools, self._websocket_connection |
| 1285 | |
| 1286 | @asynccontextmanager |
| 1287 | async def bidi_connection(self): |