#!/usr/bin/env python """Launch real Chrome with CDP on 9223 (detached) for context.dev flow.""" import os, sys, subprocess, time, json, urllib.request CHROME = os.environ.get("CTX_CHROME_BIN", r"C:\Program Files\Google\Chrome\Application\chrome.exe") BASE = os.path.dirname(os.path.abspath(__file__)) PROF = os.environ.get("CTX_CHROME_PROF", os.path.join(BASE, "chrome_prof")) PORT = int(os.environ.get("CTX_CDP_PORT", "9223")) PROXY = os.environ.get("CTX_CHROME_PROXY", "") os.makedirs(PROF, exist_ok=True) def up(): try: with urllib.request.urlopen("http://127.0.0.1:%d/json/version" % PORT, timeout=2) as r: return json.loads(r.read().decode()) except Exception: return None if not up(): args = [CHROME, "--remote-debugging-port=%d" % PORT, "--user-data-dir=" + PROF, "--no-first-run", "--no-default-browser-check", "--disable-blink-features=AutomationControlled", "--window-size=1280,900"] if PROXY: args.append("--proxy-server=" + PROXY) args.append("--proxy-bypass-list=<-loopback>") args.append("about:blank") subprocess.Popen(args, creationflags=subprocess.DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, close_fds=True) for _ in range(25): time.sleep(1) if up(): break v = up() print("CDP:", "up" if v else "DOWN", (v or {}).get("Browser", ""))