Skip to content

Studio: in-app browser panel for chat - #12347

Merged
danielhanchen merged 96 commits into
mainfrom
studio-browser-panel
Oct 5, 2026
Merged

danielhanchen merged 96 commits into
mainfrom
studio-browser-panel

Conversation

@shimmyshimmer

@shimmyshimmer shimmyshimmer commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds a browser panel to the right of chat. Attached documents open in it as tabs, and it works as a regular browser too: type a URL or a search, follow links, go back and forward, and open new tabs.

Depends on #12346 for PDFs to render once a PDF has been extracted in the same session.

What it does

  • Files open as tabs. Clicking a PDF, Office doc, HTML, Markdown, code or text attachment opens it in the panel instead of the preview dialog. HTML files use the same frame as the attachment preview, so network access stays off until allowed. Images, audio and video keep the lightbox. Each new file gets its own tab.
  • Browsing. Address bar with search (DuckDuckGo by default), back / forward / reload, a new tab page with a few shortcuts, and target="_blank" or window.open from a click opening a new tab. PDFs and other non-HTML links open in the file viewer.
  • Layout. The panel fills the full height to the right of chat, split 50/50 and resizable. The chat header, fade and model notice stop at the panel edge.
  • Lifecycle. The panel closes when you switch or leave the chat. It stays open when the first message of a new chat creates the thread. Canvas and the panel replace each other, and starting research closes it.
  • Links. Chat links still open in the system browser by default. Provider sign-in URLs always do, since the panel keeps no cookies.
  • File toolbar. An opened file shows a file menu (full name, Open in a new chat or a new browser tab), Request edits (stages "Edit name: " in the composer), a zoom menu and download.
  • Page menu. Find in page (Cmd/Ctrl+F, Enter and Shift+Enter step through matches), copy link, zoom, a device toolbar (phone and tablet widths), Downloads, History, Clear browsing data and Browser settings.
  • History and Downloads. Internal pages grouped by day, with search and per-row removal. Both are stored locally, capped at 1000 visits and 200 downloads. POST results are not recorded.
  • Browser button. Uses the internet icon, is hidden in a new chat and while the panel is open (the panel has its own close button).
  • File icons. Code, text and plain file icons use the foreground color, like the web icon. Only docs stay blue, matching the Library.

Performance

  • Loaded pages are cached per history entry, so back and forward do not refetch. Reload still does. The cache is capped at 32 MB (8 MB per page) and a closed tab's pages are dropped.
  • Only the 4 most recently viewed tabs stay mounted; others reload from the cache when shown.
  • The panel and tabs are memoized, no-op tab updates are skipped, and the title observer only watches <head>.
  • The side panel width is set on the header, fade and notice rather than the chat root, so resizing does not restyle the thread.
  • Tab history is capped at 50 entries.

Settings

New Browser section in Settings, below Shortcuts. The panel's Browser settings item, settings search, the command palette and the desktop Settings menu all open it.

  • Links and files: Open links in (Default browser or Unsloth browser, default browser by default), and open attached files in the browser panel (on by default)
  • Address bar: search engine (DuckDuckGo, Google, Bing or Brave Search), and show full URL (off by default: the address bar shows the site and path)
  • Browsing data: manage browsing history, manage download history, clear browsing data (history, downloads and cached pages; pages keep no cookies or site data)

