@devries-cameron20 / t3code-1 / commits / e52bdf430b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(client): MCP apps can no longer trap you in full screen; it opens only after a tap (#18548)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

shivam committed Oct 19, 2026 at 23:36 UTC e52bdf430b1d76d749ca63860e0e6459fca601f9
4 files changed +227 -4
apps/mobile/src/features/threads/McpAppWebView.tsx
+9 -2
@@ -47,6 +47,7 @@ const ROW_BOTTOM_MARGIN = 8;
47 // Android exposes `ReactNativeWebView` to every frame, so a frame nested in the
48 // app could post to React Native directly. The outer page therefore wraps what
49 // it relays with a secret only it holds, and React Native drops anything else.
50 +// The relay also attests activation; the sandboxed app cannot set that flag.
51 function outerDocument(src: string, allow: string, secret: string) {
52 const attribute = (value: string) =>
53 value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
@@ -54,7 +55,7 @@ function outerDocument(src: string, allow: string, secret: string) {
55 <style>html,body{margin:0;height:100%;background:transparent}iframe{border:0;display:block;width:100%;height:100%}</style></head>
56 <body><iframe id="app" sandbox="allow-scripts allow-forms" allow="${attribute(allow)}"></iframe>
57 <script>(function(){var frame=document.getElementById("app"),secret=${JSON.stringify(secret)},loads=0,live=true;
57 -var send=function(m){window.ReactNativeWebView.postMessage(JSON.stringify({secret:secret,message:m}));};
58 +var send=function(m){var u=navigator.userActivation;window.ReactNativeWebView.postMessage(JSON.stringify({secret:secret,active:!!(u&&u.isActive)&&document.activeElement===frame,message:m}));};
59 frame.addEventListener("load",function(){loads+=1;if(loads>1&&live){live=false;send({t3:"navigated"});}});
60 window.addEventListener("message",function(e){if(live&&e.source===frame.contentWindow)send(e.data);});
61 window.__t3McpAppReceive=function(m){live&&frame.contentWindow&&frame.contentWindow.postMessage(m,"*");};
@@ -248,6 +249,7 @@ export function ThreadMcpApp(props: {
249 }, [props.environmentId, props.threadId, props.itemId, app.tool]);
250 const webView = useRef<WebView<object>>(null);
251 const hostRef = useRef<McpAppHost | null>(null);
252 + const userActive = useRef(false);
253
254 useEffect(() => {
255 if (uri === null) return;
@@ -360,9 +362,12 @@ export function ThreadMcpApp(props: {
362 },
363 requestDisplayMode: async (mode) => {
364 const current = latest.current.props;
365 + // receive dispatches synchronously; read activation before awaiting teardown.
366 if (
367 mode === "fullscreen" &&
365 - (latest.current.awaitingUser || !latest.current.navigation.isFocused())
368 + (!userActive.current ||
369 + latest.current.awaitingUser ||
370 + !latest.current.navigation.isFocused())
371 ) {
372 return current.displayMode ?? "inline";
373 }
@@ -545,7 +550,9 @@ export function ThreadMcpApp(props: {
550 setNavigatedAway(true);
551 return;
552 }
553 + userActive.current = envelope.active === true;
554 hostRef.current?.receive(message);
555 + userActive.current = false;
556 }}
557 />
558 ) : asset._tag === "Failure" || crashed ? (
apps/web/src/components/chat/McpAppFrame.browser.test.tsx new
+196
@@ -0,0 +1,196 @@
1 +import { EnvironmentId, ThreadId, TurnItemId } from "@t3tools/contracts";
2 +import { act } from "react";
3 +import { createRoot, type Root } from "react-dom/client";
4 +import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
5 +import { page, userEvent } from "vite-plus/test/browser";
6 +
7 +import "~/index.css";
8 +
9 +// The app asks for full screen from its button. It also focuses its own frame
10 +// and asks on load, right after it is told it left full screen, and whenever
11 +// it loses focus while inline. It reports each answer to the page with a
12 +// message the host ignores.
13 +const APP_HTML = `<!doctype html><button>Open full screen</button><script>
14 +let nextId = 0;
15 +const pending = new Map();
16 +const request = (method, params) =>
17 + new Promise((resolve) => {
18 + nextId += 1;
19 + pending.set(nextId, resolve);
20 + parent.postMessage({ jsonrpc: "2.0", id: nextId, method, params }, "*");
21 + });
22 +let mode = "inline";
23 +const askFullscreen = async (source) => {
24 + const answer = await request("ui/request-display-mode", { mode: "fullscreen" });
25 + mode = answer.mode;
26 + parent.postMessage({ probe: source + ":" + answer.mode }, "*");
27 +};
28 +const button = document.querySelector("button");
29 +button.onclick = () => askFullscreen("tap");
30 +const refocusAndAsk = (source) => {
31 + button.focus();
32 + void askFullscreen(source);
33 +};
34 +addEventListener("message", ({ data }) => {
35 + if (data === "retry") return refocusAndAsk("retry");
36 + if (pending.has(data.id)) {
37 + pending.get(data.id)(data.result);
38 + pending.delete(data.id);
39 + return;
40 + }
41 + if (data.method !== "ui/notifications/host-context-changed") return;
42 + const left = mode === "fullscreen" && data.params.displayMode === "inline";
43 + mode = data.params.displayMode ?? mode;
44 + if (left) refocusAndAsk("exit");
45 +});
46 +// Focus can only be taken back once the browser has finished moving it away.
47 +addEventListener("blur", () => {
48 + if (mode === "inline") setTimeout(() => refocusAndAsk("blur"));
49 +});
50 +void request("ui/initialize", { protocolVersion: "2026-01-26", appCapabilities: {} }).then(() => {
51 + parent.postMessage({ jsonrpc: "2.0", method: "ui/notifications/initialized", params: {} }, "*");
52 + refocusAndAsk("load");
53 +});
54 +</script>`;
55 +
56 +vi.mock(import("../../assets/assetUrls"), async (original) => ({
57 + ...(await original()),
58 + useAssetUrlState: (() => ({
59 + _tag: "Success",
60 + url: `data:text/html,${encodeURIComponent(APP_HTML)}`,
61 + expiresAt: Date.now() + 60 * 60_000,
62 + })) as never,
63 + useAssetUrlRefresh: (() => async () => null) as never,
64 +}));
65 +vi.mock(import("../../state/queries"), async (original) => ({
66 + ...(await original()),
67 + useTurnItemDetail: (() => ({ data: undefined })) as never,
68 +}));
69 +vi.mock(import("../../state/use-atom-command"), async (original) => ({
70 + ...(await original()),
71 + useAtomCommand: (() => async () => ({ _tag: "Failure", cause: undefined })) as never,
72 +}));
73 +vi.mock(import("../../hooks/useHtmlRenderTheme"), async (original) => ({
74 + ...(await original()),
75 + useHtmlRenderTheme: (() => ({ appearance: "light", variables: {} })) as never,
76 +}));
77 +
78 +import { McpAppFrame } from "./McpAppFrame";
79 +
80 +let root: Root | undefined;
81 +let skew = 0;
82 +let answers: string[] = [];
83 +let answered: (() => void) | undefined;
84 +const onProbe = (event: MessageEvent) => {
85 + const probe = (event.data as { readonly probe?: unknown } | null)?.probe;
86 + if (typeof probe !== "string") return;
87 + answers.push(probe);
88 + answered?.();
89 +};
90 +const nextAnswer = async (action: () => Promise<unknown>) => {
91 + const seen = answers.length;
92 + const answer = new Promise<string>((resolve) => {
93 + answered = () => {
94 + if (answers.length > seen) resolve(answers[seen]!);
95 + };
96 + });
97 + await action();
98 + return answer;
99 +};
100 +
101 +beforeEach(() => {
102 + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
103 + answers = [];
104 + answered = undefined;
105 + skew = 0;
106 + // Advance the host cooldown without manufacturing browser user activation.
107 + const now = performance.now.bind(performance);
108 + vi.spyOn(performance, "now").mockImplementation(() => now() + skew);
109 + window.addEventListener("message", onProbe);
110 +});
111 +afterEach(async () => {
112 + window.removeEventListener("message", onProbe);
113 + if (root !== undefined) await act(async () => root?.unmount());
114 + root = undefined;
115 + document.body.replaceChildren();
116 + vi.restoreAllMocks();
117 + vi.unstubAllGlobals();
118 +});
119 +
120 +const isFullscreen = () => document.querySelector("[data-mcp-app-fullscreen]") !== null;
121 +
122 +const renderApp = async () => {
123 + const container = document.body.appendChild(document.createElement("div"));
124 + root = createRoot(container);
125 + await act(async () =>
126 + root?.render(
127 + <McpAppFrame
128 + environmentId={EnvironmentId.make("env")}
129 + threadId={ThreadId.make("thread")}
130 + conversationThreadId={ThreadId.make("thread")}
131 + itemId={TurnItemId.make("item")}
132 + revision="1"
133 + app={{ attachmentId: "app", server: "srv", tool: "show", resourceUri: "ui://srv/app" }}
134 + onSendMessage={undefined}
135 + />,
136 + ),
137 + );
138 +};
139 +
140 +const retry = () =>
141 + nextAnswer(async () => {
142 + document.querySelector("iframe")!.contentWindow!.postMessage("retry", "*");
143 + });
144 +
145 +it("keeps load and idle retries inline even after the page-input cooldown", async () => {
146 + expect(await nextAnswer(renderApp)).toBe("load:inline");
147 + skew += 5_000;
148 + expect(await retry()).toBe("retry:inline");
149 + expect(await retry()).toBe("retry:inline");
150 + expect(isFullscreen()).toBe(false);
151 +});
152 +
153 +it("allows an app click immediately after loading on an idle page", async () => {
154 + expect(await nextAnswer(renderApp)).toBe("load:inline");
155 + const appButton = page
156 + .frameLocator(page.getByTitle("srv app"))
157 + .getByRole("button", { name: "Open full screen" });
158 + expect(await nextAnswer(() => userEvent.click(appButton))).toBe("tap:fullscreen");
159 + expect(isFullscreen()).toBe(true);
160 +});
161 +
162 +it("opens full screen only from a tap in the app, never from activation the page got elsewhere", async () => {
163 + const appButton = page
164 + .frameLocator(page.getByTitle("srv app"))
165 + .getByRole("button", { name: "Open full screen" });
166 + const elsewhere = document.body.appendChild(document.createElement("button"));
167 + elsewhere.textContent = "Elsewhere";
168 + const tapApp = async () => {
169 + skew += 5_000;
170 + expect(await nextAnswer(() => userEvent.click(appButton))).toBe("tap:fullscreen");
171 + expect(isFullscreen()).toBe(true);
172 + };
173 +
174 + // The click that opens a thread still activates the page as its app loads.
175 + const load = nextAnswer(async () => {
176 + await userEvent.click(elsewhere);
177 + await renderApp();
178 + });
179 + expect(await load).toBe("load:inline");
180 + expect(isFullscreen()).toBe(false);
181 +
182 + await tapApp();
183 + const exit = page.getByRole("button", { name: "Exit full screen" });
184 + expect(await nextAnswer(() => userEvent.click(exit))).toBe("exit:inline");
185 + expect(isFullscreen()).toBe(false);
186 +
187 + skew += 5_000;
188 + expect(await nextAnswer(() => userEvent.click(elsewhere))).toBe("blur:inline");
189 + expect(isFullscreen()).toBe(false);
190 +
191 + // Escape activates nothing, but the tap that opened full screen still does.
192 + await tapApp();
193 + (await exit.element()).focus();
194 + expect(await nextAnswer(() => userEvent.keyboard("{Escape}"))).toBe("exit:inline");
195 + expect(isFullscreen()).toBe(false);
196 +});
apps/web/src/components/chat/McpAppFrame.tsx
+21 -1
@@ -48,6 +48,8 @@ const fullscreenSupported =
48 typeof HTMLElement !== "undefined" && "popover" in HTMLElement.prototype;
49
50 const MAX_DOWNLOAD_BYTES = 25 * 1024 * 1024;
51 +// Exclude activation left by input elsewhere in T3.
52 +const PAGE_ACTIVATION_MS = 5_000;
53
54 function saveBlob(blob: Blob, name: string) {
55 const url = URL.createObjectURL(blob);
@@ -168,6 +170,21 @@ export function McpAppFrame(props: {
170 latest.current = live;
171 });
172
173 + // Frame input does not bubble here. An app can refocus itself, so focus
174 + // alone cannot exclude activation from input elsewhere in T3.
175 + const lastPageInputAt = useRef(Number.NEGATIVE_INFINITY);
176 + useEffect(() => {
177 + const note = () => {
178 + lastPageInputAt.current = performance.now();
179 + };
180 + if (navigator.userActivation?.isActive) note();
181 + const types = ["pointerdown", "pointerup", "touchend", "keydown"] as const;
182 + for (const type of types) window.addEventListener(type, note, true);
183 + return () => {
184 + for (const type of types) window.removeEventListener(type, note, true);
185 + };
186 + }, []);
187 +
188 useEffect(() => {
189 const box = boxRef.current;
190 if (box === null || !fullscreenSupported) return;
@@ -343,7 +360,10 @@ export function McpAppFrame(props: {
360 const otherFullscreen = document.querySelector("[data-mcp-app-fullscreen]");
361 if (
362 mode === "fullscreen" &&
346 - (latest.current.props.awaitingUser === true ||
363 + (document.activeElement !== frameRef.current ||
364 + !navigator.userActivation?.isActive ||
365 + performance.now() - lastPageInputAt.current < PAGE_ACTIVATION_MS ||
366 + latest.current.props.awaitingUser === true ||
367 isConfirmDialogActive() ||
368 (otherFullscreen !== null && otherFullscreen !== boxRef.current))
369 ) {
docs/user/html-renders.md
+1 -1
@@ -14,4 +14,4 @@ Some MCP servers return an interactive app with their tool results, following th
14
15 Apps follow your theme. An app can call tools on its own server and post a message to the thread; T3 Code asks first unless the server marks the tool as read-only, and it asks before every message. On mobile, an app also asks before opening a link, and T3 Code asks before saving a file an app offers. An app stays viewable after its agent stops, but using it needs the agent of the thread that created it running, so send a message in that thread first if the app says it is unavailable. An app that navigates away from its own page is stopped.
16
17 -An app can open full screen; use the button in its top corner, or press Escape outside the app, to return it to the thread. Anything else that needs your attention, such as an approval, also returns it to the thread. On mobile, full screen opens the app again in its own screen, so anything the app does not save itself starts over. An app can also keep the agent informed of what you did in it, such as a filter you picked; T3 Code sends the latest note from each app with your next message.
17 +An app can open full screen right after you tap or click in it. On web and desktop, a tap in the app within five seconds of a click or key press elsewhere in T3 Code doesn't count, so tap it again after that. Use the button in its top corner, or press Escape outside the app, to return it to the thread. Anything else that needs your attention, such as an approval, also returns it to the thread. On mobile, full screen opens the app again in its own screen, so anything the app does not save itself starts over. An app can also keep the agent informed of what you did in it, such as a filter you picked; T3 Code sends the latest note from each app with your next message.