1
0
Fork 0

refactor: harden ChatGPT token lifecycle with startup recovery, single-writer locking, and faster auth flow

This commit is contained in:
Arthur K. 2026-03-01 20:58:24 +03:00
parent 71d1050adb
commit 533e382e0e
Signed by: wzray
GPG key ID: B97F30FDC4636357
9 changed files with 313 additions and 178 deletions

View file

@ -1,7 +1,6 @@
import asyncio
import json
import logging
import os
import shutil
import subprocess
import tempfile
@ -45,6 +44,8 @@ CHROME_FLAGS = [
"--disable-search-engine-choice-screen",
]
DEFAULT_CDP_PORT = 9222
def _fetch_ws_endpoint(port: int) -> str | None:
try:
@ -78,9 +79,10 @@ class ManagedBrowser:
shutil.rmtree(self.profile_dir, ignore_errors=True)
async def launch(playwright: Playwright, cdp_port: int | None = None) -> ManagedBrowser:
chrome_path = os.environ.get("CHROMIUM_PATH") or playwright.chromium.executable_path
cdp_port = cdp_port or int(os.environ.get("CDP_PORT", "9222"))
async def launch(
playwright: Playwright, cdp_port: int = DEFAULT_CDP_PORT
) -> ManagedBrowser:
chrome_path = playwright.chromium.executable_path
profile_dir = Path(tempfile.mkdtemp(prefix="megapt_profile-", dir="/tmp"))
args = [