How pages load

  • POST /api/browser/fetch fetches through the existing _fetch_url_raw, so the SSRF guard applies (private and loopback addresses are refused). HTML comes back as JSON with its final URL and base. Anything else is returned as is, with the final URL in a header.
  • GET /api/browser/frame is a static shell served with sandbox allow-scripts allow-forms (no allow-same-origin), form-action 'none' and treat-as-public-address. Pages run in an opaque origin and cannot reach Studio's cookies, storage or API. Fetch directives allow only https: (and wss: for sockets) with upgrade-insecure-requests, so pages cannot reach local http services through requests or subresources (WebKit has no local network protection).
  • The shell loads the page into a srcdoc child with a <base> and a small script that turns link clicks, form submits, window.open and history pushes into messages, relayed to the panel, which fetches the next page through the proxy. The panel only accepts messages from its own frame and validates every field.
  • After creating the child, the shell sets frame-src 'none' on itself. The child keeps its own policy, so embeds still load, but the page can no longer navigate its own frame, including to loopback ports the desktop app's CSP allows. This does not rely on the Navigation API.
  • Messages that open a tab, open an external link or run a shortcut are only honored when the frame has focus and the user just clicked or typed, at most one per second. A page cannot open tabs or apps on its own. Page favicons load through the guarded fetch and show as blob URLs, so a page cannot point Studio at a local address.
  • Fetches run in their own thread pool, with page rewriting off the event loop, and stop when the panel aborts the load. Browsing does not hold up chat streaming.
  • <meta> CSP and base tags are stripped. Short meta refreshes are followed through the proxy, long ones dropped.
  • _fetch_url_raw gained post_data (for form POSTs, kept only on 307/308) and meta_out (final URL and charset).
  • The shell path is exempt from the X-Frame-Options middleware, and the two browser headers are exposed through CORS.
  • External link opens are limited to http, https and mailto.
  • Find and zoom are sent by the panel through the shell to the page, which only accepts commands from its parent. The page reports whether find matched.

Testing

  • npm run typecheck is clean and npm test passes, apart from the existing More menu test that also fails on main.
  • pytest passes, including the new tests/test_browser_routes.py (shell CSP and isolation, page preparation, charset decoding, raw passthrough, form POST, refused fetches as 502, the dedicated fetch pool and cancel on disconnect).
  • Manual checks in a local build:
    • search, link and form navigation, back and forward, new tabs
    • PDFs from the web and from attachments
    • link and settings defaults, closing on chat switch
    • requests to loopback and private addresses are refused
  • Scripted browser checks in Chrome: scripted popups and shortcuts are dropped, a real click on a target="_blank" link opens a tab, Cmd/Ctrl+L from a page focuses the address bar, pages cannot reach loopback, back and forward come from the cache, reload refetches, old tabs unload, PDFs and search load, find in page selects and reports misses, zoom applies to the page, the device toolbar narrows it, history records visits, the file menu and Request edits work, downloads are recorded, and a new chat shows no browser button. Focus and activation gating also checked in WebKit.

