Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Mergedshivamhwp(GitHub profile, opens in a new tab)merged 7 commits intomain fromrefs/pull/18548/headmerged by juliusmarminge View on GitHub

Showing 4 changed files with 205 additions and 2 deletions (loading 2).

x
0 of 4 viewed, 4 left
9 additions and 2 deletionsapps/mobile/src/features/threads/McpAppWebView.tsxModified
View file
@@ -47,6 +47,7 @@
// Android exposes `ReactNativeWebView` to every frame, so a frame nested in the
// app could post to React Native directly. The outer page therefore wraps what
// it relays with a secret only it holds, and React Native drops anything else.
+// The relay also attests activation; the sandboxed app cannot set that flag.
function outerDocument(src: string, allow: string, secret: string) {
const attribute = (value: string) =>
value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
@@ -54,7 +55,7 @@
<style>html,body{margin:0;height:100%;background:transparent}iframe{border:0;display:block;width:100%;height:100%}</style></head>
<body><iframe id="app" sandbox="allow-scripts allow-forms" allow="${attribute(allow)}"></iframe>
<script>(function(){var frame=document.getElementById("app"),secret=${JSON.stringify(secret)},loads=0,live=true;
-var send=function(m){window.ReactNativeWebView.postMessage(JSON.stringify({secret:secret,message:m}));};
+var send=function(m){var u=navigator.userActivation;window.ReactNativeWebView.postMessage(JSON.stringify({secret:secret,active:!!(u&&u.isActive)&&document.activeElement===frame,message:m}));};
frame.addEventListener("load",function(){loads+=1;if(loads>1&&live){live=false;send({t3:"navigated"});}});
window.addEventListener("message",function(e){if(live&&e.source===frame.contentWindow)send(e.data);});
window.__t3McpAppReceive=function(m){live&&frame.contentWindow&&frame.contentWindow.postMessage(m,"*");};
@@ -248,6 +249,7 @@
}, [props.environmentId, props.threadId, props.itemId, app.tool]);
const webView = useRef<WebView<object>>(null);
const hostRef = useRef<McpAppHost | null>(null);
+ const userActive = useRef(false);
​
useEffect(() => {
if (uri === null) return;
@@ -360,9 +362,12 @@