# Built-in browser

Pages render in Electron `WebContentsView`s on their own `persist:webtabs` profile, sharing no cookies or storage with the App. The Agent works on the same pages through `computer_use` with `type="browser"`: the user watches and can take over, and pages a session opens appear in that session's Resources.

## Toolbar and menus

| Pane width | 720 px and up | 560–719 | 520–559 | Below 520 |
| --- | --- | --- | --- | --- |
| Back, Reload/Stop, star, Browser `⋯` | Shown | Shown | Shown | Shown |
| Address bar | Fills the rest | Fills the rest | Fills the rest | Fills the rest, 160 px at least |
| Forward | Shown | Shown | Shown | In `⋯` |
| Home, Bookmarks, Open externally | Shown | In `⋯` | In `⋯` | In `⋯` |
| Bookmarks bar | Shown | Shown | Hidden | Hidden |

Toolbar 40 px, bookmarks bar 30 px, no wrapping.

| Level | Holds |
| --- | --- |
| Toolbar | Frequent current-page actions. The star only saves or removes this page; Bookmarks opens the manager. The pen left of the star is [Annotate](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/browser/annotate.html). No split controls, no Settings gear. |
| Browser `⋯` | New browser tab, Collapse to floating window, Find, Comment on the page and Screenshot a region (where available), Zoom, Print, Bookmarks, History, Downloads, Show bookmarks bar, Import browser data, Clear browsing data, Browser settings |
| Window menu | New pane or window, pane layout, OpenProgram Settings, Help, About |
| Tab or pane controls | Splitting and arranging, which apply to Files, Chat, Browser and Terminal alike |

Both settings entries open one page and one store; Browser `⋯` deep-links to `/settings/browser`.

**Menu rules**

| Aspect | Behaviour |
| --- | --- |
| Placement | Each menu uses its own trigger's screen rectangle: right edges aligned, 4 px gap |
| Zoom | Renderer CSS px convert to DIP by the sender's zoom, so menus stay beside triggers at 80, 100 and 125% |
| Size | Desktop popovers report intrinsic size from `scrollWidth/scrollHeight`, never shrinking recursively to a clipped height |
| Browser `⋯` icons | Solar Bold Duotone, named by `glyph` and drawn by `MenuIcon` in the overlay; the Web fallback uses the same `MenuRow` |
| Icon slot | Only when a row carries a glyph, folder or favicon. Text in rows without one starts at the row's `10px` padding. |
| Checks | At the row end, after any key tag; unchecked rows keep that column empty |
| Toolbar tips | Always above the control and one line, truncating long labels: the native page below would cover them |
| Popovers near pages | A native page is suspended only when a visible popover intersects it; see [native page bounds](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/browser/web-tab-native-bounds.html) |

## Surfaces

| Surface | Content |
| --- | --- |
| New pane | A Launchpad that only selects content: Files, New chat, Browser, Terminal, then enabled applications. No address bar, quick sites, Bookmarks or History. |
| Browser home | Opens in place with the same address and bookmarks bars as a page. Back, Forward, Reload, Home, star and Open externally stay visible but disabled; address input, Bookmarks, Import and `⋯` work. Shows only user-maintained quick sites and the import entry. |
| History | Grouped by local date. Row: time, favicon, title, domain, actions, 38 px. Up to 5000 records; search runs in main. |
| Bookmarks manager | Title, search and page menu on top; folder tree on the left, current folder's direct children on the right. Row: icon, title, single `⋮`. Folders open. Narrow panes stack the tree above the list. |
| Downloads | To the system Downloads folder. Live progress and final status; open, reveal in Finder, cancel, clear records. |

Manager sizes: header 52 px, rows 36, search 30, icon buttons 28, right list padding 16.

### Bookmarks bar and menus