Review fixes

  • Tag stripping on fetched pages (<base>, <meta>, <head>) was quadratic on unclosed tags. One hostile page held the GIL: /api/health stalled 12.9 s while it loaded (7 ms after the fix), so chat froze too. Matching is now linear.

  • Split drag: the page area keeps its start width while the handle is dragged and lays out once on release. Chromium at 4x CPU throttle, Wikipedia in the panel: frames over 50 ms during a drag went from 25 to 2, long-task time from about 3.4 s to 0.5 s.

  • Desktop native views: only the newest bounds are sent during a resize (no backlog), show/hide only on a tab switch, views close when the panel closes (no background audio or scripts), and a reopened view returns to the page it had reached. browser_view_show is async (a sync command creating a webview deadlocks on Windows).

  • A child webview breaks Tauri's WebviewWindow extractor and get_webview_window, so file dialogs, clipboard, native intents and tray restore failed once a page was open. Commands now take the calling Webview; window lookups use get_window.

  • Linux desktop uses the proxied frame: Tauri packs Linux child webviews into the window's GtkBox, which ignores their bounds.

  • Back/Forward on macOS come from WebKit's own history (no Navigation API before Safari 26.2).

  • Open in default app checks where the opened file really is (a sandbox folder swapped for a link could stage an outside file), and requires the installation owner.

  • Bot checks: a Cloudflare/Akamai Server header only counts on a 403, so rate limits and outages are not reported as bot checks; "Open in browser" is the primary action on a bot check.

  • Reopening a file that changed since it opened shows the new bytes. Pages in native views can open at most one tab per second.

  • Web annotations: a page's title or address cannot close the annotation block the model reads, a marked password field never copies its value, a long address no longer drops the chip's title and link, and marks stay open if the composer refuses them.

  • Links and forms go through the proxy only after the page's own handlers leave them alone (router links and fetch-based forms stay in the page), and requestSubmit() keeps native validation. Checked in Chromium, Firefox and WebKit: 15 failing cases before, none after.

  • Reload drops only the current page from the cache, so Back keeps earlier pages and form results. /api/browser is under the request body cap, revealing one sandbox file needs the installation owner, and a failed fetch logs only the host.

  • Windows pages keep SmartScreen on (their WebView2 arguments had dropped it with wry's defaults); the app's own webview is unchanged.

  • Inline onclick="return false" / onsubmit="return false" handlers now cancel the proxy navigation, as preventDefault does.

  • Non-UTF-8 text files (text/csv; charset=iso-8859-1 and similar) are transcoded to UTF-8 instead of showing garbled.

  • Sent attachment tabs are keyed by message, so two messages with the same file name open separate tabs. Send in the annotate bar shows for a first comment and cannot stage twice.

  • Remote chat images whose host refuses CORS still open in the image viewer. A failed native support probe fails a data clear instead of skipping it, so an account switch never keeps the previous account's cookies.

  • A native view refuses an address too long for the bar to show, so the bar never keeps an older page's address. Tab menu Reload reloads native views through the native path.

  • Legacy charset labels and unlabelled pages decode as windows-1252, as browsers do, and unquoted meta refreshes are followed.

  • An account switch clears native site data before anything else is purged, so a failed clear leaves the signed-in account whole. Reopened files are compared in 1 MiB slices rather than byte by byte on the UI thread.

  • Scheme-less IP and IDN links in answers open as web links, not chat files; Studio-URL detection resolves addresses before comparing origins; concurrent native downloads differing only by case get separate names on Windows and macOS.

  • A fitted image refits when the viewer resizes. The sandbox open tests stub os.startfile, so Windows runs never launch an app.

  • Duplicate on a tab showing a form's result asks before posting it again, as Back does, instead of resending the form. A muted tab stays muted in the desktop app when its native view is closed to make room for others and reopened.

Screenshots

Before (main) vs after (this PR): the browser button opens the panel beside the chat, here on example.com, with the address bar's bookmark star and its site panel open (connection status, clear browsing data, browser settings).

Before and after

The tab's right-click menu (pin to sidebar, new tab to the right, duplicate, fork into a chat, copy URL, rename, mute, close) and the page pinned to the sidebar's Pinned section:

Tab menu and pinned page

pre-commit-ci Bot and others added 3 commits September 30, 2026 10:33
- Run page fetches in their own pool, off the event loop, and cancel them
  when the panel aborts the load, so browsing can't stall chat streaming.
- Only honor tab opens, external links and shortcuts from a page when its
  frame has focus and the user just interacted, rate limited to one per
  second.
- Drop http: and ws: from the shell's connect-src and add
  treat-as-public-address, so pages can't reach local services.
- Refuse favicons that point at Studio.
- Cache loaded pages per history entry for instant back and forward, cap
  history at 50, and keep only the 4 most recent tabs mounted.
- Memoize the panel and tabs, skip no-op tab updates, and watch only
  <head> for title changes.
- Set the side panel width on the header, fade and notice instead of the
  content root, so resizing doesn't restyle the whole thread.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

- Open local HTML files in the same frame as the attachment preview, so
  network access stays off until the user allows it.
- Allow only https in the shell's fetch directives and add
  upgrade-insecure-requests. WebKit has no local network protection, so
  http images, scripts, styles, media and frames could reach local
  services directly.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

shimmyshimmer and others added 2 commits September 30, 2026 05:22
…cache

- Load pages into a srcdoc child of the shell, then set frame-src 'none'
  on the shell. The child keeps its own policy, so embeds still load, but
  can no longer navigate itself. This does not depend on the Navigation
  API, which WebKit and Chrome don't fire here, and closes the gap where
  the desktop app's frame-src allows every loopback port.
- Parse frame messages field by field and bound titles, URLs and bodies,
  so a malformed message can't crash the chat.
- Give the page cache a 32 MB total and 8 MB per-page byte budget, and
  drop a tab's pages when it closes.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

- Opened files get a file menu (full name, Open in new chat or tab),
  Request edits, a zoom menu and download.
- Page menu: find in page, copy link, zoom, device toolbar, downloads,
  history, clear browsing data and browser settings.
- History and Downloads pages with search and per-row removal.
- Settings: show full URL, manage history and downloads, clear data.
- Browser button uses the internet icon, hides in a new chat and while
  the panel is open.
- Code, text and plain file icons use the foreground color; only docs
  stay blue.
- Washes follow the contrast setting and the tab height follows the UI
  scale.
- Favicons from pages load through the guarded fetch and show as blob
  URLs, so a page cannot point Studio at a local or LAN address.
- Provider sign-in URLs always open in the system browser, since the
  browser panel keeps no cookies.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

shimmyshimmer and others added 5 commits September 30, 2026 07:23
- New Browser section under Shortcuts, with the browser icon: links and
  files, address bar, and browsing data.
- Browser rows leave the Chat section; the panel's Browser settings item,
  settings search, the command palette and the desktop Settings menu
  point at the new section.
- Breadcrumb back to Settings and Browser settings, large title, and a
  search pill with a time range filter (all time, today, 7 or 30 days).
- Days are collapsible cards; rows show the site favicon (loaded through
  the guarded fetch once on screen), title, host, time and a menu to open
  the page or remove it.
- Rows can be selected and removed together; Clear browsing data sits
  above the list.
unpdf sets globalThis.pdfjsWorker to its own PDF.js build, which the viewer's
PDF.js then adopts and fails on (API 5.4.296 vs worker 5.6.205). Give each
document its own worker so that lookup never happens. Same change as #12346.
…link menus, canvas tools

- Full view: floating chat over the browser, minimize, move chat to the left/right pane (Shift+Cmd+F)
- File toolbar floats over the document; new tab page, menus and icons restyled
- Request edits: annotate mode with a comment-bubble cursor, click or drag an area to
  mark it, comment, and send all marks to the chat as one annotations attachment
- Image viewer for chat images (gallery, zoom, download, open source page)
- Right-click menus for web links, sandbox file links, created-file rows and attachments;
  sandbox files can be opened in the default app or revealed in the file manager
- Canvas parity for file tabs: Preview/Source, Run again, Console with error badge,
  Fix with the model, Copy, Wrap lines, Open in Canvas
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 4 commits September 30, 2026 16:41
…urity fixes

Desktop app: web pages now load in a native child webview per tab instead of
the proxy and sandboxed iframe, so Cloudflare challenges, logins and web apps
work. Navigation is limited to public http(s) hosts (plus a WebKit content
rule list on macOS for subresources), the views get no IPC, use their own
data store, turn popups into tabs and quarantine downloads. Also fixes the
tab strip being covered by the macOS titlebar drag region.

Web UI: bot-check refusals are detected and explained, HTML responses are
capped, favicons use a smaller cap, pushState reports are coalesced, and
history writes are batched and capped.

Chat performance: link context menus mount lazily, web links skip file-scope
subscriptions, a descendant :has() on the thread is replaced, PDF.js shares
one worker, and the image viewer drops its backdrop blur.

Security: SVG and HTML never open from blob URLs on Studio's origin, redirect
unwrapping only follows web targets, bidi controls are stripped from the
address, and "Open in default app" opens a staged copy so a swapped symlink
can't redirect it.
…, annotate HTML source

- Send includes the annotation still being typed instead of dropping it.
- Save Link As puts the page's base URL back, so relative links resolve.
- Request edits on an HTML preview switches to its source; the framed
  preview can't be selected from the parent.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Pages in the desktop app's native webviews now connect through a loopback
proxy (browser_proxy.rs) that resolves each host itself, refuses private or
loopback answers and connects to the address it checked. That covers every
request (images, fetch, sockets), not just navigations, on every platform,
and stops hostnames and DNS rebinding from reaching local services.

- macOS 14+: set on the pages' data store, with the Network calls looked up
  at run time so older macOS still launches. macOS 13 and earlier keep the
  content rule list.
- Windows: WebView2 --proxy-server with <-loopback> so loopback isn't
  bypassed. Linux: WebKitGTK proxy settings on the pages' own context.

Also fixes a crash: polling the page address called wry's url(), which
panics on macOS while WebKit has no URL (a failed load).
chatgpt-codex-connector[bot]

This comment was marked as resolved.

shimmyshimmer and others added 2 commits October 4, 2026 21:30
…, site info icons

- Find in page uses Studio's own find bar: the page is matched in its
  frame (case-insensitive, visible text, same highlights as the chat's)
  and counted back. The bar gets chat / browser page buttons while a page
  is open; Cmd+F searches whichever has focus. The browser's own find bar
  and window.find are gone.
- Print: a copy of the page as it is now goes to a separate print frame
  (/api/browser/print) whose sandbox allows the dialog and whose CSP runs
  only its own script.
- Take a screenshot (Chromium): this tab's capture cropped to the page,
  added to the chat's composer or saved.
- Site info: a slimmer padlock sized and aligned with the other rows, no
  dividers around it, and a certificate icon. The chat header's new tab
  button shows the globe again.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 1f65d24069

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…er settings tab

- The find bar leads with a search icon; the chat / browser page scope
  buttons are plain icons, the one being searched lit and the other
  dimmed, with a divider before close. The chat one is the plain bubble
  Settings uses for Chat. The bar widens by their room while they show.
- The Browser settings tab shows the globe instead of a window.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 2bd78d1c90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…dier web screenshots

Desktop app (src-tauri/src/browser_capture.rs):
- Take a screenshot needs no screen-share prompt. A page in a native view is captured by its
  engine (WebKit's snapshot on macOS, Chromium's Page.captureScreenshot on Windows); files,
  internal pages and proxied frames are captured from the app's webview, cropped to the page
  area (macOS, Windows, and WebKitGTK on Linux). The menu item always shows in the desktop app.
- Print works for native pages: WebKit's print sheet on macOS, titled after the page, from a copy
  of the shared print info (wry's print() zeroes the shared margins, so pages print to the edge
  and so does everything after); Edge's print preview on Windows via ShowPrintUI, which a page
  can't replace the way it can window.print().
- Print stays off for framed pages in the macOS app, whose webview drops print() from frames,
  rather than reporting success.
- Native capture and print wait for the view to come back after the menu that asked hides it.

Web build:
- The region capture waits for frames and the page to keep one size (the sharing bar settled)
  instead of a fixed 350 ms, waits for closing menus to leave the page, and stops quietly when
  sharing ends. Toasts, tooltips and the file toolbar are hidden for the shot.
- With the device toolbar on, the shot is the device's width only.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 5209f7d1f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ute tabs

Tab right-click menu: Pin to sidebar, New tab to the right, Reload (the two-arrow refresh icon),
Duplicate (a copy with its history, beside it), Fork (into a new or temporary chat), Copy URL,
Open in external browser, Rename, Mute tab, Close, Close other tabs, Close tabs to the right.

- Pinned pages (pinned-pages-store, per account like bookmarks) show in the sidebar's Pinned
  section after its chats and folders: the site's icon and title, a one-click unpin, and the same
  menu as the tab (3-dot and right-click). Clicking one shows its tab, or opens one at the pinned
  address; from outside a chat it goes to one first.
- Rename edits the name in place, in the tab or the sidebar row; it is kept as the tab
  navigates, and empty gives back the page's title. A pinned tab and its row share the name.
- Mute: a muted tab shows a speaker to unmute it. Framed pages mute their media (on the page or
  not) and suspend Web Audio, and a muted tab's next page loads muted. In the desktop app,
  Windows mutes the WebView2 view; macOS mutes each page's media as it commits and loads.
- The tab menu (tab-menu.tsx) is shared by the tab strip and the sidebar row.
- Strings in every locale.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

… pruned muted view reopens muted

Duplicate tab copied each history entry into a new object, so the resubmit guard (keyed by entry) no longer knew a copied POST had been sent: the copy posted the form again unasked. Copied POST entries are now marked sent, so the copy asks first. browser_view_close also forgot a tab's mute, and it is how the panel prunes views past four, so a muted tab came back with sound while showing muted; the mute now stays until the tab is unmuted.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 5e8a1c0c71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

frame.tabIndex = -1;
// Kept on screen at a pixel: a frame with no size may never lay out its images.
frame.style.cssText = "position:fixed;right:0;bottom:0;width:1px;height:1px;border:0;opacity:0;pointer-events:none";
frame.src = apiUrl("/api/browser/print");
Comment on lines +186 to +194
{
type: "unsloth:browser-html",
html,
url,
base,
refresh: refresh ?? null,
zoom: zoomRef.current,
muted: mutedRef.current,
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects UI# new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard >3000#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants