fix: consider existing frames when waiting for a frame (#8200)

This commit is contained in:
Alex Rudenko 2022-04-07 15:05:36 +02:00 committed by GitHub
parent bdc9671465
commit 0955225b51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -2039,7 +2039,7 @@ export class Page extends EventEmitter {
return false; return false;
} }
return Promise.race([ const eventRace = Promise.race([
helper.waitForEvent( helper.waitForEvent(
this._frameManager, this._frameManager,
FrameManagerEmittedEvents.FrameAttached, FrameManagerEmittedEvents.FrameAttached,
@ -2055,6 +2055,18 @@ export class Page extends EventEmitter {
this._sessionClosePromise() this._sessionClosePromise()
), ),
]); ]);
return Promise.race([
eventRace,
(async () => {
for (const frame of this.frames()) {
if (await predicate(frame)) {
return frame;
}
}
await eventRace;
})(),
]);
} }
/** /**

View File

@ -371,6 +371,21 @@ describeChromeOnly('OOPIF', function () {
await target.page(); await target.page();
browser1.disconnect(); 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'));
});
});
}); });
/** /**