| Aspect | Behaviour |
| --- | --- |
| Default | Visible on home and pages; off stays off (Browser `⋯` or Settings) |
| Contents | Direct children of Chromium's `Bookmarks bar`, in order, plus ordinary root bookmarks. Then a `»` overflow menu, a divider and All bookmarks, which opens the manager with `Other bookmarks` and `Mobile bookmarks`. |
| Overflow | One row, no scrollbar. Hidden items leave no clipped button; the last visible one keeps its full background and rounded ends. |
| Menus | 280 px, ellipsized titles, nested level by level (Folder icon and arrow), bounded by window height, mouse, trackpad and keyboard |
| Desktop hover | Opens at once; moving to an adjacent folder switches without delay by replacing data in one view. Stays open from trigger into a panel, closes within 120 ms after leaving all of them. The overlay starts at the bar's lower edge, clear of its buttons. |
| Icons | Saved image, then the origin's `/favicon.ico`, then the Bookmark or Lucide browser fallback, never an empty slot. HTTP(S) and image data only, no referrer, no third-party service. New bookmarks keep the page's icon; revisiting an exact URL refreshes it without erasing it during loading. |

## Page behaviour

| Behaviour | Rule |
| --- | --- |
| Loading | Reload becomes an accented Lucide X named Stop loading, over a thin indeterminate bar below the toolbar with no percentage and no height change. Static with reduced motion. Completion, failure and cancellation restore Reload. |
| Unsaved pages | A blocked reload or navigation (`will-prevent-unload`) shows a native dialog on the owning window. Stay on page is the default and cancel; Leave page permits only that operation. Missing owner, destruction or dialog failure keeps the page. A page that is not on screen in the focused window leaves without the dialog, since nobody is there to answer and the dialog would come in front of what the user is doing. Tab close and App shutdown are outside this rule. |
| Tab icons | Favicon when it decodes to visible pixels, else the animated Lucide browser icon. Main reads bytes through the page session: HTTP(S) and image data, 256 KiB, five seconds, returned as data URLs so the renderer can detect fully transparent icons. Navigation and destruction cancel reads; stale results cannot land. Snapshots carry the favicon; history keeps the original URL. |
| Find, Zoom, Print | Target only the requesting window's exact WebTab. Find has previous, next, count and close, which clears selection. `⌘/Ctrl+F`, `⌘/Ctrl++/-/0` and `⌘/Ctrl+P` match the menu. An older shell lacking the IPC disables the action. |
| Print | System printing first; on failure or with no destination, the owning window's Save PDF dialog. Cancelling writes nothing; a successful print makes no PDF. The PDF is written to a unique temporary file, then replaces the target; failure keeps existing files. |

### Navigation, popups and the context menu

| Page intent | Main process | Renderer |
| --- | --- | --- |
| Link, form, script assignment, same-document navigation | `did-navigate` / `did-navigate-in-page` report state; no popup event | `updateWebTab` updates URL, title and favicon in place; id and active tab stay; History records it |
| `target="_blank"`, `window.open` | `setWindowOpenHandler` rejects child windows and sends only valid HTTP(S) URLs and opener ids to the owning window | `openPopupWebTab` creates a unique id and activates it. Already on `/chat` or `/s/<id>`, it does not push `/chat`, so route sync cannot overwrite the activation. A popup from the user's own page while an Agent holds it opens beside the page without activation or a route change. |
| Context menu, Open Link in New Tab | `context-menu` validates exact ownership and URL, then reuses the popup event | Same as a page popup; nothing runs after dismissal or with a stale owner |

| Hit | Native menu |
| --- | --- |
| HTTP(S) link | Open Link in New Tab, Copy Link Address |
| Editable | Undo, Redo, Cut, Copy, Paste, Select All |
| Ordinary page | Back, Forward, Reload |
| Not offered | Save page, Save image, Download linked file, View source, Inspect element, extension entries: these need their own download, file-authorization and developer-mode boundaries |

### Floating preview scope

| Active content | Preview | Native WebTab |
| --- | --- | --- |
| The chat that created it | Visible, at its previous position and size | PiP bounds and layout zoom; same `WebContentsView`, URL, scroll and form state, no reload |
| Another chat or non-chat page | Hidden, no restore entry | Out of the `syncVisible` set; user zoom restored |
| Regular Browser tab, or the same page in split | Hidden | The pane alone owns its bounds; PiP zoom does not persist |
| User closed it in its chat | Hidden; that chat alone shows a restore entry | Kept in the background, not exposed to other sessions |

## Import

From Chrome, Brave, Edge or Chromium, with source, profile and data types confirmed separately. Desktop only.

