Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: keep browsing from a temporary chat out of browser history (#12984)

Nilaya1b00a3a89dc
diff --git a/studio/frontend/src/features/browser/browser-panel.tsx b/studio/frontend/src/features/browser/browser-panel.tsx
index 58a1265cc65..0d6d057a978 100644
--- a/studio/frontend/src/features/browser/browser-panel.tsx
+++ b/studio/frontend/src/features/browser/browser-panel.tsx
@@ -34,6 +34,7 @@ import {
ATTACHMENT_KIND_ICONS,
ATTACHMENT_KIND_ICON_CLASS,
attachmentFileKind,
+ useChatRuntimeStore,
} from "@/features/chat";
import { formatBytes } from "@/features/hub";
import { startLibraryChat } from "@/features/library";
@@ -1043,6 +1044,8 @@ function tabDownload(tab: BrowserTab | undefined): BrowserDownload | undefined {
? {
...page,
url: tab.displayUrl ?? (entry.kind === "web" ? entry.url : null),
+ // Only a temporary page's own flag: otherwise the chat shown when Download is clicked decides.
+ temporary: entry.kind === "web" && entry.temporary ? true : undefined,
}
: undefined;
}
@@ -1134,6 +1137,8 @@ function ZoomControl({ tab }: { tab: BrowserTab | undefined }) {
}
async function takeScreenshot(tab: BrowserTab, page: HTMLElement, t: ReturnType<typeof useT>): Promise<void> {
+ const shown = currentEntry(tab);
+ const temporary = useChatRuntimeStore.getState().incognito || (shown.kind === "web" && shown.temporary === true);
let blob: Blob | null;
try {
blob = await screenshotPage(tab, page);
@@ -1152,7 +1157,7 @@ async function takeScreenshot(tab: BrowserTab, page: HTMLElement, t: ReturnType<
const pad = (value: number) => String(value).padStart(2, "0");
const stamp = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}.${pad(now.getMinutes())}.${pad(now.getSeconds())}`;
const name = `Screenshot ${entry.kind === "web" ? hostOf(entry.url) : tab.title || "page"} ${stamp}.png`.replace(/[\\/:*?"<>|]+/g, "-");
- const download: BrowserDownload = { blob, name, contentType: "image/png", url: null };
+ const download: BrowserDownload = { blob, name, contentType: "image/png", url: null, temporary };
const attach = useBrowserStore.getState().attachToChat;
if (attach && (await attach(new File([blob], name, { type: "image/png" })))) {
toast.success(t("browser.screenshot.added"), {
diff --git a/studio/frontend/src/features/browser/downloads.ts b/studio/frontend/src/features/browser/downloads.ts
index 67c3ae3d114..a9504512b7e 100644
--- a/studio/frontend/src/features/browser/downloads.ts
+++ b/studio/frontend/src/features/browser/downloads.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+import { useChatRuntimeStore } from "@/features/chat";
import { getLocale, translate } from "@/i18n";
import { isTauri } from "@/lib/api-base";
import { DownloadCancelledError, downloadFile, isDownloadCancelled } from "@/lib/native-files";
@@ -14,7 +15,14 @@ import { useBrowserHistoryStore } from "./history-store";
import { type SavedNativeDownload, saveNativeDownload } from "./native-downloads";
import { useBrowserPrefsStore } from "./prefs-store";
-export type BrowserDownload = { blob: Blob; name: string; contentType: string; url: string | null; site?: string };
+export type BrowserDownload = {
+ blob: Blob;
+ name: string;
+ contentType: string;
+ url: string | null;
+ site?: string;
+ temporary?: boolean;
+};
type SaveHandle = {
name: string;
@@ -60,6 +68,8 @@ function approved(url: string | null, name: string, site?: string): Promise<bool
/** Website files wait for approval first. `target`: a location already picked, null for none; omitted, the dialog opens when Settings asks. */
export async function saveBrowserDownload(download: BrowserDownload, target?: SaveHandle | null): Promise<void> {
+ // Taken now: the fetch, approval and the save dialog can outlast the temporary chat.
+ const temporary = download.temporary ?? useChatRuntimeStore.getState().incognito;
if (target === undefined) {
if (!(await approved(download.url, download.name, download.site))) return;
// A save dialog needs a fresh click; a late approval waits for a click on Save instead.
@@ -68,16 +78,20 @@ export async function saveBrowserDownload(download: BrowserDownload, target?: Sa
toast(translate("browser.downloadPrompt.ready", { name: safeDownloadName(download.name) }, locale), {
action: {
label: translate("browser.downloadPrompt.save", {}, locale),
- onClick: () => void writeDownload(download, undefined),
+ onClick: () => void writeDownload(download, undefined, temporary),
},
});
return;
}
}
- await writeDownload(download, target);
+ await writeDownload(download, target, temporary);
}
-async function writeDownload(download: BrowserDownload, target: SaveHandle | null | undefined): Promise<void> {
+async function writeDownload(
+ download: BrowserDownload,
+ target: SaveHandle | null | undefined,
+ temporary: boolean,
+): Promise<void> {
const { blob, contentType, url } = download;
const name = safeDownloadName(download.name);
let saved: SavedNativeDownload | null = null;
@@ -108,13 +122,8 @@ async function writeDownload(download: BrowserDownload, target: SaveHandle | nul
return;
}
const savedName = saved?.name || picked?.name || name;
- const historyId = useBrowserHistoryStore.getState().recordDownload({
- name: savedName,
- url,
- size: blob.size,
- contentType,
- nativeId: saved?.id,
- });
+ const item = { name: savedName, url, size: blob.size, contentType, nativeId: saved?.id };
+ const historyId = useBrowserHistoryStore.getState().recordDownload(item, temporary);
// Open uses the saved file when the app kept it; only otherwise does this session hold the bytes.
const shown = finishDownload(
key,
@@ -147,6 +156,7 @@ function linkDownload(page: BrowserPage, url: string): BrowserDownload {
/** Save what a link points at, fetched through the panel's proxy so any site works. */
export async function saveLinkAs(url: string): Promise<void> {
+ const temporary = useChatRuntimeStore.getState().incognito;
const controller = new AbortController();
const pending = fetchBrowserPage({ url }, controller.signal).then((page) => linkDownload(page, url));
// The dialog needs the menu click, which a slow fetch outlasts: ask with the resolved name
@@ -181,5 +191,5 @@ export async function saveLinkAs(url: string): Promise<void> {
if (asked !== undefined && isDangerousDownload(download.name) && !isDangerousDownload(asked)) {
if (!(await approved(url, download.name))) return;
}
- await saveBrowserDownload(download, target);
+ await saveBrowserDownload({ ...download, temporary }, target);
}
diff --git a/studio/frontend/src/features/browser/history-store.ts b/studio/frontend/src/features/browser/history-store.ts
index 51770f84bc2..d314f9e643d 100644
--- a/studio/frontend/src/features/browser/history-store.ts
+++ b/studio/frontend/src/features/browser/history-store.ts
@@ -3,6 +3,7 @@
import { create } from "zustand";
import { type StateStorage, createJSONStorage, persist } from "zustand/middleware";
+import { useChatRuntimeStore } from "@/features/chat";
import { accountDatabaseName } from "@/lib/account-transition";
import { hostOf } from "./address";
import { forgetNativeDownloads } from "./native-downloads";
@@ -45,6 +46,10 @@ function iconsFor(history: HistoryItem[], icons: Record<string, string>): Record
return Object.fromEntries(Object.entries(icons).filter(([host]) => hosts.has(host)));
}
+function savesHistory(temporary: boolean): boolean {
+ return useBrowserPrefsStore.getState().saveHistory && !temporary && !useChatRuntimeStore.getState().incognito;
+}
+
function retentionCutoff(): number {
const days = useBrowserPrefsStore.getState().historyRetentionDays;
return days > 0 ? Date.now() - days * DAY_MS : 0;
@@ -87,10 +92,10 @@ interface BrowserHistoryState {
downloads: DownloadItem[];
/** Host to the icon its pages declared, newest last. */
icons: Record<string, string>;
- recordVisit: (url: string, title: string) => void;
- recordIcon: (host: string, icon: string) => void;
- /** The new row's id; undefined when download history is off. */
- recordDownload: (item: Omit<DownloadItem, "id" | "downloadedAt">) => string | undefined;
+ recordVisit: (url: string, title: string, temporary?: boolean) => void;
+ recordIcon: (host: string, icon: string, temporary?: boolean) => void;
+ /** The new row's id; undefined when download history is off or a temporary chat is shown. */
+ recordDownload: (item: Omit<DownloadItem, "id" | "downloadedAt">, temporary?: boolean) => string | undefined;
removeVisit: (id: string) => void;
removeVisits: (ids: ReadonlySet<string>) => void;
removeDownload: (id: string) => void;
@@ -106,19 +111,19 @@ export const useBrowserHistoryStore = create<BrowserHistoryState>()(
history: [],
downloads: [],
icons: {},
- recordIcon: (host, icon) =>
+ recordIcon: (host, icon, temporary = false) =>
set((state) => {
if (!host || icon.length > MAX_URL_CHARS || state.icons[host] === icon) return state;
// Icons name the hosts visited, so they follow the history setting.
- if (!useBrowserPrefsStore.getState().saveHistory) return state;
+ if (!savesHistory(temporary)) return state;
const { [host]: _replaced, ...rest } = state.icons;
const hosts = Object.keys(rest);
for (const old of hosts.slice(0, Math.max(0, hosts.length + 1 - MAX_ICONS))) delete rest[old];
return { icons: { ...rest, [host]: icon } };
}),
- recordVisit: (url, fullTitle) =>
+ recordVisit: (url, fullTitle, temporary = false) =>
set((state) => {
- if (url.length > MAX_URL_CHARS || !useBrowserPrefsStore.getState().saveHistory) return state;
+ if (url.length > MAX_URL_CHARS || !savesHistory(temporary)) return state;
const title = fullTitle.slice(0, MAX_TITLE_CHARS);
const cutoff = retentionCutoff();
const kept = cutoff ? state.history.filter((visit) => visit.visitedAt >= cutoff) : state.history;
@@ -132,8 +137,9 @@ export const useBrowserHistoryStore = create<BrowserHistoryState>()(
const icons = kept.length < state.history.length ? iconsFor(history, state.icons) : state.icons;
return { history, icons };
}),
- recordDownload: (item) => {
- if (!useBrowserPrefsStore.getState().saveDownloadHistory) {
+ recordDownload: (item, temporary) => {
+ // Callers that took the state when the download began pass it; the rest go by the chat shown now.
+ if (!useBrowserPrefsStore.getState().saveDownloadHistory || (temporary ?? useChatRuntimeStore.getState().incognito)) {
if (item.nativeId) forgetNativeDownloads([item.nativeId]);
return undefined;
}
diff --git a/studio/frontend/src/features/browser/native-view.ts b/studio/frontend/src/features/browser/native-view.ts
index 43730234aec..0adf9fc989d 100644
--- a/studio/frontend/src/features/browser/native-view.ts
+++ b/studio/frontend/src/features/browser/native-view.ts
@@ -3,6 +3,7 @@
/** desktop web pages use per-tab native views for bot checks; native views cover the DOM, so overlays use snapshots. */
+import { useChatRuntimeStore } from "@/features/chat";
import { getLocale, translate } from "@/i18n";
import type { TranslationKey } from "@/i18n";
import type { InterpolationValues } from "@/i18n";
@@ -97,7 +98,7 @@ function keepReachedPage(tabId: string): void {
const tab = store.tabs.find((candidate) => candidate.id === tabId);
const shown = pages.get(tabId);
if (!tab || !shown?.url || currentEntry(tab).kind !== "web" || shown.url === currentEntryUrl(tab)) return;
- store.navigate(tabId, { url: shown.url }, { replace: false });
+ store.navigate(tabId, { url: shown.url, temporary: temporaryPages.get(tabId) }, { replace: false });
store.updateTab(tabId, { title: shown.title, favicon: shown.favicon, loading: false });
}
@@ -108,6 +109,9 @@ function closeView(tabId: string): void {
zooms.delete(tabId);
icons.delete(tabId);
pages.delete(tabId);
+ temporaryPages.delete(tabId);
+ pageEntries.delete(tabId);
+ loadingPages.delete(tabId);
recency = recency.filter((id) => id !== tabId);
void call("browser_view_close", { tabId }).catch(() => undefined);
}
@@ -122,6 +126,27 @@ function listenOnce(): void {
);
}
+// Prompts asked for beside a temporary chat: their downloads land later, often after the chat is gone.
+const temporaryDownloads = new Set<string>();
+
+// Per tab, whether its page began loading beside a temporary chat: in-page navigation makes no new entry.
+// A page's first load is its entry's, which may start long after the entry was made (a background tab).
+const temporaryPages = new Map<string, boolean>();
+const pageEntries = new Map<string, BrowserEntry>();
+// Tabs mid-load: a redirect starts again within the same navigation, which keeps its state.
+const loadingPages = new Set<string>();
+
+function notePageStart(tabId: string, entry: Extract<BrowserEntry, { kind: "web" }>): void {
+ const fresh = pageEntries.get(tabId) !== entry;
+ pageEntries.set(tabId, entry);
+ const kept = fresh ? entry.temporary === true : loadingPages.has(tabId) && temporaryPages.get(tabId) === true;
+ temporaryPages.set(tabId, useChatRuntimeStore.getState().incognito || kept);
+}
+
+function pageTemporary(tabId: string, entry: BrowserEntry): boolean {
+ return temporaryPages.get(tabId) ?? (entry.kind === "web" && entry.temporary === true);
+}
+
/** One running download in the Downloads button, from approval until it ends. */
const downloadKey = (promptId: string) => `native:${promptId}`;
@@ -129,6 +154,7 @@ const downloadKey = (promptId: string) => `native:${promptId}`;
function onDownloadPrompt(event: Extract<NativeEvent, { kind: "downloadPrompt" }>, tab: BrowserTab | undefined): void {
const { id, url, site, name, saveAs } = event;
const entry = tab ? currentEntry(tab) : null;
+ if (useChatRuntimeStore.getState().incognito || (tab && entry && pageTemporary(tab.id, entry))) temporaryDownloads.add(id);
// The site asking is the page that started it, taken then (a later site's answer must not cover it); blob: counts as its creator. With no web origin yet, the opener or the address asked for.
const asking = downloadSiteOf(site) ? site : entry?.kind === "web" ? entry.from || entry.url : "";
// Picked from the context menu: the save dialog is the prompt, whatever the site's remembered answer.
@@ -141,6 +167,7 @@ function onDownloadPrompt(event: Extract<NativeEvent, { kind: "downloadPrompt" }
const key = downloadKey(id);
void decided
.then(async (allow) => {
+ if (!allow) temporaryDownloads.delete(id);
// Begun before deciding: a file that finished while the prompt was open lands at once.
if (allow) beginDownload(key, name);
await decideNativeDownload(id, allow, saveAs || useBrowserPrefsStore.getState().askWhereToSave);
@@ -148,7 +175,10 @@ function onDownloadPrompt(event: Extract<NativeEvent, { kind: "downloadPrompt" }
const { active, buttons } = useDownloadActivity.getState();
if (allow && buttons === 0 && key in active) toast(t("browser.native.downloading", { name }));
})
- .catch(() => abandonDownload(key));
+ .catch(() => {
+ temporaryDownloads.delete(id);
+ abandonDownload(key);
+ });
}
@@ -160,6 +190,7 @@ function onNativeEvent(event: NativeEvent): void {
return;
}
if (event.kind === "downloadCancelled") {
+ temporaryDownloads.delete(event.promptId);
abandonDownload(downloadKey(event.promptId));
return;
}
@@ -168,19 +199,27 @@ function onNativeEvent(event: NativeEvent): void {
if (openedTabs.has(event.tabId)) onDownload(event);
return;
}
- if (!tab || currentEntry(tab).kind !== "web") return;
+ if (!tab) return;
+ const entry = currentEntry(tab);
+ if (entry.kind !== "web") return;
const history = useBrowserHistoryStore.getState();
+ if ((event.kind === "load" && event.loading) || event.kind === "url") notePageStart(tab.id, entry);
+ if (event.kind === "load") {
+ if (event.loading) loadingPages.add(tab.id);
+ else loadingPages.delete(tab.id);
+ }
+ const temporary = pageTemporary(tab.id, entry);
switch (event.kind) {
case "load":
store.updateTab(tab.id, { loading: event.loading, displayUrl: event.url, ...leftOpenedPage(tab, event.url) });
page(tab.id).url = event.url;
remember(tab.id, event.url);
- if (!event.loading) history.recordVisit(event.url, tab.title);
+ if (!event.loading) history.recordVisit(event.url, tab.title, temporary);
break;
case "title":
store.updateTab(tab.id, { title: event.title });
page(tab.id).title = event.title;
- history.recordVisit(tab.displayUrl ?? currentEntryUrl(tab), event.title);
+ history.recordVisit(tab.displayUrl ?? currentEntryUrl(tab), event.title, temporary);
break;
case "url":
store.updateTab(tab.id, { displayUrl: event.url, ...leftOpenedPage(tab, event.url) });
@@ -232,15 +271,9 @@ function onDownload(event: Extract<NativeEvent, { kind: "download" }>): void {
// Refused before asking, it never ran: there's nothing to end, only a result to show.
const key = event.promptId ? downloadKey(event.promptId) : `native:${event.tabId}:${event.url}`;
if (!event.done) return;
- const historyId = event.success
- ? useBrowserHistoryStore.getState().recordDownload({
- name: event.name,
- url: event.url,
- size: event.size ?? 0,
- contentType: "",
- nativeId: event.downloadId ?? undefined,
- })
- : undefined;
+ const temporary = event.promptId ? temporaryDownloads.delete(event.promptId) : false;
+ const item = { name: event.name, url: event.url, size: event.size ?? 0, contentType: "", nativeId: event.downloadId ?? undefined };
+ const historyId = event.success ? useBrowserHistoryStore.getState().recordDownload(item, temporary) : undefined;
const shown = finishDownload(key, {
name: event.name,
size: event.size ?? 0,
@@ -576,6 +609,9 @@ onNativeViewsClosed(() => {
zooms.clear();
icons.clear();
pages.clear();
+ temporaryPages.clear();
+ pageEntries.clear();
+ loadingPages.clear();
resume.clear();
recency = [];
epoch += 1;
diff --git a/studio/frontend/src/features/browser/store.ts b/studio/frontend/src/features/browser/store.ts
index e39460d0940..61a0bc165f8 100644
--- a/studio/frontend/src/features/browser/store.ts
+++ b/studio/frontend/src/features/browser/store.ts
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-import type { DocumentAnnotations } from "@/features/chat";
+import { type DocumentAnnotations, useChatRuntimeStore } from "@/features/chat";
import { create } from "zustand";
import { unwrapRedirect } from "./address";
import type { BrowserPage } from "./api";
@@ -18,6 +18,8 @@ export type BrowserEntry =
body?: string;
/** source page for link, form, script, or refresh; files reached here download on its behalf. */
from?: string;
+ /** Opened beside a temporary chat, so it stays out of history. */
+ temporary?: true;
}
| {
kind: "file";
@@ -208,9 +210,10 @@ export function currentEntry(tab: BrowserTab): BrowserEntry {
return tab.history[tab.index] ?? { kind: "newtab" };
}
-function webEntry(url: string, method?: "GET" | "POST", body?: string, from?: string): BrowserEntry {
- const entry: BrowserEntry =
+function webEntry(url: string, method?: "GET" | "POST", body?: string, from?: string, temporary?: boolean): BrowserEntry {
+ const entry: Extract<BrowserEntry, { kind: "web" }> =
method === "POST" ? { kind: "web", url, method, body } : { kind: "web", url: unwrapRedirect(url) };
+ if (temporary ?? useChatRuntimeStore.getState().incognito) entry.temporary = true;
return from ? { ...entry, from } : entry;
}
@@ -296,7 +299,7 @@ type BrowserState = {
openFile: (input: OpenFileInput) => void;
navigate: (
tabId: string,
- request: { url: string; method?: "GET" | "POST"; body?: string; from?: string },
+ request: { url: string; method?: "GET" | "POST"; body?: string; from?: string; temporary?: boolean },
options?: { replace?: boolean },
) => void;
/** removes a page-sent download from history and returns to its sending page unless the tab moved on. */
@@ -553,7 +556,7 @@ export const useBrowserStore = create<BrowserState>((set, get) => {
set((state) => ({
tabs: patchTab(state.tabs, tabId, (tab) => {
const replace = options?.replace ?? (nativeWebHistory && currentEntry(tab).kind === "web");
- const entry = webEntry(request.url, request.method, request.body, request.from);
+ const entry = webEntry(request.url, request.method, request.body, request.from, request.temporary);
if (request.from && !replace) sentFrom.set(entry, currentEntry(tab));
return pushEntry(tab, entry, replace);
}),
diff --git a/studio/frontend/src/features/browser/tab-view.tsx b/studio/frontend/src/features/browser/tab-view.tsx
index 45157524777..8a49b1b4532 100644
--- a/studio/frontend/src/features/browser/tab-view.tsx
+++ b/studio/frontend/src/features/browser/tab-view.tsx
@@ -2,6 +2,7 @@
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
import { Button } from "@/components/ui/button";
+import { useChatRuntimeStore } from "@/features/chat";
import { requestFind } from "@/features/find-in-page";
import { zoomScopeFromChord } from "@/features/interface-zoom";
import { useT } from "@/i18n";
@@ -70,6 +71,13 @@ function pageAddress(tab: BrowserTab | undefined): string | undefined {
return tab && entry?.kind === "web" ? (tab.displayUrl ?? entry.url) : undefined;
}
+// Per tab, whether its current load began beside a temporary chat: a reload keeps its entry.
+const temporaryLoads = new Map<string, boolean>();
+
+function loadTemporary(tabId: string, entry: BrowserEntry): boolean {
+ return (entry.kind === "web" && entry.temporary === true) || temporaryLoads.get(tabId) === true;
+}
+
function useFrameMessages(tabId: string, origin: string | null) {
const t = useT();
return useCallback(
@@ -102,7 +110,7 @@ function useFrameMessages(tabId: string, origin: string | null) {
const favicon = safeFavicon(message.favicon);
// Kept by site, so Recents, History and Suggested show it once the tab is gone.
if (favicon && tab && entry?.kind === "web") {
- useBrowserHistoryStore.getState().recordIcon(hostOf(tab.displayUrl ?? entry.url), favicon);
+ useBrowserHistoryStore.getState().recordIcon(hostOf(tab.displayUrl ?? entry.url), favicon, loadTemporary(tabId, entry));
}
if (favicon && entry) {
void proxiedFavicon(favicon).then((icon) => {
@@ -112,7 +120,7 @@ function useFrameMessages(tabId: string, origin: string | null) {
}
// POST results can't be revisited, so they stay out of history.
if (tab && entry?.kind === "web" && entry.method !== "POST") {
- useBrowserHistoryStore.getState().recordVisit(tab.displayUrl ?? entry.url, message.title);
+ useBrowserHistoryStore.getState().recordVisit(tab.displayUrl ?? entry.url, message.title, loadTemporary(tabId, entry));
}
break;
}
@@ -247,6 +255,7 @@ function WebPage({
const reload = useBrowserStore((store) => store.reload);
useEffect(() => {
+ temporaryLoads.set(tab.id, entry.temporary === true || useChatRuntimeStore.getState().incognito);
const show = (page: BrowserPage) => {
if (page.kind === "raw") {
const name = page.fileName ?? fileNameFromUrl(page.url);
@@ -259,7 +268,7 @@ function WebPage({
documentType: page.contentType,
pageError: false,
});
- if (method !== "POST") useBrowserHistoryStore.getState().recordVisit(page.url, name);
+ if (method !== "POST") useBrowserHistoryStore.getState().recordVisit(page.url, name, loadTemporary(tab.id, entry));
} else {
fitZoomToPage(tab.id, false);
updateTab(tab.id, {
@@ -294,7 +303,7 @@ function WebPage({
const name = page.fileName ?? fileNameFromUrl(page.url);
if (!canShowFile(name, page.contentType)) {
// use the sender or requested address, not the redirect target, so another site's permission cannot apply.
- void saveBrowserDownload({ blob: page.blob, name, contentType: page.contentType, url: page.url, site: entry.from ?? url });
+ void saveBrowserDownload({ blob: page.blob, name, contentType: page.contentType, url: page.url, site: entry.from ?? url, temporary: loadTemporary(tab.id, entry) || undefined });
if (entry.kind === "web" && entry.from) useBrowserStore.getState().leaveDownload(tab.id, entry);
}
}
diff --git a/studio/frontend/tests/browser-native-view-snapshot.test.ts b/studio/frontend/tests/browser-native-view-snapshot.test.ts
index fa795f75668..32429bf4637 100644
--- a/studio/frontend/tests/browser-native-view-snapshot.test.ts
+++ b/studio/frontend/tests/browser-native-view-snapshot.test.ts
@@ -96,7 +96,7 @@ let captureDone: ((bytes: ArrayBuffer) => void) | null = null;
register("./helpers/browser-store-resolver.mjs", import.meta.url);
register("./helpers/native-view-resolver.mjs", import.meta.url);
-const { useBrowserStore } = await import("../src/features/browser/store.ts");
+const { currentEntry, useBrowserStore } = await import("../src/features/browser/store.ts");
const { startNativeViews } = await import(
"../src/features/browser/native-view.ts"
);
@@ -376,3 +376,168 @@ test("with a Downloads button on screen, a download shows there, not as a toast"
stop();
}
});
+
+test("a native page and its downloads begun beside a temporary chat stay temporary when they land after it", async () => {
+ const { useChatRuntimeStore } = await import("@/features/chat");
+ const stop = startNativeViews();
+ const g = globalThis as {
+ nativeViewListener?: (event: { payload: unknown }) => void;
+ nativeViewSeen?: unknown;
+ nativeViewVisits?: unknown;
+ nativeViewApprove?: boolean;
+ };
+ try {
+ useBrowserStore.getState().openUrl("https://example.org/", { newTab: true });
+ await frame();
+ const tabId = useBrowserStore.getState().activeTabId as string;
+ const visits: { url: string; temporary: boolean }[] = [];
+ const seen: { level: string; message: string; temporary?: boolean }[] = [];
+ g.nativeViewVisits = visits;
+ g.nativeViewSeen = seen;
+ g.nativeViewApprove = true;
+ const load = (url: string, loading: boolean) =>
+ g.nativeViewListener?.({ payload: { kind: "load", tabId, url, loading } });
+ const url = "https://example.org/a.zip";
+ useChatRuntimeStore.getState().setIncognito(true);
+ load("https://example.org/next", true);
+ g.nativeViewListener?.({ payload: { kind: "downloadPrompt", tabId, url, site: "", name: "a.zip", id: "p1" } });
+ g.nativeViewListener?.({ payload: { kind: "downloadPrompt", tabId, url, site: "", name: "a.zip", id: "p2" } });
+ await settle();
+ useChatRuntimeStore.getState().setIncognito(false);
+ load("https://example.org/next", false);
+ const done = { kind: "download", tabId, url, name: "a.zip", path: null, size: 3, done: true, success: true, marked: true };
+ g.nativeViewListener?.({ payload: { ...done, downloadId: "d1", promptId: "p1" } });
+ g.nativeViewListener?.({ payload: { ...done, downloadId: "d2", promptId: "p2" } });
+ g.nativeViewListener?.({ payload: { ...done, downloadId: "d3", promptId: null } });
+ load("https://example.org/later", true);
+ load("https://example.org/later", false);
+ assert.deepEqual(visits, [
+ { url: "https://example.org/next", temporary: true },
+ { url: "https://example.org/later", temporary: false },
+ ]);
+ assert.deepEqual(
+ seen.filter((item) => item.level === "history"),
+ [
+ { level: "history", message: "d1", temporary: true },
+ { level: "history", message: "d2", temporary: true },
+ { level: "history", message: "d3" },
+ ],
+ );
+ } finally {
+ useChatRuntimeStore.getState().setIncognito(false);
+ delete g.nativeViewApprove;
+ stop();
+ }
+});
+
+test("a native page begun beside a normal chat is kept in history though its tab opened beside a temporary chat", async () => {
+ const { useChatRuntimeStore } = await import("@/features/chat");
+ const stop = startNativeViews();
+ const g = globalThis as { nativeViewListener?: (event: { payload: unknown }) => void; nativeViewVisits?: unknown };
+ try {
+ useChatRuntimeStore.getState().setIncognito(true);
+ useBrowserStore.getState().openUrl("https://example.net/", { newTab: true });
+ useChatRuntimeStore.getState().setIncognito(false);
+ await frame();
+ const tabId = useBrowserStore.getState().activeTabId as string;
+ const visits: { url: string; temporary: boolean }[] = [];
+ g.nativeViewVisits = visits;
+ const load = (url: string, loading: boolean) =>
+ g.nativeViewListener?.({ payload: { kind: "load", tabId, url, loading } });
+ // The view's first page is the entry's, even when it starts loading after the chat turned normal.
+ load("https://example.net/", true);
+ load("https://example.net/", false);
+ load("https://example.net/next", true);
+ load("https://example.net/next", false);
+ assert.deepEqual(visits, [
+ { url: "https://example.net/", temporary: true },
+ { url: "https://example.net/next", temporary: false },
+ ]);
+ const seen: { level: string; message: string; temporary?: boolean }[] = [];
+ (globalThis as { nativeViewSeen?: unknown }).nativeViewSeen = seen;
+ (globalThis as { nativeViewApprove?: boolean }).nativeViewApprove = true;
+ const url = "https://example.net/b.zip";
+ g.nativeViewListener?.({ payload: { kind: "downloadPrompt", tabId, url, site: "", name: "b.zip", id: "p3" } });
+ await settle();
+ g.nativeViewListener?.({
+ payload: { kind: "download", tabId, url, name: "b.zip", path: null, size: 3, done: true, success: true, marked: true, downloadId: "d5", promptId: "p3" },
+ });
+ assert.deepEqual(seen.filter((item) => item.level === "history"), [{ level: "history", message: "d5" }]);
+ } finally {
+ useChatRuntimeStore.getState().setIncognito(false);
+ delete (globalThis as { nativeViewApprove?: boolean }).nativeViewApprove;
+ stop();
+ }
+});
+
+test("a native page begun beside a temporary chat keeps it through a redirect and a clear", async () => {
+ const { useChatRuntimeStore } = await import("@/features/chat");
+ const stop = startNativeViews();
+ const g = globalThis as {
+ nativeViewListener?: (event: { payload: unknown }) => void;
+ nativeViewVisits?: unknown;
+ nativeViewsClosed?: () => void;
+ };
+ try {
+ useBrowserStore.getState().openUrl("https://example.edu/", { newTab: true });
+ await frame();
+ const tabId = useBrowserStore.getState().activeTabId as string;
+ const visits: { url: string; temporary: boolean }[] = [];
+ g.nativeViewVisits = visits;
+ const load = (url: string, loading: boolean) =>
+ g.nativeViewListener?.({ payload: { kind: "load", tabId, url, loading } });
+ load("https://example.edu/", true);
+ load("https://example.edu/", false);
+ useChatRuntimeStore.getState().setIncognito(true);
+ load("https://example.edu/go", true);
+ useChatRuntimeStore.getState().setIncognito(false);
+ // The redirect starts again inside the same navigation.
+ load("https://example.edu/landed", true);
+ load("https://example.edu/landed", false);
+ assert.deepEqual(visits.at(-1), { url: "https://example.edu/landed", temporary: true });
+ useChatRuntimeStore.getState().setIncognito(true);
+ load("https://example.edu/private", true);
+ load("https://example.edu/private", false);
+ useChatRuntimeStore.getState().setIncognito(false);
+ g.nativeViewsClosed?.();
+ await frame();
+ const tab = useBrowserStore.getState().tabs.find((item) => item.id === tabId)!;
+ const reached = currentEntry(tab);
+ assert.ok(reached.kind === "web" && reached.temporary === true);
+ load("https://example.edu/private", true);
+ load("https://example.edu/private", false);
+ assert.deepEqual(visits.at(-1), { url: "https://example.edu/private", temporary: true });
+ } finally {
+ useChatRuntimeStore.getState().setIncognito(false);
+ stop();
+ }
+});
+
+test("a new address asked for beside a temporary chat stays temporary when its native load starts after it", async () => {
+ const { useChatRuntimeStore } = await import("@/features/chat");
+ const stop = startNativeViews();
+ const g = globalThis as { nativeViewListener?: (event: { payload: unknown }) => void; nativeViewVisits?: unknown };
+ try {
+ useBrowserStore.getState().openUrl("https://example.info/", { newTab: true });
+ await frame();
+ const tabId = useBrowserStore.getState().activeTabId as string;
+ const visits: { url: string; temporary: boolean }[] = [];
+ g.nativeViewVisits = visits;
+ const load = (url: string, loading: boolean) =>
+ g.nativeViewListener?.({ payload: { kind: "load", tabId, url, loading } });
+ load("https://example.info/", true);
+ load("https://example.info/", false);
+ useChatRuntimeStore.getState().setIncognito(true);
+ useBrowserStore.getState().navigate(tabId, { url: "https://example.info/private" });
+ useChatRuntimeStore.getState().setIncognito(false);
+ load("https://example.info/private", true);
+ load("https://example.info/private", false);
+ assert.deepEqual(visits, [
+ { url: "https://example.info/", temporary: false },
+ { url: "https://example.info/private", temporary: true },
+ ]);
+ } finally {
+ useChatRuntimeStore.getState().setIncognito(false);
+ stop();
+ }
+});
diff --git a/studio/frontend/tests/browser-settings.test.ts b/studio/frontend/tests/browser-settings.test.ts
index 28691b6803f..73e9f35f5f0 100644
--- a/studio/frontend/tests/browser-settings.test.ts
+++ b/studio/frontend/tests/browser-settings.test.ts
@@ -25,6 +25,8 @@ register("./helpers/browser-store-resolver.mjs", import.meta.url);
const { useBrowserHistoryStore } = await import("../src/features/browser/history-store.ts");
const { useBrowserPrefsStore } = await import("../src/features/browser/prefs-store.ts");
const { useBrowserBookmarksStore } = await import("../src/features/browser/bookmarks-store.ts");
+const { useChatRuntimeStore } = await import("@/features/chat");
+const { currentEntry, useBrowserStore } = await import("../src/features/browser/store.ts");
const download = { name: "file.pdf", url: "https://example.com/file.pdf", size: 10, contentType: "application/pdf" };
@@ -39,6 +41,37 @@ test("with history saving off, visits are not recorded; turned back on, they are
assert.equal(useBrowserHistoryStore.getState().history.length, 1);
});
+test("pages visited beside a temporary chat stay out of history, icons included", () => {
+ const history = useBrowserHistoryStore.getState();
+ history.clearHistory();
+ useChatRuntimeStore.getState().setIncognito(true);
+ history.recordIcon("example.com", "https://example.com/icon.png");
+ history.recordVisit("https://example.com/", "Example");
+ assert.deepEqual(useBrowserHistoryStore.getState().history, []);
+ assert.deepEqual(useBrowserHistoryStore.getState().icons, {});
+ useChatRuntimeStore.getState().setIncognito(false);
+ history.recordVisit("https://example.com/", "Example");
+ assert.equal(useBrowserHistoryStore.getState().history.length, 1);
+});
+
+test("a page opened beside a temporary chat stays out of history when it loads after the chat turns normal", () => {
+ const history = useBrowserHistoryStore.getState();
+ history.clearHistory();
+ useChatRuntimeStore.getState().setIncognito(true);
+ useBrowserStore.getState().openUrl("https://example.com/", { newTab: true });
+ const tab = useBrowserStore.getState().tabs.find((item) => item.id === useBrowserStore.getState().activeTabId);
+ const entry = tab ? currentEntry(tab) : null;
+ useChatRuntimeStore.getState().setIncognito(false);
+ assert.equal(entry?.kind === "web" && entry.temporary, true);
+ history.recordVisit("https://example.com/", "Example", entry?.kind === "web" ? entry.temporary : false);
+ assert.deepEqual(useBrowserHistoryStore.getState().history, []);
+ useBrowserStore.getState().openUrl("https://example.org/", { newTab: true });
+ const next = useBrowserStore.getState().tabs.find((item) => item.id === useBrowserStore.getState().activeTabId);
+ const nextEntry = next ? currentEntry(next) : null;
+ history.recordVisit("https://example.org/", "Example", nextEntry?.kind === "web" ? nextEntry.temporary : false);
+ assert.equal(useBrowserHistoryStore.getState().history.length, 1);
+});
+
test("with download history off, downloads are not listed", () => {
const history = useBrowserHistoryStore.getState();
history.clearDownloads();
@@ -51,6 +84,140 @@ test("with download history off, downloads are not listed", () => {
assert.equal(useBrowserHistoryStore.getState().downloads[0].id, id);
});
+test("a navigation asked for as temporary stays temporary in a normal chat", () => {
+ const store = useBrowserStore.getState();
+ store.openUrl("https://example.com/", { newTab: true });
+ const tabId = useBrowserStore.getState().activeTabId!;
+ store.navigate(tabId, { url: "https://example.com/reached", temporary: true });
+ const entry = currentEntry(useBrowserStore.getState().tabs.find((item) => item.id === tabId)!);
+ assert.equal(entry.kind === "web" && entry.temporary, true);
+ store.navigate(tabId, { url: "https://example.com/after" });
+ const after = currentEntry(useBrowserStore.getState().tabs.find((item) => item.id === tabId)!);
+ assert.equal(after.kind === "web" && after.temporary, undefined);
+ // A page noted as normal stays normal when it is kept during a temporary chat.
+ useChatRuntimeStore.getState().setIncognito(true);
+ store.navigate(tabId, { url: "https://example.com/kept", temporary: false });
+ useChatRuntimeStore.getState().setIncognito(false);
+ const kept = currentEntry(useBrowserStore.getState().tabs.find((item) => item.id === tabId)!);
+ assert.equal(kept.kind === "web" && kept.temporary, undefined);
+ store.closeTab(tabId);
+});
+
+test("files downloaded beside a temporary chat are not listed", () => {
+ const history = useBrowserHistoryStore.getState();
+ history.clearDownloads();
+ useChatRuntimeStore.getState().setIncognito(true);
+ history.recordDownload(download);
+ assert.deepEqual(useBrowserHistoryStore.getState().downloads, []);
+ useChatRuntimeStore.getState().setIncognito(false);
+ history.recordDownload(download);
+ assert.equal(useBrowserHistoryStore.getState().downloads.length, 1);
+});
+
+test("a download begun beside a temporary chat stays unlisted when it is saved after the chat turns normal", async () => {
+ const { saveBrowserDownload } = await import("../src/features/browser/downloads.ts");
+ const history = useBrowserHistoryStore.getState();
+ history.clearDownloads();
+ const prefs = useBrowserPrefsStore.getState();
+ prefs.setAskWhereToSave(true);
+ prefs.setAskBeforeDownloading(false);
+ const g = globalThis as { showSaveFilePicker?: unknown; __toasts?: { options?: { action?: { onClick: () => void } } }[] };
+ const written: Blob[] = [];
+ g.showSaveFilePicker = async ({ suggestedName }: { suggestedName: string }) => ({
+ name: suggestedName,
+ createWritable: async () => ({ write: async (data: Blob) => void written.push(data), close: async () => {} }),
+ });
+ Object.defineProperty(globalThis, "navigator", { value: { userActivation: { isActive: false } }, configurable: true });
+ g.__toasts = [];
+ try {
+ useChatRuntimeStore.getState().setIncognito(true);
+ await saveBrowserDownload({ blob: new Blob(["x"]), name: "late.zip", contentType: "application/zip", url: "https://a.example/late.zip" });
+ useChatRuntimeStore.getState().setIncognito(false);
+ g.__toasts.at(-1)!.options!.action!.onClick();
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ assert.equal(written.length, 1);
+ assert.deepEqual(useBrowserHistoryStore.getState().downloads, []);
+ } finally {
+ useChatRuntimeStore.getState().setIncognito(false);
+ prefs.setAskWhereToSave(false);
+ prefs.setAskBeforeDownloading(true);
+ delete g.showSaveFilePicker;
+ }
+});
+
+test("a file a temporary chat's page fetched stays unlisted when it is saved after the chat turns normal", async () => {
+ const { saveBrowserDownload } = await import("../src/features/browser/downloads.ts");
+ useBrowserHistoryStore.getState().clearDownloads();
+ const written: Blob[] = [];
+ const target = {
+ name: "late.bin",
+ createWritable: async () => ({ write: async (data: Blob) => void written.push(data), close: async () => {} }),
+ };
+ const download = { blob: new Blob(["x"]), name: "late.bin", contentType: "application/octet-stream", url: "https://a.example/late.bin" };
+ await saveBrowserDownload({ ...download, temporary: true }, target);
+ assert.equal(written.length, 1);
+ assert.deepEqual(useBrowserHistoryStore.getState().downloads, []);
+ await saveBrowserDownload(download, target);
+ assert.equal(useBrowserHistoryStore.getState().downloads.length, 1);
+ // Taken as normal before a temporary chat was shown: still listed.
+ useChatRuntimeStore.getState().setIncognito(true);
+ try {
+ await saveBrowserDownload({ ...download, temporary: false }, target);
+ } finally {
+ useChatRuntimeStore.getState().setIncognito(false);
+ }
+ assert.equal(useBrowserHistoryStore.getState().downloads.length, 2);
+});
+
+test("Save link as from a temporary chat stays unlisted when its fetch lands after the chat turns normal", async () => {
+ const { saveLinkAs } = await import("../src/features/browser/downloads.ts");
+ useBrowserHistoryStore.getState().clearDownloads();
+ const prefs = useBrowserPrefsStore.getState();
+ prefs.setAskWhereToSave(true);
+ prefs.setAskBeforeDownloading(false);
+ const g = globalThis as { showSaveFilePicker?: unknown; __authFetch?: unknown };
+ const written: Blob[] = [];
+ g.showSaveFilePicker = async ({ suggestedName }: { suggestedName: string }) => ({
+ name: suggestedName,
+ createWritable: async () => ({ write: async (data: Blob) => void written.push(data), close: async () => {} }),
+ });
+ g.__authFetch = () =>
+ new Promise((resolve) =>
+ setTimeout(
+ () =>
+ resolve(
+ new Response(new Blob(["x"]), {
+ headers: { "Content-Type": "application/zip", "X-Unsloth-Browser-Filename": "data.zip" },
+ }),
+ ),
+ 50,
+ ),
+ );
+ try {
+ useChatRuntimeStore.getState().setIncognito(true);
+ const saving = saveLinkAs("https://a.example/data.zip");
+ useChatRuntimeStore.getState().setIncognito(false);
+ await saving;
+ assert.equal(written.length, 1);
+ assert.deepEqual(useBrowserHistoryStore.getState().downloads, []);
+ } finally {
+ useChatRuntimeStore.getState().setIncognito(false);
+ prefs.setAskWhereToSave(false);
+ prefs.setAskBeforeDownloading(true);
+ delete g.showSaveFilePicker;
+ delete g.__authFetch;
+ }
+});
+
+test("a download begun beside a normal chat is listed though it lands while a temporary chat is shown", () => {
+ const history = useBrowserHistoryStore.getState();
+ history.clearDownloads();
+ useChatRuntimeStore.getState().setIncognito(true);
+ history.recordDownload(download, false);
+ useChatRuntimeStore.getState().setIncognito(false);
+ assert.equal(useBrowserHistoryStore.getState().downloads.length, 1);
+});
+
test("shortening how long history is kept drops older visits at once", () => {
const now = Date.now();
useBrowserPrefsStore.getState().setHistoryRetentionDays(0);
diff --git a/studio/frontend/tests/helpers/browser-store-resolver.mjs b/studio/frontend/tests/helpers/browser-store-resolver.mjs
index 613bb6c1cfe..5dda4050896 100644
--- a/studio/frontend/tests/helpers/browser-store-resolver.mjs
+++ b/studio/frontend/tests/helpers/browser-store-resolver.mjs
@@ -1,10 +1,14 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-// The browser store only needs the chat feature to close its artifact surface; stub that.
+// The browser stores only need the chat feature to close its artifact surface and to see a temporary chat; stub those.
const CHAT_STUB =
"data:text/javascript," +
- encodeURIComponent("export const useChatArtifactsStore = { getState: () => ({ closeArtifactSurface() {} }) };");
+ encodeURIComponent(
+ "export const useChatArtifactsStore = { getState: () => ({ closeArtifactSurface() {} }) };" +
+ " const runtime = { incognito: false, setIncognito: (incognito) => void (runtime.incognito = incognito) };" +
+ " export const useChatRuntimeStore = { getState: () => runtime };",
+ );
const I18N_STUB =
"data:text/javascript," +
diff --git a/studio/frontend/tests/helpers/native-view-resolver.mjs b/studio/frontend/tests/helpers/native-view-resolver.mjs
index 59fb9a696d7..cbea62d30b6 100644
--- a/studio/frontend/tests/helpers/native-view-resolver.mjs
+++ b/studio/frontend/tests/helpers/native-view-resolver.mjs
@@ -2,7 +2,7 @@
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
// register after browser-store-resolver.mjs and route Tauri calls through globalThis.nativeViewCall;
-// events reach globalThis.nativeViewListener, toasts and recorded downloads land in globalThis.nativeViewSeen
+// events reach globalThis.nativeViewListener, toasts and recorded downloads land in globalThis.nativeViewSeen, visits in globalThis.nativeViewVisits
const stub = (source) => `data:text/javascript,${encodeURIComponent(source)}`;
const STUBS = {
@@ -21,7 +21,7 @@ const STUBS = {
export const useNativeBrowser = { getState: () => ({ enabled: true }) };
export const callNative = (command, args) => globalThis.nativeViewCall(command, args);
export const nativeClearing = () => false;
- export const onNativeViewsClosed = () => () => {};
+ export const onNativeViewsClosed = (callback) => { globalThis.nativeViewsClosed = callback; return () => {}; };
export const clearNativeBrowsingData = async () => {};
`),
"./favicon": stub("export const proxiedFavicon = async () => null;"),
@@ -45,8 +45,10 @@ const STUBS = {
" export const downloadSiteOf = () => '';",
),
"./history-store": stub(
- "export const useBrowserHistoryStore = { getState: () => ({ recordVisit() {}," +
- " recordDownload: (item) => void (globalThis.nativeViewSeen ??= []).push({ level: 'history', message: item.nativeId }) }) };",
+ "const seen = (entry, temporary) => void (globalThis.nativeViewSeen ??= []).push(temporary ? { ...entry, temporary } : entry);" +
+ " export const useBrowserHistoryStore = { getState: () => ({" +
+ " recordVisit: (url, _title, temporary) => void (globalThis.nativeViewVisits ??= []).push({ url, temporary: Boolean(temporary) })," +
+ " recordDownload: (item, temporary) => seen({ level: 'history', message: item.nativeId }, temporary) }) };",
),
};