Skip to content

Studio: keep browser tabs across a reload, make browser use approvals port-aware - #17596

Merged
shimmyshimmer merged 4 commits into
mainfrom
studio-browser-followups
Nov 13, 2026
Merged

shimmyshimmer merged 4 commits into
mainfrom
studio-browser-followups

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

What changed

Follow-ups from a review of the Studio browser and browser use. Separate from #17594, no overlap in behaviour.

Browser tabs survive a reload

  • Reloading the page used to close the browser panel and drop every tab. Open tabs and each chat's panel state (open, active tab, full view, floating) are now kept in sessionStorage and restored on load.
  • sessionStorage on purpose: a reload brings the tabs back, a new window or a fresh launch starts without a browser, and two windows do not share one tab list.
  • Only what can be loaded again is kept: new tab pages, internal pages and GET web pages. Files (their bytes live in memory), form posts and pages opened beside a temporary chat are dropped from a tab's history.
  • A chat that was never saved gets a new key on reload, so its tabs follow it to the new chat. A saved chat keeps its own tabs.
  • Saved under an account-scoped key, and an account switch already clears sessionStorage.

Browser use approvals are port-aware

  • Approvals were keyed on hostname only, so approving example.edu also covered example.edu:8081, and an Always allow for submit or sign-in carried to any port. A non-default port is now its own site and asks again. http and https on their default ports remain one site, so an upgrade does not ask twice.
  • Site patterns in Settings and the request's website policy are unchanged.

Browser use refuses the port Studio is really on

  • The guard that keeps the model off Studio's own address was a fixed range (8888 to 8908). It now also refuses the port this server is bound to, for example -p 8000.

How it was verified

  • Frontend: npm run typecheck, npm test (15755 pass, 0 fail), npm run build. New browser-tab-session tests, plus port cases in browser-agent-gate and browser-agent-always-allow.
  • Backend: pytest studio/backend/tests/test_browser_agent.py studio/backend/tests/test_browser_routes.py (200 passed), with a new own-port case.
  • Live, in an isolated Studio on macOS: opened the browser in a new chat, loaded a page, reloaded the window; the panel came back open on the same tab.

Not verified here

  • The port-aware approvals and the own-port guard are covered by unit tests only; they were not exercised with a live model (CPU-only host).
  • Tab restore was checked in web Studio, not in a Desktop build, where pages show in native views.
  • biome check reports pre-existing formatting errors repo-wide; none are on lines this PR touches.

… port-aware

Browser tabs and each chat's panel state are kept in sessionStorage, so a reload of the window brings them back; an unsaved chat's tabs follow it to its new key.
Browser use approvals now tell example.edu from example.edu:8081, and the backend refuses the port this Studio is actually listening on, not only the default range.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T15:14:28.067502Z 9e867a6 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8370503bcd

ℹ️ 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".

Comment on lines +210 to +211
export async function chatIsUnsaved(chat: string): Promise<boolean> {
if (!chat.startsWith("single:")) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore tabs belonging to unsaved project chats

When tabs are opened beside an unsaved project chat, reloading still makes them inaccessible. chat-page.tsx assigns these chats a project:${view.projectId}:${projectNewThreadNonce} key and regenerates the nonce on mount, but this check rejects every project key, so claimRestored never transfers their persisted tabs or panel state to the new key. Handle unsaved project-chat keys as well, while ensuring restoration stays within the same project.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9e867a6: a project's unsaved chat key now counts as unsaved, and its tabs are only handed to a new chat of the same project. Test covers the same project, another project and a plain chat.

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 9e867a6540

ℹ️ 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".

@shimmyshimmer
shimmyshimmer merged commit d58508d into main Nov 13, 2026
@shimmyshimmer
shimmyshimmer deleted the studio-browser-followups branch November 13, 2026 07:05
shimmyshimmer added a commit that referenced this pull request Nov 13, 2026
## What changed

With the browser panel open, every chat you pass through got a new empty
tab, and that tab stayed in the browser's state after you left. Clicking
New chat four times left three empty tabs behind for chats that may
never be shown again. They are small, but nothing removed them until a
reload, and they count toward the 50 tab limit on what a reload
restores, so in a long running window they could push real tabs out of
the saved session.

Leaving a chat whose only tab is an untouched new tab now drops that
tab. The chat still remembers that its panel was open (and full view),
so coming back to it looks the same as before: it opens on a new tab. A
tab that was renamed or pinned is kept.

## How it was verified

- New test in `tests/browser-store-chats.test.ts`; it fails without the
change.
- `npm run typecheck`, `npm test` (15882 passed, 0 failed) and `npm run
build` in `studio/frontend`.
- Driven in a local web Studio with a scripted browser: after four New
chat clicks the saved tab state held no leftover empty tabs (three
before the change), the first chat kept its two pages, and browser Back
and Forward still showed each chat its own tabs.

## Not tested here

- The Desktop app was not run. The change is in the tab state both
surfaces share.
- The live check ran on this change applied on top of #17596 before that
PR merged; on this branch only the automated checks were run.
danielhanchen added a commit that referenced this pull request Nov 13, 2026
…17668)

