fix(m0): keep navigator.webdriver off so YouTube does not stop the video a minute in
With DevTools on (port or pipe), Chrome tells pages a program drives it, and YouTube then shows "문제가 발생했습니다" after about a minute of video, which spoilt every window on the gaming PC. Reproduced on Linux: the port alone, with no command sent, breaks playback at ~40 s; without it, or with --disable-blink-features=AutomationControlled, it plays on. The browser is now started with that switch, and one that still reports webdriver is refused before Jarvis is started. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -347,6 +347,16 @@ def find_browser() -> str | None:
|
||||
return next((shutil.which(n) for n in ("google-chrome", "chromium", "chromium-browser") if shutil.which(n)), None)
|
||||
|
||||
|
||||
def _says_automated(cdp: Cdp) -> bool:
|
||||
"""Whether pages see navigator.webdriver; asked again while the first page is still loading."""
|
||||
for _ in range(10):
|
||||
try:
|
||||
return cdp.evaluate("navigator.webdriver") is True
|
||||
except RuntimeError:
|
||||
time.sleep(0.5)
|
||||
return False
|
||||
|
||||
|
||||
def open_video_page(work: Path, url: str = VIDEO_URL, extra_args: tuple[str, ...] = ()) -> VideoPage | None:
|
||||
"""Open ``url`` in a new throwaway profile with DevTools on a free port. None without a browser."""
|
||||
exe = find_browser()
|
||||
@@ -356,7 +366,11 @@ def open_video_page(work: Path, url: str = VIDEO_URL, extra_args: tuple[str, ...
|
||||
shutil.rmtree(profile, ignore_errors=True)
|
||||
profile.mkdir(parents=True)
|
||||
# Kept running and drawing even if another window covers part of it; muted (nobody listens).
|
||||
# DevTools makes Chrome set navigator.webdriver, and YouTube then stops the video about a minute in
|
||||
# with "문제가 발생했습니다" (every window on the gaming PC, 2026-11-11); AutomationControlled off
|
||||
# keeps it false.
|
||||
proc = subprocess.Popen([exe, f"--user-data-dir={profile}", "--remote-debugging-port=0", "--no-first-run",
|
||||
"--disable-blink-features=AutomationControlled",
|
||||
"--no-default-browser-check", "--autoplay-policy=no-user-gesture-required",
|
||||
"--mute-audio", "--start-maximized", "--disable-backgrounding-occluded-windows",
|
||||
"--disable-renderer-backgrounding", "--disable-background-timer-throttling",
|
||||
@@ -371,7 +385,12 @@ def open_video_page(work: Path, url: str = VIDEO_URL, extra_args: tuple[str, ...
|
||||
page = next((p for p in (pages or []) if p.get("type") == "page" and "youtube" in p.get("url", "")),
|
||||
None) if code == 200 else None
|
||||
if page:
|
||||
return VideoPage(Cdp(page["webSocketDebuggerUrl"]), proc, profile, url)
|
||||
vp = VideoPage(Cdp(page["webSocketDebuggerUrl"]), proc, profile, url)
|
||||
if _says_automated(vp.cdp):
|
||||
vp.close()
|
||||
raise RuntimeError("the browser tells pages a program drives it (navigator.webdriver), "
|
||||
"so YouTube would stop the video about a minute in")
|
||||
return vp
|
||||
time.sleep(1)
|
||||
break
|
||||
if proc.poll() is not None:
|
||||
|
||||
Reference in New Issue
Block a user