fix: wait-for-selector stalling process

This commit is contained in:
Yanlong Wang 2025-05-07 22:38:50 +08:00
parent da1098f38d
commit 7bc70a1955
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -1210,7 +1210,6 @@ export class PuppeteerControl extends AsyncService {
} }
await Promise.race([Promise.allSettled([...pageScriptEvaluations, ...frameScriptEvaluations]), delayPromise]) await Promise.race([Promise.allSettled([...pageScriptEvaluations, ...frameScriptEvaluations]), delayPromise])
.catch(() => void 0); .catch(() => void 0);
finalizationPromise = doFinalization();
return stuff; return stuff;
}); });
if (options.waitForSelector) { if (options.waitForSelector) {
@ -1232,16 +1231,16 @@ export class PuppeteerControl extends AsyncService {
}); });
return p as any; return p as any;
}); });
finalizationPromise = Promise.allSettled([waitForPromise, gotoPromise]).then(doFinalization);
} else {
finalizationPromise = gotoPromise.then(doFinalization);
} }
try { try {
let lastHTML = snapshot?.html; let lastHTML = snapshot?.html;
while (true) { while (true) {
const ckpt = [nextSnapshotDeferred.promise, gotoPromise]; const ckpt = [nextSnapshotDeferred.promise, waitForPromise ?? gotoPromise];
if (waitForPromise) {
ckpt.push(waitForPromise);
}
if (options.minIntervalMs) { if (options.minIntervalMs) {
ckpt.push(delay(options.minIntervalMs)); ckpt.push(delay(options.minIntervalMs));
} }