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.

fix(studio): allow browser page clipboard writes (#14284)

Nilaybfbe28c5fe1b
diff --git a/studio/backend/routes/browser.py b/studio/backend/routes/browser.py
index 8a71dbe3af3..72d4a9c0b60 100644
--- a/studio/backend/routes/browser.py
+++ b/studio/backend/routes/browser.py
@@ -976,6 +976,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("allow", "clipboard-write");
page.setAttribute("allowfullscreen", "");
page.srcdoc = inject(data.html, base + script);
document.body.appendChild(page);
diff --git a/studio/backend/tests/test_browser_routes.py b/studio/backend/tests/test_browser_routes.py
index 4085a13fbe7..2ee61f19a74 100644
--- a/studio/backend/tests/test_browser_routes.py
+++ b/studio/backend/tests/test_browser_routes.py
@@ -35,12 +35,18 @@ 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():
+def test_the_shells_page_may_go_fullscreen_without_leaving_its_sandbox():
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_shells_page_may_copy_to_the_clipboard_but_not_read_it():
+ shell = browser_mod._FRAME_HTML
+ assert 'page.setAttribute("allow", "clipboard-write");' in shell
+ assert shell.count('setAttribute("allow",') == 1 and "page.allow" not in shell
+ assert "clipboard-read" not in shell
def test_the_print_shell_runs_only_its_own_script():
diff --git a/studio/frontend/src/features/browser/page-frame.tsx b/studio/frontend/src/features/browser/page-frame.tsx
index 20741ae26ff..262b56406f7 100644
--- a/studio/frontend/src/features/browser/page-frame.tsx
+++ b/studio/frontend/src/features/browser/page-frame.tsx
@@ -291,6 +291,7 @@ export function PageFrame({
title={title}
src={browserFrameUrl(loadId)}
sandbox="allow-scripts allow-forms"
+ allow="clipboard-write"
allowFullScreen
referrerPolicy="no-referrer"
className="size-full border-0 bg-white"
diff --git a/studio/frontend/tests/browser-page-frame-fullscreen.test.ts b/studio/frontend/tests/browser-page-frame-fullscreen.test.ts
index 9b6264b658b..46ba5692882 100644
--- a/studio/frontend/tests/browser-page-frame-fullscreen.test.ts
+++ b/studio/frontend/tests/browser-page-frame-fullscreen.test.ts
@@ -35,7 +35,7 @@ function iframeAttributes(): Map<string, string | null> {
const value = attribute.initializer;
attributes.set(
attribute.name.getText(),
- value && ts.isStringLiteral(value) ? value.text : null,
+ value ? (ts.isStringLiteral(value) ? value.text : value.getText()) : null,
);
}
return attributes;
@@ -46,5 +46,8 @@ test("the panel's page frame may go fullscreen without leaving its sandbox", ()
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"));
+});
+
+test("pages in the panel may copy to the clipboard but not read it", () => {
+ assert.equal(iframeAttributes().get("allow"), "clipboard-write");
});