@devries-cameron20 / t3code-1 / commits / 8b26d5c98b
Fork 0

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

fix(web): pasting into the device screen types into the device (#21197)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Jai Khurana committed Oct 20, 2026 at 09:47 UTC 8b26d5c98b11c75265d31cf12a214c9fb261d8b0
4 files changed +91 -5
apps/web/src/components/device/DeviceStreamView.browser.test.tsx
+40 -5
@@ -35,6 +35,7 @@ vi.mock(import("./DevicePhoneViewport"), async (original) => ({
35 return <></>;
36 },
37 }));
38 +import { pasteTextToFocusComposer } from "../chat/composerFocusRedirect";
39 import { DeviceStreamView } from "./DeviceStreamView";
40
41 // MJPEG frames come from the device hub, so images keep their src without loading it and a
@@ -109,7 +110,7 @@ afterEach(async () => {
110 vi.unstubAllGlobals();
111 });
112
112 -async function setup(h264 = false) {
113 +async function setup(h264 = false, platform: "ios" | "android" = "ios") {
114 const touches: unknown[] = [];
115 vi.useFakeTimers();
116 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
@@ -160,6 +161,7 @@ async function setup(h264 = false) {
161 return Promise.resolve(new Response("prime"));
162 });
163 const sockets: Array<{ onmessage?: (event: { data: ArrayBuffer }) => void }> = [];
164 + const sent: unknown[] = [];
165 vi.stubGlobal(
166 "WebSocket",
167 class {
@@ -169,9 +171,11 @@ async function setup(h264 = false) {
171 sockets.push(this);
172 }
173 onmessage?: (event: { data: ArrayBuffer }) => void;
172 - send(packet: Uint8Array) {
173 - if (packet[0] === 0x03) {
174 - touches.push(JSON.parse(new TextDecoder().decode(packet.subarray(1))));
174 + send(message: string | Uint8Array) {
175 + if (typeof message === "string") {
176 + sent.push(message);
177 + } else if (message[0] === 0x03) {
178 + touches.push(JSON.parse(new TextDecoder().decode(message.subarray(1))));
179 }
180 }
181 close() {}
@@ -182,7 +186,7 @@ async function setup(h264 = false) {
186 hostId="local"
187 environmentId={EnvironmentId.make("test")}
188 deviceId="test"
185 - platform="ios"
189 + platform={platform}
190 visible={visible}
191 allowPhoneView={h264}
192 />
@@ -190,6 +194,7 @@ async function setup(h264 = false) {
194 await act(async () => root.render(view(true)));
195 return {
196 images,
197 + sent,
198 view,
199 touches,
200 configure() {
@@ -322,3 +327,33 @@ it("keeps the 3D viewer mounted across iOS video recovery and releases it when h
327 expect(viewerUnmounts).toBe(1);
328 expect(vi.getTimerCount()).toBe(0);
329 });
330 +
331 +it("types a paste on the Android screen into the device and lets Ctrl+V reach the paste", async () => {
332 + const { sent } = await setup(true, "android");
333 + const screen = container.querySelector<HTMLElement>('[role="application"]')!;
334 + screen.focus();
335 + expect(document.activeElement).toBe(screen);
336 + const chord = new KeyboardEvent("keydown", {
337 + key: "v",
338 + code: "KeyV",
339 + ctrlKey: true,
340 + bubbles: true,
341 + cancelable: true,
342 + });
343 + screen.dispatchEvent(chord);
344 + expect(chord.defaultPrevented).toBe(false);
345 + const clipboardData = new DataTransfer();
346 + clipboardData.setData("text/plain", "pässwörd 1");
347 + const composerPastes: Array<string | null> = [];
348 + const capturePaste = (event: ClipboardEvent) =>
349 + composerPastes.push(pasteTextToFocusComposer(event));
350 + window.addEventListener("paste", capturePaste, true);
351 + onTestFinished(() => window.removeEventListener("paste", capturePaste, true));
352 + const paste = new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true });
353 + screen.dispatchEvent(paste);
354 + expect(paste.defaultPrevented).toBe(true);
355 + expect(sent.map((message) => JSON.parse(message as string) as unknown)).toEqual([
356 + { type: "text", text: "pässwörd 1" },
357 + ]);
358 + expect(composerPastes).toEqual([null]);
359 +});
apps/web/src/components/device/DeviceStreamView.tsx
+14
@@ -378,6 +378,8 @@ export function DeviceStreamView(props: {
378 ref={hostRef}
379 className={cn(
380 "relative flex min-h-0 min-w-0 flex-1 items-center justify-center overflow-hidden outline-none",
381 + // Overlay the stream; focus (including pointer-driven focus) marks keyboard capture.
382 + "after:pointer-events-none after:absolute after:inset-0 after:z-10 focus:after:ring-2 focus:after:ring-inset focus:after:ring-ring",
383 controlsInset && "pr-14",
384 )}
385 tabIndex={0}
@@ -386,9 +388,21 @@ export function DeviceStreamView(props: {
388 onKeyDown={(event) => {
389 if (event.target !== event.currentTarget) return;
390 if (event.metaKey && !["r", "R"].includes(event.key)) return;
391 + // Let browser paste chords fire the paste event.
392 + if (
393 + (event.ctrlKey && (event.key === "v" || event.key === "V")) ||
394 + (event.shiftKey && event.key === "Insert")
395 + ) {
396 + return;
397 + }
398 event.preventDefault();
399 clientRef.current?.sendKey(event.nativeEvent, "down");
400 }}
401 + onPaste={(event) => {
402 + if (event.target !== event.currentTarget) return;
403 + event.preventDefault();
404 + clientRef.current?.sendText(event.clipboardData.getData("text/plain"));
405 + }}
406 onKeyUp={(event) => {
407 if (event.target !== event.currentTarget) return;
408 clientRef.current?.sendKey(event.nativeEvent, "up");
packages/client-runtime/src/device/stream.test.ts
+6
@@ -114,6 +114,8 @@ describe("native device stream transport", () => {
114 socket.onopen?.();
115 expect(socket.send).not.toHaveBeenCalled();
116 socket.onmessage?.({ data: Uint8Array.of(0x83).buffer });
117 + client.sendText("hello");
118 + expect(socket.send).not.toHaveBeenCalled();
119 client.setOrientation("landscape_right");
120 client.pressButton("home");
121 client.sendTouch("begin", 0.25, 0.75);
@@ -148,6 +150,8 @@ describe("native device stream transport", () => {
150 client.setOrientation("landscape_right");
151 client.pressButton("home");
152 client.pressButton("appSwitcher");
153 + const prefix = "a".repeat(299);
154 + client.sendText(`${prefix}ä`);
155 expect(
156 socket.send.mock.calls.map(([message]) => JSON.parse(message as string) as unknown),
157 ).toEqual([
@@ -156,6 +160,8 @@ describe("native device stream transport", () => {
160 { type: "touch", action: "up", x: 0.2, y: 0.1 },
161 { type: "home" },
162 { type: "recents" },
163 + { type: "text", text: prefix },
164 + { type: "text", text: "ä" },
165 ]);
166 client.stop();
167 expect(socket.close).toHaveBeenCalledTimes(1);
packages/client-runtime/src/device/stream.ts
+31
@@ -100,6 +100,10 @@ const SEMU_MAGIC = 0x53454d55;
100 const SEMU_HEADER_BYTES = 16;
101 const SEMU_FLAG_KEY = 1;
102 const SOFT_DECODE_QUEUE = 8;
103 +// expo-device-hub 0.15.3 serve-emu input.js MAX_TEXT_BYTES limits packets to 300 UTF-8 bytes.
104 +const ANDROID_MAX_TEXT_BYTES = 300;
105 +// The pinned hub queue depth is 128; the client does not read queue rejections.
106 +const ANDROID_MAX_TEXT_CHUNKS = 64;
107
108 const IOS_MSG_TOUCH = 0x03;
109 const IOS_MSG_BUTTON = 0x04;
@@ -116,6 +120,13 @@ const isWebCodecsSupported = (): boolean =>
120 "VideoDecoder" in globalThis &&
121 "EncodedVideoChunk" in globalThis;
122
123 +function utf8ByteLength(codePoint: number): number {
124 + if (codePoint <= 0x7f) return 1;
125 + if (codePoint <= 0x7ff) return 2;
126 + if (codePoint <= 0xffff) return 3;
127 + return 4;
128 +}
129 +
130 function taggedJson(tag: number, payload: unknown): Uint8Array<ArrayBuffer> {
131 const json = encoder.encode(JSON.stringify(payload));
132 const out = new Uint8Array(1 + json.length);
@@ -245,6 +256,8 @@ export interface DeviceStreamClient {
256 /** Normalized 0..1 coordinates in the displayed frame. */
257 readonly sendTouch: (phase: "begin" | "move" | "end", x: number, y: number) => void;
258 readonly sendKey: (event: KeyboardEvent, phase: "down" | "up") => void;
259 + /** Android only: iOS input is HID key codes, which cannot carry arbitrary text. */
260 + readonly sendText: (text: string) => void;
261 readonly pressButton: (button: DeviceHardwareButton) => void;
262 readonly rotate: () => void;
263 readonly setOrientation: (orientation: DeviceScreenSize["orientation"]) => void;
@@ -1054,6 +1067,24 @@ export function createDeviceStreamClient(
1067 send(JSON.stringify({ type: "text", text: event.key }));
1068 }
1069 },
1070 + sendText: (text) => {
1071 + if (platform !== "android") return;
1072 + let chunk = "";
1073 + let chunkBytes = 0;
1074 + let sentChunks = 0;
1075 + for (const character of text) {
1076 + const characterBytes = utf8ByteLength(character.codePointAt(0)!);
1077 + if (chunkBytes + characterBytes > ANDROID_MAX_TEXT_BYTES) {
1078 + send(JSON.stringify({ type: "text", text: chunk }));
1079 + if (++sentChunks >= ANDROID_MAX_TEXT_CHUNKS) return;
1080 + chunk = "";
1081 + chunkBytes = 0;
1082 + }
1083 + chunk += character;
1084 + chunkBytes += characterBytes;
1085 + }
1086 + if (chunk.length > 0) send(JSON.stringify({ type: "text", text: chunk }));
1087 + },
1088 pressButton: (button) => {
1089 if (platform === "ios") {
1090 const name =