1. **Source profile** read only, real paths under found roots
2. **Temporary copy** directory 0700, files 0600, always deleted
3. **Bounded parsers** History SQLite and Bookmarks JSON, merged into the History store and bookmark tree
4. **Temporary source browser** decrypts Cookies over CDP, one write each into `persist:webtabs`

| Type | Read | Merge |
| --- | --- | --- |
| History | A copy of the SQLite file; http and https only; at most 5000 | Deduplicated by URL and `visitedAt`; errors keep existing records |
| Bookmarks | Roots, up to 64 folder levels, sibling order; invalid URLs dropped | No duplicate URLs or empty folders on repeat imports; hierarchy preserved |
| Cookies | Decrypted in the temporary browser; the Cookie database is never copied in | Each item validated, then `cookies.set`. Values never reach IPC, logs, History or the renderer. |

Cookie import can reduce repeated logins; device binding, expiry, secondary verification or server revocation can still require one.

### Trust boundaries

| Boundary | Constraint | Failure |
| --- | --- | --- |
| Renderer to main | Opaque source and profile ids issued by main; allowlisted data types; no file or executable paths, no Cookie values | Request rejected |
| Web content to main | Only resolved HTTP(S) URLs; actions bind to the exact WebTab owner. `file:`, `javascript:`, transferred or closed records and forged openers create nothing. | Deny, no-op |
| Source profile | Read-only discovery; symlink escapes rejected | `source_invalid` |
| Temporary data | Deleted after success, failure or timeout. Logs hold only source labels, types, counts and error codes. | Cleanup, stable error |
| Target profile | History and Bookmarks merge; the target database is never replaced | Pre-import data kept |
| Concurrency | One import across the App. Only the initiating renderer can cancel, by its bounded request id. Cancellation is checked at parser phases, during browser startup and CDP waits, and around each Cookie write. | `import_busy`, `import_cancelled` |
| After cancelling | History and Bookmarks do not merge; the browser stops and temporary files go. Cookies written earlier remain, since the Cookie API has no transaction; none follow. | Cooperative stop |

While running, Import becomes Cancel and closing is disabled. Closing before starting changes nothing. Corrupt sources, missing browsers, timeouts and partial Cookie failures return stable codes and keep original data.

**Not imported or provided**

- Passwords, payment details, addresses, extensions, downloads, caches, localStorage, Service Workers
- Password manager, system Credential Store, autofill, remote debugging of the running source browser
- Extensions: Chrome Web Store and Edge Add-ons open as ordinary pages only; see [Browser extension support](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/browser/browser-extensions.html)
- Web-only mode: import is not offered

## Agents on these pages

| Topic | Rule |
| --- | --- |
| Session pages | Grouped by session and collapsed in the session resources panel ([Session resources](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/resources/session-resources.html)). Records keep session ownership and pin state; manual pages and explicit splits stay top-level. |
| Pausing | Clicks, scrolling, keys, navigation and closing a page never pause an Agent, from a user or automation, including automation of OpenProgram. Only conversation controls pause or cancel. Browser resources keep no separate write prohibition; dispatch guards, ownership checks and current-frame validation stay. |
| Lost target | The session is discarded and the tool returns recovery information with the last URL. Recovery observes a new page at that exact URL, never replays a mutation or picks another tab. Missing authentication or unsaved state is reported. |
| Shutdown | Screenshots keep their ToolReturn images and structured errors. A live server never submits to a closed default executor; recovery respects cancellation and unresolved external effects. |

**Browser step execution and caller context**

- The workflow owns the observe, action and verify loop. Each planner request sets `stop_after_tool_round`: the shared Agent loop runs one validated, permission-checked tool round, keeps its receipts and returns without another model response. Default Agent calls continue to final output.
- Independent of the safety limit `max_iterations`. Exhausting a limit is non-retryable, so completed actions cannot replay. A structured final-output contract cannot be combined with this early return.
- Every `BrowserPageController` submission to its Playwright owner thread, including cleanup and final verification, carries the current ContextVars, copied per submission. Page isolation, binding validation, permissions and operation leases stay authoritative.
- A legacy browser task uses an explicitly bound current Page without reloading for a URL hint. A stale explicit binding fails rather than opening a replacement. With no explicit Page, URL and open behaviour are unchanged.

