From 800dab32a080a3d3081b422bf16ac41984e15d68 Mon Sep 17 00:00:00 2001 From: Rahul Rao Date: Tue, 14 Jul 2026 09:46:38 +0530 Subject: [PATCH] fix: make persistent_local_browser work on Windows Two Windows incompatibilities fixed: 1. Process detach: use subprocess.CREATE_NEW_PROCESS_GROUP on Windows instead of start_new_session (POSIX-only) 2. Process termination: use taskkill /F /T /PID on Windows instead of os.kill with SIGTERM/SIGKILL (Unix-only) Fixes: https://github.com/microsoft/Webwright/issues/58 --- src/webwright/tools/persistent_local_browser.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/webwright/tools/persistent_local_browser.py b/src/webwright/tools/persistent_local_browser.py index b861d1c..d05c202 100644 --- a/src/webwright/tools/persistent_local_browser.py +++ b/src/webwright/tools/persistent_local_browser.py @@ -140,6 +140,8 @@ def _cmd_create(args: argparse.Namespace) -> int: } if os.name == "posix": popen_kwargs["start_new_session"] = True + else: + popen_kwargs["creationflags"] = subprocess.CREATE_NEW_PROCESS_GROUP proc = subprocess.Popen(chromium_args, **popen_kwargs) # noqa: S603 try: @@ -183,6 +185,16 @@ def _cmd_info(args: argparse.Namespace) -> int: def _terminate_pid(pid: int, kill_timeout: float) -> str: if pid <= 0 or not _pid_alive(pid): return "not_running" + if os.name == "nt": + try: + subprocess.run( + ["taskkill", "/F", "/T", "/PID", str(pid)], + capture_output=True, + timeout=30, + ) + except subprocess.TimeoutExpired: + pass + return "terminated" try: os.kill(pid, signal.SIGTERM) except ProcessLookupError: