| 389 | logger.warning(f"Failed to extract SAPISID: {e}") |
| 390 | |
| 391 | def _setup_environment_variables(self, captured_ws_endpoint): |
| 392 | if not captured_ws_endpoint: |
| 393 | logger.error("Critical error: WebSocket endpoint not captured.") |
| 394 | sys.exit(1) |
| 395 | |
| 396 | os.environ["CAMOUFOX_WS_ENDPOINT"] = captured_ws_endpoint |
| 397 | os.environ["LAUNCH_MODE"] = self.final_launch_mode |
| 398 | os.environ["SERVER_LOG_LEVEL"] = self.args.server_log_level.upper() |
| 399 | |
| 400 | # Only set these env vars if CLI flags were explicitly provided |
| 401 | # Otherwise, preserve existing env var values (from .env files) |
| 402 | if ( |
| 403 | hasattr(self.args, "server_redirect_print_from_cli") |
| 404 | and self.args.server_redirect_print_from_cli |
| 405 | ): |
| 406 | os.environ["SERVER_REDIRECT_PRINT"] = str( |
| 407 | self.args.server_redirect_print |
| 408 | ).lower() |
| 409 | if hasattr(self.args, "debug_logs_from_cli") and self.args.debug_logs_from_cli: |
| 410 | os.environ["DEBUG_LOGS_ENABLED"] = str(self.args.debug_logs).lower() |
| 411 | if hasattr(self.args, "trace_logs_from_cli") and self.args.trace_logs_from_cli: |
| 412 | os.environ["TRACE_LOGS_ENABLED"] = str(self.args.trace_logs).lower() |
| 413 | if self.effective_active_auth_json_path: |
| 414 | os.environ["ACTIVE_AUTH_JSON_PATH"] = self.effective_active_auth_json_path |
| 415 | if ( |
| 416 | self.final_launch_mode == "debug" |
| 417 | and hasattr(self.args, "auto_save_auth_from_cli") |
| 418 | and self.args.auto_save_auth_from_cli |
| 419 | ): |
| 420 | os.environ["AUTO_SAVE_AUTH"] = str(self.args.auto_save_auth).lower() |
| 421 | |
| 422 | if self.args.save_auth_as: |
| 423 | os.environ["SAVE_AUTH_FILENAME"] = self.args.save_auth_as |
| 424 | os.environ["AUTH_SAVE_TIMEOUT"] = str(self.args.auth_save_timeout) |
| 425 | os.environ["SERVER_PORT_INFO"] = str(self.args.server_port) |
| 426 | os.environ["STREAM_PORT"] = str(self.args.stream_port) |
| 427 | |
| 428 | proxy_config = determine_proxy_configuration(self.args.internal_camoufox_proxy) |
| 429 | if proxy_config["stream_proxy"]: |
| 430 | os.environ["UNIFIED_PROXY_CONFIG"] = proxy_config["stream_proxy"] |
| 431 | logger.info(f"Unified proxy set: {proxy_config['source']}") |
| 432 | |
| 433 | camoufox_os = self.simulated_os_for_camoufox.lower() |
| 434 | host_os_map = {"macos": "Darwin", "windows": "Windows", "linux": "Linux"} |
| 435 | if camoufox_os in host_os_map: |
| 436 | os.environ["HOST_OS_FOR_SHORTCUT"] = host_os_map[camoufox_os] |
| 437 | |
| 438 | def _start_server(self): |
| 439 | logger.info( |