You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1010 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import type { Page } from "playwright";
import { resolveRpaQuoteCaptureMs } from "@/lib/rpa/env";
import { RpaError } from "@/modules/rpa/errors";
/** submit 后期望落点(匿名流 sign-up-quote 亦为合法结果页) */
export const POST_SUBMIT_URL_PATTERN = /sign-up-quote|\/quote(?:\/|$|\?)/i;
export function isPostSubmitDestination(url: string): boolean {
return POST_SUBMIT_URL_PATTERN.test(url);
}
const POST_SUBMIT_POLL_MS = 250;
export async function waitForPostSubmitDestination(
page: Page,
timeoutMs = 20_000,
): Promise<string> {
const effectiveTimeoutMs = resolveRpaQuoteCaptureMs(timeoutMs);
const deadline = Date.now() + effectiveTimeoutMs;
while (Date.now() < deadline) {
const url = page.url();
if (isPostSubmitDestination(url)) {
return url;
}
await page.waitForTimeout(POST_SUBMIT_POLL_MS);
}
throw new RpaError(
"QUOTE_ENTRY_UNAVAILABLE",
`submit 后未到达报价结果页url=${page.url()}`,
{ retryable: true },
);
}