## Summary

`Frontend build + bundle sanity` intermittently fails on PRs that do not
touch the browser (seen on #17641 and #17659):

```
not ok - an unsaved chat's tabs follow it to the key a reload gives it, by either way the chat page names it
  location: 'studio/frontend/tests/browser-tab-session.test.ts:160:1'
  + actual - expected
  +   false,
  +   []
  -   true,
  -   [
  -     'https://draft.example/'
  -   ]
```

The test came in with #17596. After a reload, the browser store asks
storage whether the chat shown before the reload was saved
(`chatIsUnsaved` in `tab-session.ts`), and that lookup starts with a
dynamic `import()`. In the test, the import goes through the module
hooks registered by `browser-store-resolver.mjs`. The test waited one
`setTimeout(0)` and then asserted that the lookup had landed. On a busy
runner the import can take longer than one timer tick, so the unsaved
chat's tabs had not been handed over yet.

The store is right: it handles the lookup landing either before or after
the chat is named, and that is what the test is checking. Only the
test's wait was too short.

## Change

- The test stub's `__storedThreads` is now a `Set` that counts `has`
calls, which is how the stub answers each lookup. `reloaded()` counts a
lookup when the session it reloads from shows a `single:` chat, which is
the only case where the store looks one up.
- `settled()` waits until every started lookup has been answered (10 s
cap, then fails with "a stored-chat lookup never answered"), then waits
one more tick for the store's `.then`.

No product code changes.

## Testing

- Sabotage: with a 5 ms delay added to the stub's `getStoredChatThread`,
main's version of the test fails with the same diff as CI. With this
change it passes with a 5 ms delay and with a 60 ms one.
- Without the delay: `tests/browser-tab-session.test.ts` 7 passed, 3
runs.
- `tsc -p tsconfig.test.json`: no errors in the file.
shimmyshimmer added a commit that referenced this pull request Nov 14, 2026
…local links (#17646)

## What changed

Three additions to the Studio browser settings. Independent of #17594
and #17596.

**Import browsing history**
- Settings > Browser > Browsing data has a new Import history row, next
to the existing bookmark import.
- Accepts Safari's `History.json` (File > Export Browsing Data) and
Chrome's history from Google Takeout. Both arrive as a ZIP; unzip and
pick the JSON.
- Only http and https visits with a sane date are imported. Importing
the same file twice adds nothing, and the "Keep history for" setting and
the history limit still apply. The import works with history saving
turned off, since it is an explicit action.

**Camera and microphone site settings (Desktop app)**
- A new section sets Ask or Block for camera and for microphone, as a
default and per site. A site rule wins over the default.
- Block only: the app still never grants a page a capture device itself.
Ask is the system's own prompt, as before. The existing test that proves
no path returns Allow now runs over every rule combination.
- Rules are stored per account in the app and sent to the shell at
startup and on change. Until the first send, requests get the system
prompt.

**Links to local addresses**
- With "Open links in: Unsloth browser" on, a link to `localhost` used
to open a panel tab that cannot load, because a local page only opens in
the panel when its address is typed there. Such links now go to the
default browser, and the setting's description says so.

## How it was verified

- Frontend: `npm run typecheck`, `npm test` (15884 pass, 0 fail), `npm
run build`. New `browser-history-import` and `browser-capture-sites`
tests.
- Rust: `cargo test page_` (5 passed) and `cargo test capture` (8
passed) on macOS.
- Live, in an isolated web Studio on macOS: the Import history row is
present; importing a small Safari-format file added the one valid visit
and dropped a `javascript:` entry and one dated 1970. The camera and
microphone section is hidden outside the Desktop app, as intended.

## Not verified here

- The camera and microphone settings screen and the real block behaviour
need a running Desktop app, which was not built or driven. The Rust
change has no platform-specific code, but Windows and Linux were not
compiled.
- A site that WebView2 has already been told to allow may not reach the
handler, so Block may not apply to it until that saved answer is reset.
- The import formats follow Apple's and Google's published schemas; no
real export file was available.
- Other locales fall back to English for the new strings.
- `biome check` reports pre-existing formatting errors repo-wide; the
new files add none at error level.

Schemas:
https://developer.apple.com/documentation/safariservices/importing-data-exported-from-safari
and
https://developers.google.com/data-portability/schema-reference/chrome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants