This commit is contained in:
Yanlong Wang 2025-04-17 22:38:07 +08:00
parent d2afa9ddc2
commit 33ca16405e
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -1096,7 +1096,7 @@ export class PuppeteerControl extends AsyncService {
nextSnapshotDeferred.promise.finally(() => { nextSnapshotDeferred.promise.finally(() => {
this.off('crippled', crippleListener); this.off('crippled', crippleListener);
}); });
let successfullyDone = false; let successfullyDone;
const hdl = (s: any) => { const hdl = (s: any) => {
if (snapshot === s) { if (snapshot === s) {
return; return;
@ -1145,9 +1145,12 @@ export class PuppeteerControl extends AsyncService {
let waitForPromise: Promise<any> | undefined; let waitForPromise: Promise<any> | undefined;
let finalizationPromise: Promise<any> | undefined; let finalizationPromise: Promise<any> | undefined;
const doFinalization = async () => { const doFinalization = async () => {
if (!waitForPromise) { if (waitForPromise) {
successfullyDone = true; // SuccessfullyDone is meant for the finish of the page.
// It doesn't matter if you are expecting something and it didn't show up.
await waitForPromise.catch(() => void 0);
} }
successfullyDone ??= true;
try { try {
const pSubFrameSnapshots = this.snapshotChildFrames(page); const pSubFrameSnapshots = this.snapshotChildFrames(page);
snapshot = await page.evaluate('giveSnapshot(true)') as PageSnapshot; snapshot = await page.evaluate('giveSnapshot(true)') as PageSnapshot;
@ -1222,13 +1225,14 @@ export class PuppeteerControl extends AsyncService {
page.waitForSelector(options.waitForSelector!, { timeout: thisTimeout })) page.waitForSelector(options.waitForSelector!, { timeout: thisTimeout }))
.then(() => { .then(() => {
successfullyDone = true; successfullyDone = true;
finalizationPromise = doFinalization();
}) })
.catch((err) => { .catch((err) => {
waitForPromise = undefined;
this.logger.warn(`Page ${sn}: Failed to wait for selector ${options.waitForSelector}`, { err }); this.logger.warn(`Page ${sn}: Failed to wait for selector ${options.waitForSelector}`, { err });
}); });
return p as any; return p as any;
}); });
} }
try { try {