Agent Zero AI framework
Accept host-browser discovery endpoints
Alessandro2e32a2f8dc16
diff --git a/AGENTS.md b/AGENTS.mdindex 704ab7554..d32f21c51 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -27,7 +27,7 @@- Never commit secrets, `.env` files, API keys, tokens, or private user data.- Preserve authentication and CSRF protections.- Use Linux paths and commands in examples.-- Treat the Docker container exposed at `localhost:32080` as the live plugin/backend runtime when that target is named.+- When a live Dockerized Agent Zero target is explicitly named, verify that exact runtime instead of assuming a fixed localhost port.- Copy live core-plugin changes back into tracked source under `plugins/`.- Develop new custom plugins under ignored `usr/plugins/`; tracked bundled plugins live under `plugins/`.- Use the framework runtime for backend and plugin-hook verification, not the separate agent execution runtime.diff --git a/docs/guides/a0-cli-connector.md b/docs/guides/a0-cli-connector.mdindex f0812efc8..a68671941 100644--- a/docs/guides/a0-cli-connector.md+++ b/docs/guides/a0-cli-connector.md@@ -173,11 +173,12 @@ explicit remote debugging port and a separate profile:opera --remote-debugging-port=9222 --user-data-dir="$HOME/.config/a0-opera-debug"```-Then choose **Custom endpoint** in Browser settings, run `/browser ws://...` in-A0 CLI, or pass the full DevTools websocket endpoint to A0 CLI:+Then choose **Custom endpoint** in Browser settings, run+`/browser localhost:9222` in A0 CLI, or pass the discovery address to A0 CLI. A+full DevTools WebSocket endpoint also works:```bash-export A0_HOST_BROWSER_REMOTE_DEBUGGING_ENDPOINTS="ws://127.0.0.1:9222/devtools/browser/..."+export A0_HOST_BROWSER_REMOTE_DEBUGGING_ENDPOINTS="http://localhost:9222"```### Browser Profilesdiff --git a/docs/guides/browser.md b/docs/guides/browser.mdindex 33d1b719f..2b7d18efe 100644--- a/docs/guides/browser.md+++ b/docs/guides/browser.md@@ -169,11 +169,12 @@ directory:opera --remote-debugging-port=9222 --user-data-dir="$HOME/.config/a0-opera-debug"```-Then choose **Custom endpoint** in Browser settings, or pass the full DevTools-websocket endpoint to the CLI:+Then choose **Custom endpoint** in Browser settings and enter `localhost:9222`+or `http://localhost:9222`. A full DevTools WebSocket endpoint also works. The+same forms can be passed to A0 CLI:```bash-export A0_HOST_BROWSER_REMOTE_DEBUGGING_ENDPOINTS="ws://127.0.0.1:9222/devtools/browser/..."+export A0_HOST_BROWSER_REMOTE_DEBUGGING_ENDPOINTS="http://localhost:9222"```diff --git a/plugins/_browser/AGENTS.md b/plugins/_browser/AGENTS.mdindex a0e570a9d..c9c40c57e 100644--- a/plugins/_browser/AGENTS.md+++ b/plugins/_browser/AGENTS.md@@ -24,9 +24,9 @@- Keep Browser viewer frame transport capability-negotiated: updated clients may request binary/slim screencast frames, while older clients must keep the base64/full-metadata fallback. Do not let the WebUI advertise binary frames unless its Socket.IO client reconstructs attachments as real `Blob`, `ArrayBuffer`, or typed-array values.- Keep WebUI Browser tabs scoped to the active chat context by default; aggregate tabs from other AgentContext runtimes only when the Browser settings tab scope is `shared`.- Keep narrow WebUI Browser controls usable by grouping navigation with Annotate/settings above a full-width address bar.-- For Bring Your Own Browser with an existing host profile, `host_browser_selection` may target automatic CLI selection, a browser family/id, or an explicit CDP endpoint and must be forwarded to the connector runtime as `browser_selection`.+- For Bring Your Own Browser with an existing host profile, `host_browser_selection` may target automatic CLI selection, a browser family/id, an HTTP CDP discovery address, or a full DevTools WebSocket endpoint and must be forwarded to the connector runtime as `browser_selection`.- Browser Settings must refresh connected A0 CLI host-browser inventory while the settings view is open so newly authorized endpoints appear without saving or reopening.-- Browser Settings keeps the Host browser dropdown focused on automatic selection, advertised debug endpoints, and a validated Custom endpoint field instead of listing every installed local profile.+- Browser Settings keeps the Host browser dropdown focused on automatic selection, advertised debug endpoints, and a validated Custom endpoint field instead of listing every installed local profile. Preserve endpoint path/query case and let A0 CLI resolve discovery addresses on the host.- Browser URL-intent handling must only claim web URL schemes and leave custom Agent Zero schemes to their owning surfaces.- Prefer DOM/CDP browser actions with refs, selectors, frame-chain refs, and screenshots over viewport coordinate input. Coordinates remain a visual fallback.- Do not hardcode user-specific browser paths or secrets.diff --git a/plugins/_browser/helpers/config.py b/plugins/_browser/helpers/config.pyindex 5279f6215..60d0bfac5 100644--- a/plugins/_browser/helpers/config.py+++ b/plugins/_browser/helpers/config.py@@ -63,8 +63,12 @@ def _normalize_host_browser_selection(value: Any) -> str:raw = str(value or "").strip()if not raw:return ""+ endpoint_like = "://" in raw or (+ raw.rpartition(":")[0] and raw.rpartition(":")[2].isdigit()+ )+ if endpoint_like:+ return "".join(ch for ch in raw if ch.isprintable() and not ch.isspace())[:2048]normalized = raw.lower().replace(" ", "_")- # Keep explicit CLI ids/ports/endpoints usable while avoiding control characters.return "".join(ch for ch in normalized if ch.isalnum() or ch in {"_", "-", ":", ".", "/"})[:200]diff --git a/plugins/_browser/webui/browser-config-store.js b/plugins/_browser/webui/browser-config-store.jsindex 4f32fe0ac..6ae665209 100644--- a/plugins/_browser/webui/browser-config-store.js+++ b/plugins/_browser/webui/browser-config-store.js@@ -70,19 +70,27 @@ function normalizeRuntimeBackend(value) {}function normalizeHostBrowserSelection(value) {- return String(value || "").trim().toLowerCase().replace(/\s+/g, "_").slice(0, 200);+ const raw = String(value || "").trim();+ if (raw.includes("://") || /^(?:\[[^\]]+\]|[^/:\s]+):\d+$/.test(raw)) {+ return raw.replace(/\s+/g, "").slice(0, 2048);+ }+ return raw.toLowerCase().replace(/\s+/g, "_").slice(0, 200);}function normalizeCustomHostBrowserEndpoint(value) {const raw = String(value || "").trim();if (!raw) return "";- const candidate = raw.includes("://") ? raw : `ws://${raw}`;+ const candidate = raw.includes("://") ? raw : `http://${raw}`;try {const url = new URL(candidate);- if (!["ws:", "wss:"].includes(url.protocol) || !url.host || !url.pathname.startsWith("/devtools/browser/")) {- return "";+ if (!url.host) return "";+ if (["http:", "https:"].includes(url.protocol)) {+ if (!["/", "/json/version"].includes(url.pathname)) return "";+ const path = url.pathname === "/" ? "" : url.pathname;+ return normalizeHostBrowserSelection(`${url.protocol}//${url.host}${path}${url.search || ""}`);}- return normalizeHostBrowserSelection(`${url.protocol}//${url.host}${url.pathname}${url.search || ""}`);+ if (!["ws:", "wss:"].includes(url.protocol)) return "";+ return normalizeHostBrowserSelection(`${url.protocol}//${url.host}${url.pathname === "/" ? "" : url.pathname}${url.search || ""}`);} catch (_error) {return "";}@@ -92,20 +100,6 @@ function isCustomHostBrowserEndpoint(value) {return Boolean(normalizeCustomHostBrowserEndpoint(value));}-function debugPortVersionUrl(value) {- const raw = String(value || "").trim();- if (!raw) return "";- const candidate = raw.includes("://") ? raw : `ws://${raw}`;- try {- const url = new URL(candidate);- if (!["ws:", "wss:"].includes(url.protocol) || !url.host) return "";- if (url.pathname && url.pathname !== "/") return "";- return `http://${url.host}/json/version`;- } catch (_error) {- return "";- }-}-function normalizeBoolean(value, fallback = true) {if (value === undefined || value === null || value === "") return fallback;if (typeof value === "boolean") return value;@@ -314,9 +308,8 @@ export const store = createStore("browserConfig", {const safeConfig = ensureConfig(this.config);if (!safeConfig) return;const endpoint = normalizeCustomHostBrowserEndpoint(this.hostBrowserCustomEndpoint);- if (endpoint || !this.hostBrowserCustomEndpoint) {- safeConfig.host_browser_selection = endpoint;- }+ safeConfig.host_browser_selection = endpoint+ || normalizeHostBrowserSelection(this.hostBrowserCustomEndpoint);},customHostBrowserEndpointDiagnostic() {@@ -325,11 +318,7 @@ export const store = createStore("browserConfig", {}const endpoint = normalizeCustomHostBrowserEndpoint(this.hostBrowserCustomEndpoint);if (endpoint) return `Using ${endpoint}`;- const versionUrl = debugPortVersionUrl(this.hostBrowserCustomEndpoint);- if (versionUrl) {- return `This looks like a debug port. Open ${versionUrl} and copy webSocketDebuggerUrl.`;- }- return "Endpoint must be a ws:// or wss:// URL ending in /devtools/browser/...";+ return "Use host:port, an http(s):// discovery address, or a ws(s):// browser endpoint.";},hostBrowserProfileModeLabel() {diff --git a/plugins/_browser/webui/config.html b/plugins/_browser/webui/config.htmlindex 40cba5d37..07a14c472 100644--- a/plugins/_browser/webui/config.html+++ b/plugins/_browser/webui/config.html@@ -106,7 +106,7 @@><span class="material-symbols-outlined">info</span><span>- For an already-open browser, Chrome, Edge, Brave, Vivaldi, and Chromium use chrome://inspect/#remote-debugging; Opera uses opera://inspect/#remote-debugging. Enable "Allow remote debugging for this browser instance", then restart or reconnect A0 CLI if the browser does not appear. If needed, launch the browser with --remote-debugging-port=9222 and --user-data-dir=<profile-dir>, or set A0_HOST_BROWSER_REMOTE_DEBUGGING_ENDPOINTS to the full ws://.../devtools/browser/... endpoint.+ For an already-open browser, Chrome, Edge, Brave, Vivaldi, and Chromium use chrome://inspect/#remote-debugging; Opera uses opera://inspect/#remote-debugging. Enable "Allow remote debugging for this browser instance", then restart or reconnect A0 CLI if the browser does not appear. If needed, launch the browser with --remote-debugging-port=9222 and --user-data-dir=<profile-dir>, then use localhost:9222 or the full ws://.../devtools/browser/... endpoint here or in A0_HOST_BROWSER_REMOTE_DEBUGGING_ENDPOINTS.</span></div>diff --git a/tests/test_browser_agent_regressions.py b/tests/test_browser_agent_regressions.pyindex ce921faa9..79519e0d8 100644--- a/tests/test_browser_agent_regressions.py+++ b/tests/test_browser_agent_regressions.py@@ -197,11 +197,14 @@ def test_browser_config_normalizes_host_browser_selection():== "chrome")assert (- normalize_browser_config({"host_browser_selection": "ws://127.0.0.1:9222/devtools"})[+ normalize_browser_config({"host_browser_selection": "ws://127.0.0.1:9222/devtools/Browser/AbC?token=XyZ"})["host_browser_selection"]- == "ws://127.0.0.1:9222/devtools"+ == "ws://127.0.0.1:9222/devtools/Browser/AbC?token=XyZ")+ assert normalize_browser_config({"host_browser_selection": "localhost:9222"})[+ "host_browser_selection"+ ] == "localhost:9222"assert normalize_browser_config({"host_browser_selection": "bad\x00value"})["host_browser_selection"] == "badvalue"@@ -1029,7 +1032,9 @@ def test_browser_tool_does_not_auto_open_canvas_policy_is_documented():assert "opera://inspect/#remote-debugging" in config_htmlassert "A0_HOST_BROWSER_REMOTE_DEBUGGING_ENDPOINTS" in config_htmlassert "Custom endpoint" in config_html+ assert "localhost:9222" in config_htmlassert "customHostBrowserEndpointDiagnostic" in config_store_js+ assert "http(s):// discovery address" in config_store_jsassert "HOST_BROWSER_STATUS_REFRESH_MS = 1000" in config_store_js