fix(server): a timed-out browser drag no longer exits the server (#17360)

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Scott NortemanandClaude Opus 5.5 authored and GitHub committed 2026-10-09 00:10:34 -05:00
1 parent 5785df19ea
commit 8f76037197
2 files changed
+50 -3

No files matched your search

@@ -277,3 +277,45 @@ describe("server browser element refs", () => {
expect(await ServerBrowserPage.evaluate(cdp, { expression: "1 + 1" }, 2_000)).toBe(2);
});
});
describe("server browser drag", () => {
it("fails the drag, not the server, when it times out while the cursor is still moving", async () => {
const timedOut = new Error("locator.dragTo: Timeout 30000ms exceeded.");
const box = { x: 0, y: 0, width: 20, height: 20 };
const targetBox = Promise.withResolvers<typeof box>();
// Only the calls `drag` makes. The drag fails at once; the target's position arrives only
// when the test hands it over, after the rejection has had a turn to go unobserved.
const page = {
locator: (selector: string) =>
selector === "#card"
? {
scrollIntoViewIfNeeded: async () => {},
boundingBox: async () => box,
dragTo: () => Promise.reject(timedOut),
}
: { boundingBox: () => targetBox.promise },
} as unknown as Page;
const unobserved: Array<unknown> = [];
const onUnhandled = (reason: unknown) => unobserved.push(reason);
process.on("unhandledRejection", onUnhandled);
try {
let finished = false;
const settled = ServerBrowserPage.drag(page, { source: "#card", target: "#lane" }).then(
() => null,
(error: unknown) => error,
);
void settled.then(() => (finished = true));
// Two macrotask turns: Node reports a rejection nobody observed after the first.
await new Promise((resolve) => setImmediate(resolve));
await new Promise((resolve) => setImmediate(resolve));
// The failed drag waits for the cursor to reach the target before it reports.
expect(finished).toBe(false);
targetBox.resolve(box);
expect(await settled).toBe(timedOut);
expect(unobserved).toEqual([]);
} finally {
process.off("unhandledRejection", onUnhandled);
}
});
});
+8 -3
View File
@@ -380,11 +380,16 @@ export const drag = async (
const source = targetLocator(page, { locator: input.source })!;
const target = targetLocator(page, { locator: input.target })!;
await pointer(await targetPoint(page, source, {}, timeout), "move");
// The cursor travels with the drag; the page sees one continuous gesture.
const dropped = source.dragTo(target, { timeout });
// The cursor travels with the drag; the page sees one continuous gesture. Observe the drag's
// outcome as it starts: a rejection nobody handles while the cursor moves exits the server.
const dragFailure = source.dragTo(target, { timeout }).then(
() => null,
(error: unknown) => ({ error }),
);
const end = await target.boundingBox({ timeout }).catch(() => null);
if (end) await pointer({ x: end.x + end.width / 2, y: end.y + end.height / 2 }, "move");
await dropped;
const failure = await dragFailure;
if (failure) throw failure.error;
};
/** Sets files on one file input; false when no locator or selector names one. */