# User browsers

`type="browser"` with `app` drives a browser the user already runs, with their tabs and sign-ins. Every browser takes the same actions and returns the same snapshot; three engines sit behind them.

| Engine | `app` | Transport | Module |
| --- | --- | --- | --- |
| Chromium | `chrome`, `chrome-beta`, `chrome-dev`, `chrome-canary`, `edge`, `edge-beta`, `edge-dev`, `edge-canary`, `brave`, `vivaldi`, `opera`, `arc`, `chromium` | Playwright MCP in extension mode, relaying CDP through the Playwright Extension | `extension.py` |
| Safari | `safari` (macOS) | `osascript`: JXA for tabs and `doJavaScript`, AppleScript for new tabs | `safari.py` over `script_page.py` |
| Firefox | `firefox` | WebDriver BiDi over the remote agent's WebSocket | `firefox.py` over `script_page.py` |

All modules are in `openprogram/programs/applications/browser/`. `catalog.py` holds one row per browser (name, label, engine, Playwright channel, data directory, executables, bundle ids, process names); the registry, the tool's description and its argument check, the provider and the web labels (`apps/web/lib/computer-use/browsers.ts`) all read that order.

## Decisions

| Decision | Reason |
| --- | --- |
| Every Chromium browser goes through the Playwright Extension | The extension is a Chrome Web Store extension, and Brave, Vivaldi, Opera, Arc and Chromium install from that store. One transport keeps one action mapping and one set of refs. |
| A browser without a Playwright channel is named by its executable, with `PWTEST_EXTENSION_USER_DATA_DIR` | Playwright MCP 0.0.79 knows only the Chrome and Edge channels. Given `--executable-path`, it finds the profile with the extension only through that variable, from which it adds `--user-data-dir` and `--profile-directory`; without it the connect page opens in a profile without the extension. |
| Safari through AppleScript, not WebKit or `safaridriver` | Playwright's WebKit is not the user's Safari and has none of their sign-ins. `safaridriver` drives a separate automation window that locks out the user and keeps no state. Apple Events reach the user's own tabs; `do JavaScript` runs the page layer in them. |
| Safari's async results are polled inside one `osascript` run | `doJavaScript` returns only a synchronous value. A kick script starts the work and stores its result on the page under a token; the same JXA run then reads it every 50 ms, so a step costs one process, not one per poll. |
| Safari tab keys are kept by a heuristic | Safari tabs have no ids. A tab keeps its key while its window and index, or its URL and title, still match the last listing; a tab that matches neither gets a new key, so a stale key is refused instead of landing on another page. |
| Safari maps its errors to the fix | -1743 is a missing Automation permission; "Allow JavaScript from Apple Events" in the error means the Develop setting is off; both answer `PERMISSION_MISSING` naming the switch. -600 and -1728 mean Safari or the tab is gone, and the call says which. |
| Safari screenshots are window captures | Safari has no page capture over Apple Events. The desktop driver's `capture_window` (ScreenCaptureKit) captures the window without raising it, cropped to the viewport; a tab that is not the one showing in its window is refused, since its pixels do not exist. `create_tab` opens a new window in the background so the new page can be captured without changing what the user sees. |
| Firefox through WebDriver BiDi | Firefox has no extension mode for Playwright and its CDP support was removed. The remote agent built into Firefox speaks BiDi to the user's own profile, with every command the actions need: tree, navigate, evaluate, input, files, screenshots, console and network events. |
| Port 9222, started in the background | 9222 is Firefox's default for `--remote-debugging-port`. When Firefox is closed the first call starts it with the agent (`open -g` on macOS, so nothing comes to the front). A Firefox running without the agent cannot be attached to, so the call answers `PERMISSION_MISSING` asking the user to restart it. |
| One BiDi session per process | Firefox allows one BiDi session. Conversations share the connection and each keeps its own selected context; the last conversation to end closes the session and leaves Firefox running. |
| A shared page layer for Safari and Firefox | Neither transport has Playwright's snapshot. `script_page.py` injects one script that writes the same outline Playwright writes (role, name, `[ref=eN]`) and acts on those refs, reusing the built-in browser's pointer, hover, scroll, insert and field scripts, so a guide and a model see one format everywhere. |
| Refs live in a `WeakMap` on the page | Refs must survive between calls without marking the DOM. `window.__openprogram` maps refs to `WeakRef`s and elements to refs, so a node the page removes is freed and its ref answers `ELEMENT_GONE`; a navigation starts fresh. |
| Real input only on the tab in front | BiDi input goes to the page as trusted events but needs the tab to be visible; Safari has no input over Apple Events. A tab in the background gets synthetic events from the page layer (typing, Enter submitting its form, Tab moving focus, Backspace and Delete), so choosing a tab never switches what the user sees. |
| App names match without regard to case, and browser short names are aliases | A model writes `chrome` or `Safari` as often as the bundle name. `type="window"` matching was already case-insensitive on every platform; macOS also maps the short names (`chrome` to Google Chrome, `edge` to Microsoft Edge, …) after an exact match fails. |

## What each engine lacks

| Engine | Not available |
| --- | --- |
| Chromium | filtering console messages and requests |
| Safari | `upload_file`, console and network reads, a screenshot of a tab that is not showing |
| Firefox | trusted input on a tab in the background |

## Implementation status

| State | Scope |
| --- | --- |
| Implemented | The catalog, every Chromium browser and channel, Safari, Firefox, the page layer, the window aliases, the guides, the settings help and the web labels. Unit tests cover them against fakes: a fake page, a fake `osascript` and a fake BiDi agent. |
| Not run live | Any of these browsers; the Safari JXA scripts were only compiled with `osacompile`. |
| Not implemented | Firefox Developer Edition and Nightly, Safari Technology Preview. Arc on Windows is found by a glob of its package directory and is untested. |
