Skip to content

Add optional Chrome DevTools Protocol (CDP) support per display - #11

Merged
MindFreeze merged 2 commits into
MindFreeze:mainfrom
Darktex:add-cdp-support
May 26, 2026
Merged

Add optional Chrome DevTools Protocol (CDP) support per display#11
MindFreeze merged 2 commits into
MindFreeze:mainfrom
Darktex:add-cdp-support

Conversation

@Darktex

@Darktex Darktex commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an optional cdp_port field per display that exposes Chromium's Chrome DevTools Protocol so external tools (Playwright, Puppeteer, browser automation agents, AI agents) can drive the same browser session that a human is observing over VNC. Off by default.

The motivating use case: agentic browser automation on Home Assistant OS. The agent needs CDP; the human needs VNC to watch and occasionally take over (captchas, teaching). This addon already nails the VNC + persistent-profile side beautifully — CDP is the natural complement.

Why this isn't just --remote-debugging-port=9222 in browser_args

Since Chromium M113, --remote-debugging-address=0.0.0.0 is silently downgraded to 127.0.0.1 as a security hardening measure (upstream WontFix: crbug.com/40261787). The flag passes through but the binding is loopback-only, so nothing outside the container can reach CDP — even when you publish 9222 in config.yaml, the host-side port forward points at a closed socket.

This PR works around it the same way every Chromium-in-container project does (Browserless, Playwright Docker, etc.): bind Chromium to a loopback-only internal port, then forward 0.0.0.0:cdp_port → 127.0.0.1:internal via socat. --remote-allow-origins=* is also injected — without it, modern Chromium rejects WebSocket upgrades from non-localhost callers with a 403, which silently breaks Playwright/Puppeteer (HTTP /json/version works, WS doesn't).

Changes

  • Dockerfile: install socat; expose 9221-9224.
  • config.yaml: add 9221-9224 to ports: (defaulted to null so they're reachable from sibling addons but not published to the host unless explicitly configured); add cdp_port: int(9221,9224)? to the per-display schema; bump version to 0.13.0.
  • run_vnc.sh: when cdp_port is set on a display, strip any conflicting --remote-debugging-* flags from user-supplied browser_args, inject --remote-debugging-port=<internal> (= cdp_port + 100) and --remote-allow-origins=*, and launch a socat forwarder.
  • README: document cdp_port and explain the M113+ workaround.

Backwards compatibility

Fully backwards compatible. Existing configs without cdp_port behave identically — no socat is launched, no flags injected. Users who previously put --remote-debugging-port=9222 into browser_args (which didn't actually work because of M113+) will see those flags silently stripped if they also set cdp_port, which is the safer behavior.

Test plan

  • Build passes CI (docker build)
  • Existing displays without cdp_port still work (no socat, no extra flags)
  • With cdp_port: 9222, curl http://<addon-host>:9222/json/version returns Chromium build info
  • Playwright connect_over_cdp("ws://<addon-host>:9222") connects successfully (verifies --remote-allow-origins)
  • Multiple displays each get their own CDP port without collisions

🤖 Generated with Claude Code

Setting cdp_port on a display now exposes Chromium's DevTools Protocol so
external tools (Playwright, Puppeteer, browser automation agents) can drive
the same browser session a human is observing over VNC.

Chromium M113+ silently ignores --remote-debugging-address=0.0.0.0 and
binds 127.0.0.1 regardless (upstream WontFix: crbug.com/40261787), so the
addon now binds Chromium to a loopback-only internal port and forwards via
socat. --remote-allow-origins=* is also injected automatically; without it
modern Chromium rejects WebSocket upgrades from non-localhost callers.

Off by default — only takes effect when cdp_port is set on a display.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Darktex pushed a commit to Darktex/ha-cups-epson that referenced this pull request May 25, 2026
Patched fork of MindFreeze/ha-vnc-web-browser that adds an optional
cdp_port field per display, exposing Chromium's DevTools Protocol via a
socat forwarder. Needed because Chromium M113+ silently downgrades
--remote-debugging-address=0.0.0.0 to 127.0.0.1 (upstream WontFix:
crbug.com/40261787).

Upstream PR: MindFreeze/ha-vnc-web-browser#11

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Comment thread README.md

@MindFreeze MindFreeze left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Darktex

@MindFreeze
MindFreeze merged commit be17ef2 into MindFreeze:main May 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants