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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: let videos in the browser panel go full screen (#13759)
Nilaycd947468f18f
diff --git a/studio/backend/routes/browser.py b/studio/backend/routes/browser.pyindex b6dd7a96c42..5ed366f6c90 100644--- a/studio/backend/routes/browser.py+++ b/studio/backend/routes/browser.py@@ -747,6 +747,7 @@ _FRAME_HTML = r"""<!doctype html>const script = `<script>(${boot.toString()})(${JSON.stringify(cfg).replace(/</g, "\\u003c")});<\/script>`;page = document.createElement("iframe");page.setAttribute("sandbox", "allow-scripts allow-forms");+ page.setAttribute("allowfullscreen", "");page.srcdoc = inject(data.html, base + script);document.body.appendChild(page);// A script navigation the page's hooks missed (no Navigation API) hits the lock below; thediff --git a/studio/backend/tests/test_browser_routes.py b/studio/backend/tests/test_browser_routes.pyindex f30677837b5..c0b5fd72f90 100644--- a/studio/backend/tests/test_browser_routes.py+++ b/studio/backend/tests/test_browser_routes.py@@ -35,6 +35,14 @@ def test_the_shell_is_isolated():assert "X-Unsloth-Browser-Kind" in browser_mod.EXPOSED_HEADERS+def test_the_shells_page_may_go_fullscreen_and_nothing_more():+ shell = browser_mod._FRAME_HTML+ assert 'page.setAttribute("sandbox", "allow-scripts allow-forms");' in shell+ assert 'page.setAttribute("allowfullscreen", "");' in shell+ assert "allow-same-origin" not in shell+ assert 'setAttribute("allow",' not in shell and "page.allow" not in shell++def test_the_print_shell_runs_only_its_own_script():import base64import hashlibdiff --git a/studio/frontend/src/features/browser/page-frame.tsx b/studio/frontend/src/features/browser/page-frame.tsxindex 60913bb8b93..8f4bae0a931 100644--- a/studio/frontend/src/features/browser/page-frame.tsx+++ b/studio/frontend/src/features/browser/page-frame.tsx@@ -236,6 +236,7 @@ export function PageFrame({title={title}src={browserFrameUrl(loadId)}sandbox="allow-scripts allow-forms"+ allowFullScreenreferrerPolicy="no-referrer"className="size-full border-0 bg-white"onLoad={() => {diff --git a/studio/frontend/src/features/browser/tab-view.tsx b/studio/frontend/src/features/browser/tab-view.tsxindex 91542f825e4..cf68494fe70 100644--- a/studio/frontend/src/features/browser/tab-view.tsx+++ b/studio/frontend/src/features/browser/tab-view.tsx@@ -148,14 +148,21 @@ function useFrameMessages(tabId: string, origin: string | null) {});break;}- case "shortcut":- if (message.key === "l") store.focusAddress();- else if (message.key === "f") requestFind(BROWSER_FIND_TARGET);- else if (message.key === "t") store.newTab();- else if (message.key === "w") store.closeTab(tabId);- else if (message.key === "r") store.reload(tabId);- else if (message.key === "d") store.bookmarkPage();+ case "shortcut": {+ const { key } = message;+ const run = () => {+ if (key === "l") store.focusAddress();+ else if (key === "f") requestFind(BROWSER_FIND_TARGET);+ else if (key === "t") store.newTab();+ else if (key === "w") store.closeTab(tabId);+ else if (key === "r") store.reload(tabId);+ else if (key === "d") store.bookmarkPage();+ };+ // A full screen page covers the panel; leave it first so the shortcut's result shows.+ if (document.fullscreenElement) void document.exitFullscreen().catch(() => undefined).then(run);+ else run();break;+ }case "zoom":// A key goes through the scope, so the View menu repeating it doesn't zoom twice.if (message.wheel) zoomTab(tabId, message.direction);diff --git a/studio/frontend/src/hooks/use-mobile.ts b/studio/frontend/src/hooks/use-mobile.tsindex 15f5739e42f..c095bb0a988 100644--- a/studio/frontend/src/hooks/use-mobile.ts+++ b/studio/frontend/src/hooks/use-mobile.ts@@ -7,16 +7,24 @@ import { useSyncExternalStore } from "react";const MOBILE_BREAKPOINT = 768;const MEDIA_QUERY = `(max-width: ${MOBILE_BREAKPOINT - 1}px)`;-function getSnapshot(): boolean {+let lastMobile = false;++// Full screen resizes the viewport; swapping layouts then would unmount the full screen element.+export function isMobileViewport(): boolean {if (typeof window === "undefined") return false;- return window.matchMedia(MEDIA_QUERY).matches;+ if (!document.fullscreenElement) lastMobile = window.matchMedia(MEDIA_QUERY).matches;+ return lastMobile;}function subscribe(callback: () => void): () => void {if (typeof window === "undefined") return () => {};const mql = window.matchMedia(MEDIA_QUERY);mql.addEventListener("change", callback);- return () => mql.removeEventListener("change", callback);+ document.addEventListener("fullscreenchange", callback);+ return () => {+ mql.removeEventListener("change", callback);+ document.removeEventListener("fullscreenchange", callback);+ };}/**@@ -24,7 +32,7 @@ function subscribe(callback: () => void): () => void {* submenu or a settings panel that only has room to overlay has to overlay.*/export function useIsMobile(): boolean {- return useSyncExternalStore(subscribe, getSnapshot, () => false);+ return useSyncExternalStore(subscribe, isMobileViewport, () => false);}/**diff --git a/studio/frontend/tests/browser-page-frame-fullscreen.test.ts b/studio/frontend/tests/browser-page-frame-fullscreen.test.tsnew file mode 100644index 00000000000..d74ac9c19d2--- /dev/null+++ b/studio/frontend/tests/browser-page-frame-fullscreen.test.ts@@ -0,0 +1,50 @@+// 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 assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";+import { fileURLToPath } from "node:url";++import ts from "typescript";++import { openingTag } from "./helpers/tsx-ast.ts";++const PAGE_FRAME = "../src/features/browser/page-frame.tsx";++function iframeAttributes(): Map<string, string | null> {+ const path = fileURLToPath(new URL(PAGE_FRAME, import.meta.url));+ const source = ts.createSourceFile(+ path,+ readFileSync(path, "utf8"),+ ts.ScriptTarget.ESNext,+ true,+ ts.ScriptKind.TSX,+ );+ const tags: ts.JsxOpeningLikeElement[] = [];+ const visit = (node: ts.Node): void => {+ const opening = openingTag(node);+ if (opening?.tagName.getText() === "iframe") tags.push(opening);+ node.forEachChild(visit);+ };+ visit(source);+ assert.equal(tags.length, 1);+ const attributes = new Map<string, string | null>();+ for (const attribute of tags[0].attributes.properties) {+ if (!ts.isJsxAttribute(attribute)) continue;+ const value = attribute.initializer;+ attributes.set(+ attribute.name.getText(),+ value && ts.isStringLiteral(value) ? value.text : null,+ );+ }+ return attributes;+}++test("the panel's page frame may go fullscreen without leaving its sandbox", () => {+ const attributes = iframeAttributes();+ assert.ok(attributes.has("allowFullScreen"));+ assert.equal(attributes.get("allowFullScreen"), null);+ assert.equal(attributes.get("sandbox"), "allow-scripts allow-forms");+ assert.ok(!attributes.has("allow"));+});diff --git a/studio/frontend/tests/browser-shortcut-leaves-fullscreen.test.ts b/studio/frontend/tests/browser-shortcut-leaves-fullscreen.test.tsnew file mode 100644index 00000000000..b9a1f7c4f29--- /dev/null+++ b/studio/frontend/tests/browser-shortcut-leaves-fullscreen.test.ts@@ -0,0 +1,35 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// A page in the browser panel relays Cmd/Ctrl+F, L, D, ... to the panel. While the page was full+// screen, the find bar or address bar opened under it, out of sight.++import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";+import { fileURLToPath } from "node:url";++import ts from "typescript";++const TAB_VIEW = fileURLToPath(new URL("../src/features/browser/tab-view.tsx", import.meta.url));++function shortcutCase(): string {+ const source = ts.createSourceFile(TAB_VIEW, readFileSync(TAB_VIEW, "utf8"), ts.ScriptTarget.ESNext, true, ts.ScriptKind.TSX);+ let found: string | null = null;+ const visit = (node: ts.Node): void => {+ if (ts.isCaseClause(node) && ts.isStringLiteral(node.expression) && node.expression.text === "shortcut") found = node.getText();+ node.forEachChild(visit);+ };+ visit(source);+ assert.ok(found, "the frame message switch has a shortcut case");+ return found;+}++test("a relayed shortcut leaves full screen before acting, and acts at once otherwise", () => {+ const clause = shortcutCase();+ assert.match(clause, /if \(document\.fullscreenElement\) void document\.exitFullscreen\(\)\.catch\(\(\) => undefined\)\.then\(run\);\s*else run\(\);/);+ for (const action of ["store.focusAddress()", "requestFind(BROWSER_FIND_TARGET)", "store.bookmarkPage()", "store.newTab()"]) {+ const at = clause.indexOf(action);+ assert.ok(at > clause.indexOf("const run = () =>") && at < clause.indexOf("document.exitFullscreen()"), `${action} runs inside run()`);+ }+});diff --git a/studio/frontend/tests/mobile-layout-holds-in-fullscreen.test.ts b/studio/frontend/tests/mobile-layout-holds-in-fullscreen.test.tsnew file mode 100644index 00000000000..497cc4e7996--- /dev/null+++ b/studio/frontend/tests/mobile-layout-holds-in-fullscreen.test.ts@@ -0,0 +1,40 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// A page in the narrow browser overlay going full screen widens the viewport past the mobile+// breakpoint; swapping to the side panel then unmounted the full screen frame and reloaded it.++import assert from "node:assert/strict";+import test from "node:test";++import { registerBundlerResolver } from "./helpers/kit.ts";++registerBundlerResolver();++let width = 700;+const doc: { fullscreenElement: object | null } = { fullscreenElement: null };+Object.assign(globalThis, {+ document: doc,+ window: {+ location: { protocol: "http:" },+ matchMedia: (query: string) => ({+ matches: width <= Number(/max-width: (\d+)px/.exec(query)?.[1]),+ addEventListener: () => undefined,+ removeEventListener: () => undefined,+ }),+ },+});++const { isMobileViewport } = await import("../src/hooks/use-mobile.ts");++test("the mobile layout holds while something is full screen and follows the viewport after", () => {+ assert.equal(isMobileViewport(), true);+ doc.fullscreenElement = {};+ width = 1512;+ assert.equal(isMobileViewport(), true);+ doc.fullscreenElement = null;+ width = 700;+ assert.equal(isMobileViewport(), true);+ width = 1440;+ assert.equal(isMobileViewport(), false);+});