Skip to content

Commit

Permalink
fix: waitForRequest works with async predicate (#9058)
Browse files Browse the repository at this point in the history
  • Loading branch information
aspic-fish authored Oct 5, 2022
1 parent a07ff12 commit 8f6b2c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/puppeteer-core/src/common/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1668,12 +1668,12 @@ export class CDPPage extends Page {
return waitForEvent(
this.#frameManager.networkManager,
NetworkManagerEmittedEvents.Request,
request => {
async request => {
if (isString(urlOrPredicate)) {
return urlOrPredicate === request.url();
}
if (typeof urlOrPredicate === 'function') {
return !!urlOrPredicate(request);
return !!(await urlOrPredicate(request));
}
return false;
},
Expand Down
16 changes: 16 additions & 0 deletions test/src/page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,22 @@ describe('Page', function () {
]);
expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
});
it('should work with async predicate', async () => {
const {page, server} = getTestState();

await page.goto(server.EMPTY_PAGE);
const [request] = await Promise.all([
page.waitForRequest(async request => {
return request.url() === server.PREFIX + '/digits/2.png';
}),
page.evaluate(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
}),
]);
expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
});
it('should respect timeout', async () => {
const {page, puppeteer} = getTestState();

Expand Down

0 comments on commit 8f6b2c9

Please sign in to comment.