feat(auth): auto-launch background browser if CDP is down during cookie extraction
This commit is contained in:
@@ -6,6 +6,8 @@ instance inside its isolated network namespace and save to ~/.config/muse-cli/<n
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
import subprocess
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
@@ -36,6 +38,27 @@ def export_cookies(node):
|
||||
print("websocket-client not installed", file=sys.stderr)
|
||||
return False
|
||||
|
||||
# Check if CDP port is responding; if not, attempt background browser launch
|
||||
try:
|
||||
urllib.request.urlopen(f"http://127.0.0.1:{port}/json", timeout=2)
|
||||
except Exception:
|
||||
print(f"CDP unreachable on port {port}. Attempting background browser launch for {node}...", file=sys.stderr)
|
||||
try:
|
||||
subprocess.Popen([
|
||||
str(Path(__file__).resolve().parent / "netvm-chrome.sh"),
|
||||
"--headless", node, "https://muse.ai"
|
||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
# Give it up to 6 seconds to bind
|
||||
for _ in range(12):
|
||||
time.sleep(0.5)
|
||||
try:
|
||||
urllib.request.urlopen(f"http://127.0.0.1:{port}/json", timeout=1)
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
print(f"Failed to launch browser: {e}", file=sys.stderr)
|
||||
|
||||
try:
|
||||
req = urllib.request.urlopen(f"http://127.0.0.1:{port}/json", timeout=3)
|
||||
tabs = json.loads(req.read().decode())
|
||||
|
||||
Reference in New Issue
Block a user