@devries-cameron20 / t3code-1 / commits / a4a8c61918
Fork 0

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

fix(server): preview click, hover and drag survive a target replaced while scrolling it into view (#30600)

Julius Marminge committed Nov 13, 2026 at 09:23 UTC a4a8c61918ac0df391e74952f2092e973d27911d
2 files changed +79 -1
apps/server/src/preview/ServerBrowserPage.test.ts
+61
@@ -610,6 +610,67 @@ describe("server browser drag", () => {
610 });
611 });
612
613 +describe("server browser click", () => {
614 + it("clicks a target the page replaced while it was being scrolled into view", async () => {
615 + let scrolls = 0;
616 + const clicks: Array<unknown> = [];
617 + const page = {
618 + locator: () => ({
619 + // Playwright resolves the node once; a page re-rendering it detaches that node.
620 + scrollIntoViewIfNeeded: async () => {
621 + if (scrolls++ === 0) {
622 + throw new Error("locator.scrollIntoViewIfNeeded: Element is not attached to the DOM");
623 + }
624 + },
625 + boundingBox: async () => ({ x: 0, y: 0, width: 20, height: 20 }),
626 + click: async (options: unknown) => {
627 + clicks.push(options);
628 + },
629 + count: async () => 1,
630 + }),
631 + once: () => {},
632 + off: () => {},
633 + } as unknown as Page;
634 +
635 + await expect(ServerBrowserPage.click(page, { selector: "#save" })).resolves.toEqual({
636 + x: 10,
637 + y: 10,
638 + });
639 + expect(clicks).toHaveLength(1);
640 + });
641 +
642 + it("retries a replaced target only within the action's timeout", async () => {
643 + vi.useFakeTimers();
644 + try {
645 + const timeouts: Array<number | undefined> = [];
646 + const clicks: Array<unknown> = [];
647 + const detached = new Error(
648 + "locator.scrollIntoViewIfNeeded: Element is not attached to the DOM",
649 + );
650 + const page = {
651 + locator: () => ({
652 + scrollIntoViewIfNeeded: async (options?: { timeout?: number }) => {
653 + timeouts.push(options?.timeout);
654 + vi.advanceTimersByTime(60);
655 + throw detached;
656 + },
657 + click: async (options: unknown) => {
658 + clicks.push(options);
659 + },
660 + }),
661 + } as unknown as Page;
662 +
663 + await expect(
664 + ServerBrowserPage.click(page, { selector: "#save", timeoutMs: 100 }),
665 + ).rejects.toBe(detached);
666 + expect(timeouts).toEqual([100, 40]);
667 + expect(clicks).toHaveLength(0);
668 + } finally {
669 + vi.useRealTimers();
670 + }
671 + });
672 +});
673 +
674 describe("server browser evaluate", () => {
675 it("does not retry a parse error that arrives after the timeout", async () => {
676 vi.useFakeTimers();
apps/server/src/preview/ServerBrowserPage.ts
+18 -1
@@ -147,6 +147,23 @@ export type PointerReporter = (
147 ) => Promise<void>;
148 const noPointer: PointerReporter = async () => {};
149
150 +// Locator.scrollIntoViewIfNeeded resolves its node once and fails when the page replaces it; the
151 +// input actions after it re-resolve, so the scroll does too, within the same timeout.
152 +const DETACHED = /^locator\.scrollIntoViewIfNeeded: Element is not attached to the DOM(?:\n|$)/;
153 +
154 +const scrollIntoView = async (locator: Locator, timeout: number) => {
155 + const deadline = Date.now() + timeout;
156 + for (;;) {
157 + try {
158 + return await locator.scrollIntoViewIfNeeded({ timeout: Math.max(1, deadline - Date.now()) });
159 + } catch (cause) {
160 + if (!(cause instanceof Error && DETACHED.test(cause.message)) || Date.now() >= deadline) {
161 + throw cause;
162 + }
163 + }
164 + }
165 +};
166 +
167 const targetPoint = async (
168 page: Page,
169 locator: Locator | null,
@@ -154,7 +171,7 @@ const targetPoint = async (
171 timeout: number,
172 ) => {
173 if (locator === null) return { x: input.x ?? 0, y: input.y ?? 0 };
157 - await locator.scrollIntoViewIfNeeded({ timeout });
174 + await scrollIntoView(locator, timeout);
175 const box = await locator.boundingBox({ timeout });
176 if (box) return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
177 const viewport = page.viewportSize();