From 305a702e09db54ee850038ea5037cce4ed510e3a Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 15 Apr 2026 14:11:18 -0700 Subject: [PATCH] fix: /browser connect CDP override now takes priority over Camofox (#10523) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a user runs /browser connect to attach browser tools to their real Chrome instance via CDP, the BROWSER_CDP_URL env var is set. However, every browser tool function checks _is_camofox_mode() first, which short-circuits to the Camofox backend before _get_session_info() ever checks for the CDP override. Fix: is_camofox_mode() now returns False when BROWSER_CDP_URL is set, so the explicit CDP connection takes priority. This is the correct behavior — /browser connect is an intentional user override. Reported by SkyLinx on Discord. --- tests/tools/test_browser_camofox.py | 12 ++++++++++++ tools/browser_camofox.py | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/tools/test_browser_camofox.py b/tests/tools/test_browser_camofox.py index af36f780..81d69967 100644 --- a/tests/tools/test_browser_camofox.py +++ b/tests/tools/test_browser_camofox.py @@ -37,6 +37,18 @@ class TestCamofoxMode: monkeypatch.setenv("CAMOFOX_URL", "http://localhost:9377") assert is_camofox_mode() is True + def test_cdp_override_takes_priority(self, monkeypatch): + """When BROWSER_CDP_URL is set (via /browser connect), CDP takes priority over Camofox.""" + monkeypatch.setenv("CAMOFOX_URL", "http://localhost:9377") + monkeypatch.setenv("BROWSER_CDP_URL", "http://127.0.0.1:9222") + assert is_camofox_mode() is False + + def test_cdp_override_blank_does_not_disable_camofox(self, monkeypatch): + """Empty/whitespace BROWSER_CDP_URL should not suppress Camofox.""" + monkeypatch.setenv("CAMOFOX_URL", "http://localhost:9377") + monkeypatch.setenv("BROWSER_CDP_URL", " ") + assert is_camofox_mode() is True + def test_health_check_unreachable(self, monkeypatch): monkeypatch.setenv("CAMOFOX_URL", "http://localhost:19999") assert check_camofox_available() is False diff --git a/tools/browser_camofox.py b/tools/browser_camofox.py index fbd1c962..88f486f1 100644 --- a/tools/browser_camofox.py +++ b/tools/browser_camofox.py @@ -54,7 +54,15 @@ def get_camofox_url() -> str: def is_camofox_mode() -> bool: - """True when Camofox backend is configured.""" + """True when Camofox backend is configured and no CDP override is active. + + When the user has explicitly connected to a live Chrome instance via + ``/browser connect`` (which sets ``BROWSER_CDP_URL``), the CDP connection + takes priority over Camofox so the browser tools operate on the real + browser instead of being silently routed to the Camofox backend. + """ + if os.getenv("BROWSER_CDP_URL", "").strip(): + return False return bool(get_camofox_url())