nomagick commited on
Commit
33ca164
·
unverified ·
1 Parent(s): d2afa9d
Files changed (1) hide show
  1. src/services/puppeteer.ts +8 -4
src/services/puppeteer.ts CHANGED
@@ -1096,7 +1096,7 @@ export class PuppeteerControl extends AsyncService {
1096
  nextSnapshotDeferred.promise.finally(() => {
1097
  this.off('crippled', crippleListener);
1098
  });
1099
- let successfullyDone = false;
1100
  const hdl = (s: any) => {
1101
  if (snapshot === s) {
1102
  return;
@@ -1145,9 +1145,12 @@ export class PuppeteerControl extends AsyncService {
1145
  let waitForPromise: Promise<any> | undefined;
1146
  let finalizationPromise: Promise<any> | undefined;
1147
  const doFinalization = async () => {
1148
- if (!waitForPromise) {
1149
- successfullyDone = true;
 
 
1150
  }
 
1151
  try {
1152
  const pSubFrameSnapshots = this.snapshotChildFrames(page);
1153
  snapshot = await page.evaluate('giveSnapshot(true)') as PageSnapshot;
@@ -1222,13 +1225,14 @@ export class PuppeteerControl extends AsyncService {
1222
  page.waitForSelector(options.waitForSelector!, { timeout: thisTimeout }))
1223
  .then(() => {
1224
  successfullyDone = true;
1225
- finalizationPromise = doFinalization();
1226
  })
1227
  .catch((err) => {
 
1228
  this.logger.warn(`Page ${sn}: Failed to wait for selector ${options.waitForSelector}`, { err });
1229
  });
1230
  return p as any;
1231
  });
 
1232
  }
1233
 
1234
  try {
 
1096
  nextSnapshotDeferred.promise.finally(() => {
1097
  this.off('crippled', crippleListener);
1098
  });
1099
+ let successfullyDone;
1100
  const hdl = (s: any) => {
1101
  if (snapshot === s) {
1102
  return;
 
1145
  let waitForPromise: Promise<any> | undefined;
1146
  let finalizationPromise: Promise<any> | undefined;
1147
  const doFinalization = async () => {
1148
+ if (waitForPromise) {
1149
+ // SuccessfullyDone is meant for the finish of the page.
1150
+ // It doesn't matter if you are expecting something and it didn't show up.
1151
+ await waitForPromise.catch(() => void 0);
1152
  }
1153
+ successfullyDone ??= true;
1154
  try {
1155
  const pSubFrameSnapshots = this.snapshotChildFrames(page);
1156
  snapshot = await page.evaluate('giveSnapshot(true)') as PageSnapshot;
 
1225
  page.waitForSelector(options.waitForSelector!, { timeout: thisTimeout }))
1226
  .then(() => {
1227
  successfullyDone = true;
 
1228
  })
1229
  .catch((err) => {
1230
+ waitForPromise = undefined;
1231
  this.logger.warn(`Page ${sn}: Failed to wait for selector ${options.waitForSelector}`, { err });
1232
  });
1233
  return p as any;
1234
  });
1235
+
1236
  }
1237
 
1238
  try {