Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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([
OrKoN marked this conversation as resolved.
Show resolved Hide resolved
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