fix(server): preview click timeouts identify the target #23489
Mergedjuliusmarmingemerged 8 commits into
main fromrefs/pull/23489/headmerged by juliusmarminge View on GitHubjuliusmarminge added labelsbugfix
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelspr:gate-failed
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge removed labelssize:M
- apps/server/src/preview/ServerBrowserPage.ts lines 676 to 681Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -652,0 +668,21 @@668+ locator: Locator,669+ input: { readonly locator?: string | undefined; readonly selector?: string | undefined },670+ cause: unknown,671+) => {672+ if (!(cause instanceof Error && cause.name === "TimeoutError")) return cause;673+ const target = JSON.stringify(input.locator ?? input.selector);674+ // The host's reply must still beat the broker's short grace after the operation timeout.675+ let timer: ReturnType<typeof setTimeout> | undefined;676+ const matches = await Promise.race([677+ locator.count().catch(() => undefined),678+ new Promise<undefined>((resolve) => {679+ timer = setTimeout(() => resolve(undefined), TARGET_COUNT_MS);680+ }),681+ ]).finally(() => clearTimeout(timer));682+ if (matches === undefined) return cause;683+ return new ServerBrowserOperationError(684+ "PreviewAutomationTimeoutError",685+ matches === 0686+ ? `No element matches ${target} after the timeout. Take a fresh snapshot and use its locator.`687+ : `${target} still matches an element after the timeout. The click may have happened; check the page before retrying.`,688+ );apps/server/src/preview/ServerBrowserPage.ts lines 685 to 686OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -652,0 +666,21 @@666+ */667+const namedTargetTimeout = async (668+ locator: Locator,669+ input: { readonly locator?: string | undefined; readonly selector?: string | undefined },670+ cause: unknown,671+) => {672+ if (!(cause instanceof Error && cause.name === "TimeoutError")) return cause;673+ const target = JSON.stringify(input.locator ?? input.selector);674+ // The host's reply must still beat the broker's short grace after the operation timeout.675+ let timer: ReturnType<typeof setTimeout> | undefined;676+ const matches = await Promise.race([677+ locator.count().catch(() => undefined),678+ new Promise<undefined>((resolve) => {679+ timer = setTimeout(() => resolve(undefined), TARGET_COUNT_MS);680+ }),681+ ]).finally(() => clearTimeout(timer));682+ if (matches === undefined) return cause;683+ return new ServerBrowserOperationError(684+ "PreviewAutomationTimeoutError",685+ matches === 0686+ ? `No element matches ${target} after the timeout. Take a fresh snapshot and use its locator.`
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge removed labelspr:gate-failed
juliusmarminge added labelspr:ready
- apps/server/src/mcp/PreviewAutomationBroker.ts line 215OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -207,3 +207,9 @@207207208208 const MAX_REASON_CHARS = 500;209209210+const serverBrowserReason = (211+ context: PreviewAutomationRequestErrorContext,212+ error: NonNullable<PreviewAutomationResponse["error"]>,213+) =>214+ context.clientId === SERVER_BROWSER_AUTOMATION_CLIENT_ID215+ ? { reason: error.message.slice(0, MAX_REASON_CHARS) }@@ -635,0 +645,21 @@645+ * Playwright's timeout names neither the target nor why it waited. Counting only after the646+ * wait failed keeps auto-wait intact, but the count describes the page after the timeout, not647+ * what the click did: Playwright can dispatch the click and then time out waiting for the648+ * navigation it started.649+ */650+const namedTargetTimeout = async (651+ locator: Locator,652+ input: { readonly locator?: string | undefined; readonly selector?: string | undefined },653+ cause: unknown,654+) => {655+ if (!(cause instanceof Error && cause.name === "TimeoutError")) return cause;656+ const target = JSON.stringify(input.locator ?? input.selector);657+ // The host's reply must still beat the broker's short grace after the operation timeout.658+ let timer: ReturnType<typeof setTimeout> | undefined;659+ const matches = await Promise.race([660+ locator.count().catch(() => undefined),661+ new Promise<undefined>((resolve) => {662+ timer = setTimeout(() => resolve(undefined), TARGET_COUNT_MS);663+ }),664+ ]).finally(() => clearTimeout(timer));665+ if (matches === undefined) return cause;
- apps/server/src/preview/ServerBrowserPage.ts line 657OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -636 +637,21 @@636637 const locator = targetLocator(page, input);638+ try {639+ return await clickTarget(page, locator, input, timeout, pointer);640+ } catch (cause) {641+ throw locator === null ? cause : await namedTargetTimeout(locator, input, cause);642+ }643+};644+645+/**646+ * Playwright's timeout names neither the target nor why it waited. Counting only after the647+ * wait failed keeps auto-wait intact, but the count describes the page after the timeout, not648+ * what the click did: Playwright can dispatch the click and then time out waiting for the649+ * navigation it started.650+ */651+const namedTargetTimeout = async (652+ locator: Locator,653+ input: { readonly locator?: string | undefined; readonly selector?: string | undefined },654+ cause: unknown,655+) => {656+ if (!(cause instanceof Error && cause.name === "TimeoutError")) return cause;657+ const target = JSON.stringify(input.locator ?? input.selector);
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this10f3657
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed