diff --git a/tests/tools/test_browser_real_profile.py b/tests/tools/test_browser_real_profile.py index 2fb47b9f12..2aa870c676 100644 --- a/tests/tools/test_browser_real_profile.py +++ b/tests/tools/test_browser_real_profile.py @@ -355,15 +355,16 @@ class TestRealProfileCdpLaunch: assert cdp == "http://127.0.0.1:41000" self._reset() + @pytest.mark.parametrize("encoding", ["utf-8", "utf-8-sig"]) @pytest.mark.parametrize("live_browser_id", ["/devtools/browser/x", "/devtools/browser/other"]) - def test_reattaches_to_surviving_chrome_instead_of_overlaying_its_profile(self, tmp_path, live_browser_id): + def test_reattaches_to_surviving_chrome_instead_of_overlaying_its_profile(self, tmp_path, live_browser_id, encoding): """The attach daemon of a crashed owner gets reaped, but its Chrome (Hermes-launched, own session) survives holding the copy dir: re-attach, never re-run the snapshot. A DevToolsActivePort left by a crash whose port was recycled by ANOTHER CDP server (browser id mismatch) must not be attached to; the normal launch path runs.""" import tools.browser_tool as bt self._reset() - (tmp_path / "DevToolsActivePort").write_text("41000\n/devtools/browser/x\n") + (tmp_path / "DevToolsActivePort").write_text("41000\n/devtools/browser/x\n", encoding=encoding) version = Mock() version.json.return_value = {"webSocketDebuggerUrl": f"ws://127.0.0.1:41000{live_browser_id}"} with patch.object(bt_cloud, "_use_real_profile", return_value=True), \ diff --git a/tools/browser_tool_real_profile.py b/tools/browser_tool_real_profile.py index 51155c444a..45815fa22f 100644 --- a/tools/browser_tool_real_profile.py +++ b/tools/browser_tool_real_profile.py @@ -85,7 +85,7 @@ def _surviving_chrome_cdp(data_dir: str) -> Optional[str]: outlives a crashed Chrome and its port can be recycled by another local CDP server, so the file's browser id (line 2) must match what ``/json/version`` reports before it is trusted.""" try: - with open(os.path.join(data_dir, "DevToolsActivePort"), encoding="utf-8") as fh: + with open(os.path.join(data_dir, "DevToolsActivePort"), encoding="utf-8-sig") as fh: port, browser_path = fh.readline().strip(), fh.readline().strip() except OSError: return None