Skip to content

Commit

Permalink
fix: consider existing frames when waiting for a frame (#8200)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Apr 7, 2022
1 parent bdc9671 commit 0955225
Show file tree
Hide file tree
Showing 2 changed files with 28 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
15 changes: 15 additions & 0 deletions test/oopif.spec.ts
Expand Up @@ -371,6 +371,21 @@ describeChromeOnly('OOPIF', function () {
await target.page();
browser1.disconnect();
});

describe('waitForFrame', () => {
it('should resolve immediately if the frame already exists', async () => {
const { server } = getTestState();

await page.goto(server.EMPTY_PAGE);
await utils.attachFrame(
page,
'frame2',
server.CROSS_PROCESS_PREFIX + '/empty.html'
);

await page.waitForFrame((frame) => frame.url().endsWith('/empty.html'));
});
});
});

/**
Expand Down

0 comments on commit 0955225

Please sign in to comment.