**File selection and planner failures**

- The planner uploads with an approved local path and a fresh file-input ref, under sandbox reads, approval, Page ownership, cancellation and step limits. MCP-backed planners use the same controller.
- File inputs expose type and selected names, never bytes or local paths. Selecting is separate from server acceptance: `file_selected` checks the exact current input and final evidence is rechecked.
- Verification uses `value`, not typing text. Invalid calls return an actionable error; three consecutive failures on an unchanged frame stop with the concrete error. A planner can stop with a blocker, which never grants success. Operation counts are Page mutations, not model requests.

## Icon and menu lifetime

| Part | Behaviour |
| --- | --- |
| Bookmark menus | One detached cascade view per desktop window between openings; reopening attaches it and updates data without a new document. Window cleanup destroys visible and detached views; detached senders cannot dispatch actions. |
| Favicon cache | Renderer-owned, deduplicates loads. Decoded 32 px surfaces for 30 minutes, failures for 5, at most 256 sources, 5-second load, no persistent icon database. |
| Draw | Components draw cached surfaces without another request; a changed source selects another entry. Cross-origin images stay drawable without reading pixels. Repeated native events for the current source do not reload; navigation invalidates ownership. |
| Owners | `bookmark-bar.tsx` layout and menus, `browser-controls.tsx` commands, `favicon-cache.ts` loading and reuse, `tab-favicon.tsx` presentation |

## How web tabs present themselves

As a current Chromium browser, consistently across headers and script. Nothing claims to be another browser.

