Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/browser_harness/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ def _open_chrome_inspect():
"""Open chrome://inspect/#remote-debugging so the user can tick the checkbox."""
import platform, subprocess, webbrowser
url = "chrome://inspect/#remote-debugging"
if platform.system() == "Darwin":
system = platform.system()
if system == "Darwin":
try:
subprocess.run([
"osascript",
Expand All @@ -730,6 +731,22 @@ def _open_chrome_inspect():
return
except Exception:
pass
if system == "Windows":
for root in (
os.environ.get("PROGRAMFILES"),
os.environ.get("PROGRAMFILES(X86)"),
os.environ.get("LOCALAPPDATA"),
):
if not root:
continue
chrome = Path(root) / "Google" / "Chrome" / "Application" / "chrome.exe"
if not chrome.exists():
continue
try:
subprocess.Popen([str(chrome), url])
return
except Exception:
pass
try:
webbrowser.open(url, new=2)
except Exception:
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,44 @@ def test_chrome_running_detects_helium_on_linux(monkeypatch):
assert admin._chrome_running()


def test_open_chrome_inspect_uses_chrome_executable_on_windows(monkeypatch, tmp_path):
program_files = tmp_path / "Program Files"
chrome = program_files / "Google" / "Chrome" / "Application" / "chrome.exe"
chrome.parent.mkdir(parents=True)
chrome.write_text("chrome")
popen_calls = []
webbrowser_calls = []

monkeypatch.setattr("platform.system", lambda: "Windows")
monkeypatch.setenv("PROGRAMFILES", str(program_files))
monkeypatch.delenv("PROGRAMFILES(X86)", raising=False)
monkeypatch.delenv("LOCALAPPDATA", raising=False)
monkeypatch.setattr("subprocess.Popen", lambda args: popen_calls.append(args))
monkeypatch.setattr("webbrowser.open", lambda *args, **kwargs: webbrowser_calls.append((args, kwargs)))

admin._open_chrome_inspect()

assert popen_calls == [[str(chrome), "chrome://inspect/#remote-debugging"]]
assert webbrowser_calls == []


def test_open_chrome_inspect_falls_back_to_webbrowser_when_windows_chrome_missing(monkeypatch):
popen_calls = []
webbrowser_calls = []

monkeypatch.setattr("platform.system", lambda: "Windows")
monkeypatch.delenv("PROGRAMFILES", raising=False)
monkeypatch.delenv("PROGRAMFILES(X86)", raising=False)
monkeypatch.delenv("LOCALAPPDATA", raising=False)
monkeypatch.setattr("subprocess.Popen", lambda args: popen_calls.append(args))
monkeypatch.setattr("webbrowser.open", lambda *args, **kwargs: webbrowser_calls.append((args, kwargs)))

admin._open_chrome_inspect()

assert popen_calls == []
assert webbrowser_calls == [(("chrome://inspect/#remote-debugging",), {"new": 2})]


@pytest.mark.parametrize(
"path, expected",
[
Expand Down