@devries-cameron20 / t3code-1 / commits / 77b38f9b09
Fork 0

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

fix(server): preview hover and drag fail within their timeout, not up to 3x later (#33550)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 14, 2026 at 10:30 UTC 77b38f9b09a9971c08abd2a3e9dfa29c688516e2
2 files changed +55 -7
apps/server/src/preview/ServerBrowserPage.test.ts
+46
@@ -765,6 +765,52 @@ describe("server browser drag", () => {
765 });
766 });
767
768 +describe("server browser action timeout", () => {
769 + type StepOptions = { readonly timeout?: number };
770 + it.each([
771 + {
772 + action: "hover",
773 + act: (page: Page) => ServerBrowserPage.hover(page, { selector: "#a", timeoutMs: 9_000 }),
774 + last: ["#a.hover 1"],
775 + },
776 + {
777 + action: "drag",
778 + act: (page: Page) =>
779 + ServerBrowserPage.drag(page, { source: "#a", target: "#b", timeoutMs: 9_000 }),
780 + last: ["#a.dragTo 1", "#b.boundingBox 1"],
781 + },
782 + ])("gives the $action's steps one shared timeout", async ({ act, last }) => {
783 + let now = 0;
784 + using _now = vi.spyOn(Date, "now").mockImplementation(() => now);
785 + const steps: Array<string> = [];
786 + const box = { x: 0, y: 0, width: 20, height: 20 };
787 + const page = {
788 + locator: (selector: string) => {
789 + const record = (step: string, options: StepOptions) =>
790 + steps.push(`${selector}.${step} ${options.timeout}`);
791 + return {
792 + // Each step that finds the target takes 5 of the 9 seconds.
793 + scrollIntoViewIfNeeded: async (options: StepOptions) => {
794 + record("scrollIntoViewIfNeeded", options);
795 + now += 5_000;
796 + },
797 + boundingBox: async (options: StepOptions) => {
798 + record("boundingBox", options);
799 + now += 5_000;
800 + return box;
801 + },
802 + hover: async (options: StepOptions) => record("hover", options),
803 + dragTo: async (_target: unknown, options: StepOptions) => record("dragTo", options),
804 + };
805 + },
806 + } as unknown as Page;
807 +
808 + await act(page);
809 +
810 + expect(steps).toEqual(["#a.scrollIntoViewIfNeeded 9000", "#a.boundingBox 4000", ...last]);
811 + });
812 +});
813 +
814 describe("server browser click", () => {
815 it("clicks a target the page replaced while it was being scrolled into view", async () => {
816 let scrolls = 0;
apps/server/src/preview/ServerBrowserPage.ts
+9 -7
@@ -917,14 +917,15 @@ export const hover = async (
917 input: PreviewAutomationHoverInput,
918 pointer: PointerReporter = noPointer,
919 ) => {
920 - const timeout = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
920 + const deadline = Date.now() + (input.timeoutMs ?? DEFAULT_TIMEOUT_MS);
921 + const remaining = () => Math.max(1, deadline - Date.now());
922 const locator = targetLocator(page, input);
922 - await pointer(await targetPoint(page, locator, input, () => timeout), "move");
923 + await pointer(await targetPoint(page, locator, input, remaining), "move");
924 if (locator === null) {
925 await page.mouse.move(input.x ?? 0, input.y ?? 0);
926 return;
927 }
927 - await locator.hover({ timeout });
928 + await locator.hover({ timeout: remaining() });
929 };
930
931 export const select = async (
@@ -967,17 +968,18 @@ export const drag = async (
968 input: PreviewAutomationDragInput,
969 pointer: PointerReporter = noPointer,
970 ) => {
970 - const timeout = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
971 + const deadline = Date.now() + (input.timeoutMs ?? DEFAULT_TIMEOUT_MS);
972 + const remaining = () => Math.max(1, deadline - Date.now());
973 const source = targetLocator(page, { locator: input.source })!;
974 const target = targetLocator(page, { locator: input.target })!;
973 - await pointer(await targetPoint(page, source, {}, () => timeout), "move");
975 + await pointer(await targetPoint(page, source, {}, remaining), "move");
976 // Observe drag rejection immediately; an unhandled rejection during cursor movement exits the server.
977 // Chromium delivers a single move before dragstart; steps give the page mousemoves during the drag.
976 - const dragFailure = source.dragTo(target, { timeout, steps: 5 }).then(
978 + const dragFailure = source.dragTo(target, { timeout: remaining(), steps: 5 }).then(
979 () => null,
980 (error: unknown) => ({ error }),
981 );
980 - const end = await target.boundingBox({ timeout }).catch(() => null);
982 + const end = await target.boundingBox({ timeout: remaining() }).catch(() => null);
983 if (end) await pointer({ x: end.x + end.width / 2, y: end.y + end.height / 2 }, "move");
984 const failure = await dragFailure;
985 if (failure) throw failure.error;