The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): browser annotations show above page popovers and modal dialogs (#38846)
Julius Marminge committed
Nov 18, 2026 at 19:50 UTC
63bf014dc3fb35e76c32d4ca23ed0485cd5d47f7
2 files changed
+44
-3
apps/desktop/src/preview/PickPreload.test.ts
+3
@@ -29,6 +29,9 @@ const startAnnotation = (): ShadowRoot => {
29
disconnect() {}
30
},
31
);
32
+ // jsdom has no popover API.
33
+ HTMLElement.prototype.showPopover ??= () => {};
34
+ HTMLElement.prototype.hidePopover ??= () => {};
35
using attachShadow = vi.spyOn(Element.prototype, "attachShadow");
36
for (const listener of ipcListeners.get(START_PICK_CHANNEL) ?? []) listener({}, undefined, false);
37
const shadowRoot = attachShadow.mock.results[0]?.value;
apps/desktop/src/preview/PickPreload.ts
+41
-3
@@ -563,7 +563,9 @@ function startAnnotation(
563
const host = document.createElement("div");
564
host.setAttribute(OVERLAY_ATTRIBUTE, "");
565
host.setAttribute("dir", "ltr");
566
- host.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY};pointer-events:none`;
566
+ host.popover = "manual";
567
+ // Resets the UA popover box (fit-content size, auto margin, border, padding, Canvas background).
568
+ host.style.cssText = `position:fixed;inset:0;width:auto;height:auto;margin:0;border:0;padding:0;overflow:visible;background:transparent;color:inherit;z-index:${Z_INDEX_OVERLAY};pointer-events:none`;
569
applyAnnotationTheme(host, annotationTheme);
570
const shadowRoot = host.attachShadow({ mode: "closed" });
571
const themeStyle = document.createElement("style");
@@ -577,7 +579,7 @@ function startAnnotation(
579
root.style.cssText = "pointer-events:none";
580
const cursorStyle = document.createElement("style");
581
cursorStyle.setAttribute(OVERLAY_ATTRIBUTE, "");
580
- cursorStyle.textContent = `html[data-t3code-annotation-tool] body, html[data-t3code-annotation-tool] body * { cursor: crosshair !important; } [${OVERLAY_ATTRIBUTE}], [${OVERLAY_ATTRIBUTE}] * { cursor: default !important; } [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-inner-spin-button, [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-outer-spin-button { appearance:none; margin:0; }`;
582
+ cursorStyle.textContent = `[${OVERLAY_ATTRIBUTE}]::backdrop { display:none !important; } html[data-t3code-annotation-tool] body, html[data-t3code-annotation-tool] body * { cursor: crosshair !important; } [${OVERLAY_ATTRIBUTE}], [${OVERLAY_ATTRIBUTE}] * { cursor: default !important; } [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-inner-spin-button, [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-outer-spin-button { appearance:none; margin:0; }`;
583
document.documentElement.appendChild(cursorStyle);
584
shadowRoot.appendChild(root);
585
@@ -1600,6 +1602,38 @@ function startAnnotation(
1602
event.stopPropagation();
1603
};
1604
1605
+ // Page popovers and modal dialogs sit in the top layer above any z-index, and a modal makes
1606
+ // everything outside it inert, so the overlay is shown last and lives inside the topmost modal.
1607
+ // Modals in the order they opened, since DOM order does not say which one blocks the rest.
1608
+ const openedModals: Element[] = [];
1609
+ const raiseOverlay = (): void => {
1610
+ const focused = shadowRoot.activeElement;
1611
+ const parent =
1612
+ document.activeElement?.closest("dialog:modal") ??
1613
+ openedModals.findLast((dialog) => dialog.matches(":modal")) ??
1614
+ Array.from(document.querySelectorAll("dialog:modal")).at(-1) ??
1615
+ document.documentElement;
1616
+ if (host.parentElement !== parent) parent.appendChild(host);
1617
+ if (host.matches(":popover-open")) host.hidePopover();
1618
+ host.showPopover();
1619
+ if (focused instanceof HTMLElement && !focused.matches(":focus"))
1620
+ focused.focus({ preventScroll: true });
1621
+ };
1622
+ const onPageToggle = (event: Event): void => {
1623
+ const target = event.target;
1624
+ if (target === host) return;
1625
+ if (target instanceof HTMLDialogElement) {
1626
+ const index = openedModals.indexOf(target);
1627
+ if (index !== -1) openedModals.splice(index, 1);
1628
+ if (target.matches(":modal")) openedModals.push(target);
1629
+ }
1630
+ raiseOverlay();
1631
+ };
1632
+ // Removing an open dialog hides the overlay inside it without a toggle event.
1633
+ const detachObserver = new MutationObserver(() => {
1634
+ if (!host.isConnected || !host.matches(":popover-open")) raiseOverlay();
1635
+ });
1636
+
1637
const onPointerOut = (event: PointerEvent): void => {
1638
if (event.relatedTarget === null) clearHoverOutline();
1639
};
@@ -1644,6 +1678,8 @@ function startAnnotation(
1678
dragHandle.removeEventListener("pointerup", onEditorPointerUp);
1679
dragHandle.removeEventListener("pointercancel", onEditorPointerUp);
1680
for (const type of PAGE_ISOLATED_EVENTS) host.removeEventListener(type, stopAtOverlay);
1681
+ window.removeEventListener("toggle", onPageToggle, true);
1682
+ detachObserver.disconnect();
1683
document.documentElement.removeEventListener("focusout", onFocusOutToOverlay);
1684
if (editorLayoutFrame !== null) window.cancelAnimationFrame(editorLayoutFrame);
1685
ipcRenderer.off(CANCEL_PICK_CHANNEL, onCancel);
@@ -1813,7 +1849,9 @@ function startAnnotation(
1849
document.documentElement.appendChild(inputLayer);
1850
inputLayer.focus({ preventScroll: true });
1851
}
1816
- document.documentElement.appendChild(host);
1852
+ raiseOverlay();
1853
+ window.addEventListener("toggle", onPageToggle, true);
1854
+ detachObserver.observe(document.documentElement, { childList: true, subtree: true });
1855
rootResizeObserver.observe(document.documentElement);
1856
refreshToolButtons();
1857
updateStatus();