| Part | Behaviour |
| --- | --- |
| User-Agent | `webtab-user-agent.js` drops only the App's token and keeps `Electron/x` with the full Chrome version: claiming plain Chrome while `navigator.userAgentData` lacks Google Chrome reads as forged and sticks in Cloudflare's challenge |
| Clearance cookies | `cf_clearance`, `__cf_bm` and `cf_chl_*` hold only for the User-Agent that earned them. When it differs from `webtab-user-agent.json`, the App removes them before any tab loads; other cookies stay. |
| Client Hints | Electron sends no `Sec-CH-UA`. `webtab-client-hints.js` reads `getHighEntropyValues()` once from a loopback page, then sends `Sec-CH-UA`, `-Mobile` and `-Platform` to secure origins and the high-entropy hints an origin names in `Accept-CH` |
| Permissions | `webtab-permissions.js` allows what Chrome allows silently (fullscreen, pointer lock, clipboard writes, external protocols), asks in a native dialog on the tab's window for camera, microphone, location, notifications and similar, denies the rest. Answers are kept per origin in `webtab-permissions.json`; clearing web tab cookies forgets them. An undecided permission reads `denied`, since Electron's check handler is yes or no. |
| Permission asked by an unwatched page | A request from a page that is not on screen in the focused window is refused that once and not kept, so the user is asked when they open the page. |
| Engine | The Electron in `apps/desktop/package.json` tracks Chrome stable (Electron 45 is Chromium 156); installed Apps take it as in [Stable and development instances](https://fzkuji.github.io/OpenProgram/docs/reference/design/distribution/dev-instance.html) |
| Not patched | `window.chrome` is empty and there is no Widevine. Pages needing full Chrome are a separate design: the Agent working in the user's own Chrome. |

## Homepage shortcut editor

| Aspect | Behaviour |
| --- | --- |
| Shape | The Add tile toggles a compact, non-modal popover from shared Popover, Input and Button, in the interface font and theme. Two labelled stacked fields; the name is optional. |
| Dismiss | Cancel, Close, Escape, outside interaction or Add clears the draft. Keyboard dismissal returns focus to Add. Hides when its anchor is detached or hidden. Each homepage owns its editor; no global listener or App state. |
| Submit | Enter from either field, except during input-method composition. Empty addresses cannot submit. Saving keeps the existing normalization, persistence and duplicate handling, then clears and closes. |

**Reference behaviour**

| Source | Behaviour | Here |
| --- | --- | --- |
| Codex pane entries | Files, New chat, Browser and Terminal are top-level; browser controls only inside Browser | Adopted |
| [OpenAI built-in browser](https://help.openai.com/en/articles/20001277-using-the-built-in-browser-in-the-chatgpt-desktop-app) | Independent state, Cookies and history cleared in App Settings | Adopted, plus a Browser `⋯` deep link and explicit import |
| [Chrome bookmarks](https://support.google.com/chrome/answer/188842) | Star, toggled bar, separate manager; navigation versus popups | Adopted, with stricter split-pane collapse and popups as WebTabs |
| [Chrome import](https://support.google.com/chrome/answer/96816) | Data-type selection and Imported Bookmarks merging | Informs the dialog |
| [Electron Menu](https://www.electronjs.org/docs/latest/api/menu), [webContents](https://www.electronjs.org/docs/latest/api/web-contents), [window.open](https://www.electronjs.org/docs/latest/api/window-open) | Link, selection, edit and frame hits; native popups; resolved popup URLs | A limited action set; no DevTools or arbitrary protocols |
| [Electron session](https://www.electronjs.org/docs/latest/api/session), [Cookies](https://www.electronjs.org/docs/latest/api/cookies), [WebContentsView](https://www.electronjs.org/docs/latest/api/web-contents-view) | Persistent partitions, per-cookie writes | Used |
| [Chromium user data](https://chromium.googlesource.com/chromium/src/+/main/docs/user_data_dir.md), [user_data_importer](https://chromium.googlesource.com/chromium/src/+/refs/tags/145.0.7573.1/components/user_data_importer/) | Profile file locations; the C++ importer is not exposed to Electron and has no general Cookies import | Not duplicated |
| [Canvas drawImage](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage) | Drawing without reading pixels | Used by the favicon cache |

**Code and verification**

| Area | Code and checks |
| --- | --- |
| Surfaces | `new-tab-page.tsx`, `browser-home-page.tsx`, `builtin-tab-pane.tsx`, `web-history.css`; `apps/web/tests/browser/` |
| Toolbar, menus | `web-tab-pane.tsx`, `browser-controls.tsx`, `main-menu.tsx`, `menu-overlay/context-menu/page.tsx`; `check-web-split.mjs`, `check-center-tabs.mjs`, `check-webtab-zoom-bounds.js` |
| Navigation, Find, Print, downloads | `apps/desktop/main.js`, `desktop-bridge.ts`; `check-webtab-navigation.js` (ownership, system-print and save cancellation, write failure, ownership lost during rendering) |
| Preview scope | `web-tab-pip-store.ts`, `web-tab-pip.tsx`; `check-web-split.mjs` (owner chat, inventory, switching without pointer-up), `check-webtab-navigation.js` (first commit, zoom after transfer) |
| Import | `browser-profile-import.js`, `browsing-history-store.js` self-checks; `apps/web/lib/tabs/browser/bookmarks.ts`, `bookmarks-store.test.mjs`; `check-no-browser-extensions.js` |
| Icons | `favicon-cache.test.mjs` (coalescing, expiry, timeout, eviction); `check-bookmark-menu-cache.cjs` (reuse, hidden senders, disposal); `test_tab_favicons.py`, `bookmark-favicons.test.mjs` (rendering, remounts, reopening with `Cache-Control: no-store` issues no second request) |
| Agent tasks | Real Runtime with a fake provider: one action then verification, no replay, same conversation identity on close, stale bindings rejected. Owned headless Chromium file-input fixture: corrective retries, denial, stale refs, sandbox reads, cancellation with zero transmission. |
| Installed App | Visible checks use `/Applications/OpenProgram.app`, port 18100 and `~/.openprogram`. Covered: popup stays active and route unchanged; 3 Chrome profiles found; import cancellation releases the lease; 1000 of 5000 history rows at 38 px; download, cancel, open and reveal; Find, Zoom, and the Save PDF fallback. |

## Implementation status

| Status | Items |
| --- | --- |
| Implemented | Everything above |
| Not yet | Installed-App acceptance of the homepage shortcut editor (headless checks cover it); default-App visual check of bookmark icons, overflow and manager access |
| Limits | Full-screen terminal programs that depend on a PTY |

[Native page bounds](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/browser/web-tab-native-bounds.html)
