The best way to control Claude Code, Codex and more from any computer or phone
fix(server): capture device screenshots through their selected host (#34313)
Romil committed
Nov 12, 2026 at 10:22 UTC
214f1baf71079c13018737536fac674f17b8ab76
2 files changed
+67
-8
apps/server/src/device/DeviceHubProxy.test.ts
+63
-7
@@ -27,7 +27,10 @@ const fixture = (
27
) => {
28
let finalized = 0;
29
const requests: string[] = [];
30
+ const screenshots: Array<Parameters<DeviceService.DeviceService["Service"]["screenshot"]>[0]> =
31
+ [];
32
const headers: Array<Readonly<Record<string, string>>> = [];
33
+ const unexpectedOperation = Effect.die("Unexpected device operation");
34
const client = HttpClient.make((request, _url, signal) =>
35
Effect.gen(function* () {
36
requests.push(request.url);
@@ -45,7 +48,7 @@ const fixture = (
48
const { handler, dispose } = HttpRouter.toWebHandler(
49
DeviceHubProxy.layer.pipe(
50
Layer.provideMerge(
48
- Layer.succeed(EnvironmentAuth.EnvironmentAuth, {
51
+ Layer.mock(EnvironmentAuth.EnvironmentAuth)({
52
authenticateWebSocketUpgrade: () =>
53
authError
54
? Effect.fail(authError)
@@ -55,24 +58,50 @@ const fixture = (
58
method: "bearer-access-token",
59
scopes,
60
}),
58
- } as unknown as EnvironmentAuth.EnvironmentAuth["Service"]),
61
+ }),
62
),
63
Layer.provideMerge(
61
- Layer.succeed(DeviceService.DeviceService, {
62
- currentReadiness: () =>
64
+ Layer.mock(DeviceService.DeviceService)({
65
+ currentReadiness: (hostId) =>
66
Effect.succeed({
64
- hostId: LOCAL_DEVICE_HOST_ID,
67
+ hostId: hostId ?? LOCAL_DEVICE_HOST_ID,
68
+ nodePath: "node",
69
hub: { origin: "http://hub.test" },
70
+ devices: {
71
+ list: unexpectedOperation,
72
+ boot: () => unexpectedOperation,
73
+ attach: () => unexpectedOperation,
74
+ shutdown: () => unexpectedOperation,
75
+ screenshot: () => unexpectedOperation,
76
+ },
77
+ run: () => unexpectedOperation,
78
+ helpers: { serveSimAxSettings: null, serveSimCli: null },
79
...(upstream ? { upstream } : {}),
80
}),
68
- } as DeviceService.DeviceService["Service"]),
81
+ screenshot: (input) =>
82
+ Effect.sync(() => {
83
+ screenshots.push(input);
84
+ return {
85
+ device: {
86
+ hostId: input.hostId ?? LOCAL_DEVICE_HOST_ID,
87
+ id: input.deviceId,
88
+ platform: "ios",
89
+ name: "Phone",
90
+ version: "27.0",
91
+ booted: true,
92
+ physical: false,
93
+ },
94
+ png: new Uint8Array([137, 80, 78, 71]),
95
+ };
96
+ }),
97
+ }),
98
),
99
Layer.provideMerge(Layer.succeed(HttpClient.HttpClient, client)),
100
),
101
{ disableLogger: true },
102
);
103
disposers.push(dispose);
75
- return { handler, requests, headers, finalized: () => finalized };
104
+ return { handler, requests, screenshots, headers, finalized: () => finalized };
105
};
106
107
describe("device hub proxy", () => {
@@ -239,6 +268,33 @@ describe("device hub proxy", () => {
268
).toBe(404);
269
expect(requests).toEqual([]);
270
});
271
+
272
+ it.each(["serve-sim", "serve-emu"])(
273
+ "captures %s screenshots through hosts with their own stream routing",
274
+ async (vendor) => {
275
+ const { handler, requests, screenshots } = fixture(
276
+ [AuthOrchestrationReadScope],
277
+ false,
278
+ undefined,
279
+ () => Effect.succeed(null),
280
+ );
281
+ const response = await handler(
282
+ new Request(
283
+ `http://t3.test/api/device-hub/vendor/${vendor}/api/screenshot?device=udid-1&hostId=pool`,
284
+ {
285
+ method: "POST",
286
+ },
287
+ ),
288
+ );
289
+ expect(response.status).toBe(200);
290
+ expect(response.headers.get("content-type")).toBe("image/png");
291
+ expect(new Uint8Array(await response.arrayBuffer())).toEqual(
292
+ new Uint8Array([137, 80, 78, 71]),
293
+ );
294
+ expect(requests).toEqual([]);
295
+ expect(screenshots).toEqual([{ hostId: "pool", deviceId: "udid-1" }]);
296
+ },
297
+ );
298
});
299
300
it.each([
apps/server/src/device/DeviceHubProxy.ts
+4
-1
@@ -214,7 +214,10 @@ const handler = Effect.gen(function* () {
214
upstreamSearch.delete("hostId");
215
const search = upstreamSearch.size > 0 ? `?${upstreamSearch.toString()}` : "";
216
const screenshotDevice = upstreamSearch.get("device");
217
- if (!ready.upstream && hubPath === "/vendor/serve-sim/api/screenshot" && screenshotDevice) {
217
+ if (
218
+ screenshotDevice &&
219
+ ["/vendor/serve-sim/api/screenshot", "/vendor/serve-emu/api/screenshot"].includes(hubPath)
220
+ ) {
221
const { png } = yield* devices.screenshot({ hostId: ready.hostId, deviceId: screenshotDevice });
222
return HttpServerResponse.uint8Array(png, {
223
contentType: "image/png",