The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 01:45 UTC
fix(desktop): include Chrome app text in macOS SnapShots (#11325)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Julius Marminge <julius0216@outlook.com>
shivam committed
Oct 20, 2026 at 01:53 UTC
6b43524f0d12cac3eb0bbca567772063fa257554
4 files changed
+153
-1
apps/desktop/src/snapShot/DesktopSnapShot.test.ts
+63
@@ -2725,6 +2725,69 @@ it.each([
2725
}
2726
});
2727
2728
+it.each([
2729
+ ["com.google.Chrome", "Google Chrome – Profile"],
2730
+ ["org.chromium.Chromium", "Chromium"],
2731
+])("reads macOS %s page context with an accessibility title suffix", async (bundleId, suffix) => {
2732
+ const title = "Issues · pingdotgg/t3code";
2733
+ const bounds = { x: 0, y: 33, width: 1470, height: 857 };
2734
+ const window = {
2735
+ role: "window",
2736
+ name: `${title} - ${suffix}`,
2737
+ bounds,
2738
+ tree: async () => ({ name: title, children: [{ name: "New issue", children: [] }] }),
2739
+ children: async () => [{ role: "button", name: "New issue", bounds, children: async () => [] }],
2740
+ };
2741
+ accessibilityByPidMock.mockReset().mockImplementation(async (pid: number) => ({
2742
+ children: async () => (pid === 42 ? [window] : []),
2743
+ }));
2744
+
2745
+ const context = await readAccessibleWindowContext(
2746
+ { title, bounds, owner: { processId: 42, bundleId } },
2747
+ "darwin",
2748
+ title,
2749
+ );
2750
+
2751
+ assert.equal(context?.accessibleText, `${title}\nNew issue`);
2752
+ assert.equal(context?.accessibility?.format, "element-tree");
2753
+ assert.equal(
2754
+ context?.accessibility?.format === "element-tree"
2755
+ ? context.accessibility.root.children[0]?.name
2756
+ : undefined,
2757
+ "New issue",
2758
+ );
2759
+});
2760
+
2761
+it("does not borrow another Chrome process context when the captured PID has no windows", async () => {
2762
+ const title = "Issues · pingdotgg/t3code";
2763
+ const bounds = { x: 0, y: 33, width: 1470, height: 857 };
2764
+ const otherWindow = {
2765
+ role: "window",
2766
+ name: `${title} - Google Chrome – Profile`,
2767
+ bounds,
2768
+ tree: async () => ({
2769
+ name: title,
2770
+ children: [{ name: "Other process private text", children: [] }],
2771
+ }),
2772
+ children: async () => [],
2773
+ };
2774
+ accessibilityByPidMock.mockReset().mockResolvedValue({
2775
+ pid: 42,
2776
+ children: async () => [],
2777
+ });
2778
+ accessibilityListMock.mockResolvedValue([
2779
+ { pid: 43, bundleId: "com.google.Chrome", children: async () => [otherWindow] },
2780
+ ]);
2781
+
2782
+ assert.isUndefined(
2783
+ await readAccessibleWindowContext(
2784
+ { title, bounds, owner: { processId: 42, bundleId: "com.google.Chrome" } },
2785
+ "darwin",
2786
+ title,
2787
+ ),
2788
+ );
2789
+});
2790
+
2791
it("reads Flatpak app text from the AT-SPI proxy when the compositor PID misses", async () => {
2792
vi.stubEnv("XDG_SESSION_TYPE", "wayland");
2793
const bounds = { x: 0, y: 0, width: 1_920, height: 1_048 };
apps/desktop/src/snapShot/SnapShotAccessibility.ts
+3
-1
@@ -20,7 +20,7 @@ export type AccessibleWindowIdentity = {
20
readonly title: string;
21
readonly bounds: Electron.Rectangle;
22
readonly clientBounds?: Electron.Rectangle;
23
- readonly owner: { readonly processId: number };
23
+ readonly owner: { readonly processId: number; readonly bundleId?: string };
24
readonly accessibilityBoundsReliable?: boolean;
25
};
26
@@ -134,6 +134,8 @@ async function readCapturedWindowAccessibility(
134
sourceTitle,
135
bounds: active.bounds,
136
clientBounds: active.clientBounds,
137
+ platform,
138
+ bundleId: pidWindows.length > 0 ? active.owner.bundleId : undefined,
139
};
140
const window = findAccessibleWindow(
141
pidWindows.length > 0 || foreground !== undefined ? pidWindows : await windowsFromAppList(App),
apps/desktop/src/snapShot/snapShot.test.ts
+52
@@ -332,6 +332,58 @@ describe("findAccessibleWindow", () => {
332
bounds: { x: 100, y: 200, width: 800, height: 600 },
333
};
334
335
+ const chromeCapture = {
336
+ title: "Issues · pingdotgg/t3code",
337
+ bounds: captured.bounds,
338
+ platform: "darwin" as const,
339
+ bundleId: "com.google.Chrome",
340
+ };
341
+ const chromeWindow = {
342
+ name: `${chromeCapture.title} - Google Chrome – Profile`,
343
+ bounds: chromeCapture.bounds,
344
+ active: true,
345
+ };
346
+
347
+ it("uses a browser suffix only when no exact title matches", () => {
348
+ const exact = { name: chromeCapture.title, bounds: chromeCapture.bounds };
349
+ expect(findAccessibleWindow([chromeWindow, exact], chromeCapture)).toBe(exact);
350
+ expect(findAccessibleWindow([chromeWindow], chromeCapture)).toBe(chromeWindow);
351
+ });
352
+
353
+ it("rejects browser suffix matches with wrong bounds, page titles, or ambiguous windows", () => {
354
+ expect(
355
+ findAccessibleWindow(
356
+ [{ ...chromeWindow, bounds: { ...chromeWindow.bounds, x: 0 } }],
357
+ chromeCapture,
358
+ ),
359
+ ).toBeUndefined();
360
+ expect(
361
+ findAccessibleWindow([chromeWindow, { ...chromeWindow, active: false }], chromeCapture),
362
+ ).toBeUndefined();
363
+ expect(
364
+ findAccessibleWindow([chromeWindow], { ...chromeCapture, title: "Issues" }),
365
+ ).toBeUndefined();
366
+ expect(
367
+ findAccessibleWindow([chromeWindow], {
368
+ ...chromeCapture,
369
+ title: `${chromeCapture.title} - Google Chrome`,
370
+ }),
371
+ ).toBeUndefined();
372
+ });
373
+
374
+ it("keeps strict titles outside macOS Chrome and Chromium", () => {
375
+ for (const identity of [
376
+ { platform: "linux" as const, bundleId: "com.google.Chrome" },
377
+ { platform: "win32" as const, bundleId: "com.google.Chrome" },
378
+ { platform: "darwin" as const, bundleId: "com.example.Editor" },
379
+ { platform: "darwin" as const, bundleId: undefined },
380
+ ]) {
381
+ expect(
382
+ findAccessibleWindow([chromeWindow], { ...chromeCapture, ...identity }),
383
+ ).toBeUndefined();
384
+ }
385
+ });
386
+
387
it("matches one window by its captured bounds", () => {
388
const windows = [
389
{ name: "Private", bounds: { x: 0, y: 0, width: 400, height: 300 } },
apps/desktop/src/snapShot/snapShot.ts
+35
@@ -477,6 +477,8 @@ export function findAccessibleWindow<
477
readonly sourceTitle?: string;
478
readonly bounds: WindowBounds;
479
readonly clientBounds?: WindowBounds | undefined;
480
+ readonly platform?: NodeJS.Platform;
481
+ readonly bundleId?: string | undefined;
482
},
483
matchMode: "screen-bounds" | "wayland" = "screen-bounds",
484
options: { readonly allowUntitledUniqueBounds?: boolean } = {},
@@ -515,6 +517,8 @@ export function findAccessibleWindow<
517
const activeMatches = matches.filter((window) => safeProperty(() => window.active) === true);
518
if (activeMatches.length === 1) return activeMatches[0];
519
if (matches.length > 1) return undefined;
520
+ const browserMatch = findBrowserTitleMatch(windows, titles, captured, matchMode, matchesBounds);
521
+ if (browserMatch) return browserMatch;
522
}
523
// GTK4/libadwaita often exposes the frame as an unnamed group. A PID-scoped
524
// lookup can accept the one window whose bounds match; size-only guesses cannot.
@@ -525,6 +529,37 @@ export function findAccessibleWindow<
529
return boundsMatches.length === 1 ? boundsMatches[0] : undefined;
530
}
531
532
+// Chrome's macOS AX title can append the browser and profile to the captured page title.
533
+function findBrowserTitleMatch<T extends { readonly name?: string | null }>(
534
+ windows: readonly T[],
535
+ titles: ReadonlySet<string>,
536
+ captured: { readonly platform?: NodeJS.Platform; readonly bundleId?: string | undefined },
537
+ matchMode: "screen-bounds" | "wayland",
538
+ matchesBounds: (window: T) => boolean,
539
+): T | undefined {
540
+ if (captured.platform !== "darwin" || matchMode !== "screen-bounds") return undefined;
541
+ const browserName = /^com\.google\.Chrome(?:\.(?:beta|dev|canary))?$/.test(
542
+ captured.bundleId ?? "",
543
+ )
544
+ ? "Google Chrome"
545
+ : captured.bundleId === "org.chromium.Chromium"
546
+ ? "Chromium"
547
+ : undefined;
548
+ if (!browserName) return undefined;
549
+ const browserMatches = windows.filter((window) => {
550
+ if (!matchesBounds(window)) return false;
551
+ const name = window.name?.trim() ?? "";
552
+ return [...titles].some((title) => {
553
+ const prefix = `${title} - ${browserName}`;
554
+ return (
555
+ name === prefix ||
556
+ (name.startsWith(prefix) && /^ [–—-] \S.*$/u.test(name.slice(prefix.length)))
557
+ );
558
+ });
559
+ });
560
+ return browserMatches.length === 1 ? browserMatches[0] : undefined;
561
+}
562
+
563
const ELECTRON_KEY_NAMES: Readonly<Record<string, string>> = {
564
" ": "Space",
565
"+": "Plus",