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:
@@ -1554,6 +1554,49 @@ def test_before_a_window_a_stopped_or_broken_player_is_started_again(monkeypatch
|
||||
assert not page.snapshot().get("lost")
|
||||
|
||||
|
||||
def test_the_video_browser_does_not_tell_pages_a_program_drives_it(tmp_path, monkeypatch):
|
||||
"""With DevTools on, Chrome sets navigator.webdriver, and YouTube then stops the video about a
|
||||
minute in with its error screen (seen on the gaming PC and reproduced on Linux)."""
|
||||
from m0lib import video
|
||||
if not video.find_browser():
|
||||
pytest.skip("no Chrome or Edge on this machine")
|
||||
|
||||
class Page(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/html")
|
||||
self.end_headers()
|
||||
self.wfile.write(b"<title>watch</title>")
|
||||
|
||||
def log_message(self, *a):
|
||||
pass
|
||||
|
||||
srv = ThreadingHTTPServer(("127.0.0.1", 0), Page)
|
||||
threading.Thread(target=srv.serve_forever, daemon=True).start()
|
||||
# The page is found by "youtube" in its address; headless keeps the test off the screen.
|
||||
url = f"http://127.0.0.1:{srv.server_port}/youtube"
|
||||
page = None
|
||||
try:
|
||||
page = video.open_video_page(tmp_path, url=url, extra_args=("--headless=new",))
|
||||
assert page.cdp.evaluate("navigator.webdriver") is False
|
||||
page.close()
|
||||
page = None
|
||||
# A browser that still says so (one that ignores the switch) is refused at once and closed,
|
||||
# before Jarvis is started for nothing.
|
||||
class Says(video.Cdp):
|
||||
def evaluate(self, expression):
|
||||
return True if expression == "navigator.webdriver" else super().evaluate(expression)
|
||||
|
||||
monkeypatch.setattr(video, "Cdp", Says)
|
||||
with pytest.raises(RuntimeError, match="webdriver"):
|
||||
video.open_video_page(tmp_path, url=url, extra_args=("--headless=new",))
|
||||
assert not (tmp_path / "cache" / "video" / "browser-profile").exists()
|
||||
finally:
|
||||
if page:
|
||||
page.close()
|
||||
srv.shutdown()
|
||||
|
||||
|
||||
def test_a_page_script_that_fails_while_the_page_loads_reads_as_a_lost_page():
|
||||
from m0lib import video
|
||||
|
||||
|
||||
Reference in New Issue
Block a user