mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: waitForRequest works with async predicate (#9058)
This commit is contained in:
parent
a07ff121f0
commit
8f6b2c9b7c
@ -1668,12 +1668,12 @@ export class CDPPage extends Page {
|
|||||||
return waitForEvent(
|
return waitForEvent(
|
||||||
this.#frameManager.networkManager,
|
this.#frameManager.networkManager,
|
||||||
NetworkManagerEmittedEvents.Request,
|
NetworkManagerEmittedEvents.Request,
|
||||||
request => {
|
async request => {
|
||||||
if (isString(urlOrPredicate)) {
|
if (isString(urlOrPredicate)) {
|
||||||
return urlOrPredicate === request.url();
|
return urlOrPredicate === request.url();
|
||||||
}
|
}
|
||||||
if (typeof urlOrPredicate === 'function') {
|
if (typeof urlOrPredicate === 'function') {
|
||||||
return !!urlOrPredicate(request);
|
return !!(await urlOrPredicate(request));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
@ -907,6 +907,22 @@ describe('Page', function () {
|
|||||||
]);
|
]);
|
||||||
expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
|
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 () => {
|
it('should respect timeout', async () => {
|
||||||
const {page, puppeteer} = getTestState();
|
const {page, puppeteer} = getTestState();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user