Skip to content

Commit

Permalink
fix: consider existing frames when waiting for a frame
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Apr 6, 2022
1 parent 12260b1 commit ba38097
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/common/Page.ts
Expand Up @@ -2039,7 +2039,7 @@ export class Page extends EventEmitter {
return false;
}

return Promise.race([
const eventRace = Promise.race([
helper.waitForEvent(
this._frameManager,
FrameManagerEmittedEvents.FrameAttached,
Expand All @@ -2055,6 +2055,18 @@ export class Page extends EventEmitter {
this._sessionClosePromise()
),
]);

return Promise.race([
eventRace,
(async () => {
for (const frame of this.frames()) {
if (await predicate(frame)) {
return frame;
}
}
await eventRace;
})(),
]);
}

/**
Expand Down

0 comments on commit ba38097

Please sign in to comment.