feat(browser): replace the preview proxy with a real browser panel and an agent web tool (#2883)

The preview panel worked by proxying a dev server through OpenChamber's own
origin and rewriting the HTML that came back. Anything the rewriter did not
anticipate broke, and pages that refuse to be embedded never loaded at all.
This deletes the proxy (-1604 lines and its tests) and merges the preview and
browser panels into one surface backed by a real Chromium view.

What the panel is now

- A `<webview>` in its own session partition: logins and cookies persist, hot
  reload works because nothing is rewritten, DevTools are one click away.
- Annotation: pick one element, drag a region, or draw freehand, write a note,
  and it reaches chat with a screenshot of the visible page with the marks on it.
- Toolbar: hard reload, page zoom, device sizes, a light/dark switch that
  applies to the page rather than the app, and cookie/cache clearing scoped to
  the panel alone.
- Several pages at once, each tab showing the page's own favicon, and an address
  bar that suggests pages already visited in this project.
- Dev servers are listed from what is actually listening on the machine, checked
  against what a project announced, so a server is offered no matter how it was
  started. One that is still starting is waited for instead of failing.

Remote dev servers

The desktop app binds a local port and pipes raw bytes to the OpenChamber host
over the existing authenticated connection, so the page keeps its own origin at
the root of its own host. The reachable set is exactly what discovery reports
and is re-checked per connection, so an authenticated client cannot dial
arbitrary local services on the host. Links and redirects to another loopback
port stay on the machine that served the page. A tunnel that cannot be opened is
reported; it is never replaced by the plain loopback URL, which would answer
from the user's own machine under a remote address.

Agent control

Browser actions are a separate `openchamber_web` tool: open, snapshot, click,
type, scroll, inspect computed styles, resize between mobile/tablet/desktop, and
capture a screenshot into `.openchamber/screenshots/` in the project. The
existing `openchamber` tool keeps sessions, worktrees and scheduled tasks. Each
has its own setting in the new Settings -> General -> OpenChamber Tools section,
and the plugin is not injected at all when both are off.

Capability belongs to the connected client, not to configuration: a client
declares on its event stream that it can drive a page, which only a Chromium
host does. Exactly one client performs each request — it claims the request
before acting, and the first claim wins — because deciding by whose result
arrives first would be too late for a click that already happened. No client
listening is answered immediately with an explanation rather than a timeout.

Runtime boundaries

Web tabs get a plain iframe that can display a page but not inspect one. The
VS Code extension no longer offers the surface at all, since nothing that makes
the panel worth having works there. Mobile is unaffected.

Native boundary

Camera, microphone, location and device-picker requests from panel pages are
denied — Electron grants them by default when no handler is set, and the panel
loads whatever address the user types. Page capture, appearance emulation and
storage clearing verify that their target belongs to the panel's own session
instead of trusting a web-contents id from the renderer.

Persisted state

Stored `preview` tabs migrate to `browser` (v13 -> v14). Context panel tab
limits are now per surface, so filling one surface no longer evicts another's
tabs. Address history is stored per project and per runtime.

Documentation

`preview.mdx` and `desktop-browser.mdx` rewritten across all locales, the agent
tool settings path corrected, new `DOCUMENTATION.md` for the browser-control
broker and the dev tunnel, and the `ui-api-decoupling` skill updated where it
still described the deleted proxy.
This commit is contained in:
Bohdan Triapitsyn
2026-08-13 22:44:13 +03:00
committed by GitHub
parent 50613bb170
commit a5aa32446d
151 changed files with 10431 additions and 5587 deletions
@@ -11,7 +11,7 @@ edge (`components/layout/ContextPanelRail.tsx`) and rendered by
- A surface maps 1:1 to a `ContextPanelMode` tab mode in `useUIStore`.
- `availability: 'always'` surfaces are always present on the rail.
`availability: 'has-content'` surfaces (preview, chat) are hidden from the
`availability: 'has-content'` surfaces (chat) are hidden from the
rail until a tab of their mode exists, and stay visible for as long as one
does — they must not disappear while in use.
- `defaultWidthFraction` is the panel width as a fraction of the content area,
@@ -50,7 +50,7 @@ the `openContext*` actions in `useUIStore`.
positions). Chat tab records stay open, but only the active chat iframe is
mounted while the panel is open. A selected chat restores its state from
the session stores. A closed panel mounts no chat iframe.
Singleton surfaces (git, pr, notes, plan, context) and preview tabs remount
on switch. These surfaces must restore their state from stores or snapshots.
Singleton surfaces (git, pr, notes, plan, context) remount on switch. These
surfaces must restore their state from stores or snapshots.
- Runtime scope: desktop/web `MainLayout` only. VS Code and the dedicated
mobile shell have their own layouts and do not consume this registry.
+19 -6
View File
@@ -36,14 +36,27 @@ describe('getVisibleContextRailSurfaces', () => {
).toBe(true);
});
test('offers no browser surface inside VS Code', () => {
expect(getVisibleContextRailSurfaces(baseOptions).some((s) => s.id === 'browser')).toBe(true);
// Nothing that makes the panel worth having works there, so offering it
// would promise the panel people see on the desktop.
expect(getVisibleContextRailSurfaces({ ...baseOptions, isVSCode: true }).some((s) => s.id === 'browser')).toBe(false);
});
test('hides content-driven surfaces until a matching tab exists', () => {
const preview = CONTEXT_SURFACES.find((surface) => surface.id === 'preview');
if (!preview) {
throw new Error('preview surface missing from registry');
const chat = CONTEXT_SURFACES.find((surface) => surface.id === 'chat');
if (!chat) {
throw new Error('chat surface missing from registry');
}
expect(preview.availability).toBe('has-content');
expect(getVisibleContextRailSurfaces(baseOptions).some((s) => s.id === 'preview')).toBe(false);
expect(getVisibleContextRailSurfaces({ ...baseOptions, tabs: [{ mode: preview.mode }] }).some((s) => s.id === 'preview')).toBe(true);
expect(chat.availability).toBe('has-content');
expect(getVisibleContextRailSurfaces(baseOptions).some((s) => s.id === 'chat')).toBe(false);
expect(getVisibleContextRailSurfaces({ ...baseOptions, tabs: [{ mode: chat.mode }] }).some((s) => s.id === 'chat')).toBe(true);
});
test('the browser surface can be opened from the rail with no tab yet', () => {
const browser = CONTEXT_SURFACES.find((surface) => surface.id === 'browser');
expect(browser?.availability).toBe('always');
expect(getVisibleContextRailSurfaces(baseOptions).some((s) => s.id === 'browser')).toBe(true);
});
test('respects the persisted user rail order', () => {
+10 -12
View File
@@ -13,7 +13,6 @@ export type ContextSurfaceId =
| 'notes'
| 'context'
| 'browser'
| 'preview'
| 'chat';
export type ContextSurfaceDescriptor = {
@@ -25,8 +24,8 @@ export type ContextSurfaceDescriptor = {
/**
* 'always' surfaces can be opened empty from the rail.
* 'has-content' surfaces are content-driven: they need an existing tab of
* their mode (a preview URL emitted, a split session) and stay hidden on
* the rail until one exists.
* their mode (a split session, a diff to show) and stay hidden on the rail
* until one exists.
*/
availability: 'always' | 'has-content';
/** Short tooltip explanation shown on the rail. */
@@ -129,15 +128,6 @@ export const CONTEXT_SURFACES: readonly ContextSurfaceDescriptor[] = [
labelKey: 'contextPanel.mode.browser',
availability: 'always',
},
{
id: 'preview',
descriptionKey: 'contextRail.surface.preview.description',
defaultWidthFraction: 0.45,
mode: 'preview',
icon: 'window',
labelKey: 'contextPanel.mode.preview',
availability: 'has-content',
},
{
id: 'chat',
descriptionKey: 'contextRail.surface.chat.description',
@@ -218,6 +208,14 @@ export const getVisibleContextRailSurfaces = (options: VisibleRailSurfacesOption
if (surface.id === 'walkthrough' && (options.isVSCode || options.screenWidth < WALKTHROUGH_MIN_WIDTH)) {
return false;
}
// VS Code already is an editor with a browser next to it. What OpenChamber
// could add there is a bare frame: no annotation, no agent control, no
// remote dev servers — all of which need a Chromium host the extension does
// not have. Offering the surface anyway would promise the panel people see
// on the desktop.
if (surface.id === 'browser' && options.isVSCode) {
return false;
}
if (surface.availability === 'has-content') {
return options.tabs.some((tab) => tab.mode === surface.mode);
}