mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: multiple same request event listener (#8404)
This commit is contained in:
parent
d111d19f78
commit
92110151d9
@ -631,11 +631,13 @@ export class Page extends EventEmitter {
|
|||||||
handler: (event: PageEventObject[K]) => void
|
handler: (event: PageEventObject[K]) => void
|
||||||
): EventEmitter {
|
): EventEmitter {
|
||||||
if (eventName === 'request') {
|
if (eventName === 'request') {
|
||||||
const wrap = (event: HTTPRequest) => {
|
const wrap =
|
||||||
event.enqueueInterceptAction(() =>
|
this._handlerMap.get(handler) ||
|
||||||
handler(event as PageEventObject[K])
|
((event: HTTPRequest) => {
|
||||||
);
|
event.enqueueInterceptAction(() =>
|
||||||
};
|
handler(event as PageEventObject[K])
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
this._handlerMap.set(handler, wrap);
|
this._handlerMap.set(handler, wrap);
|
||||||
|
|
||||||
|
@ -153,17 +153,21 @@ describe('Page', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
page.on('request', onResponse);
|
||||||
page.on('request', onResponse);
|
page.on('request', onResponse);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
expect(handler.callCount).toBe(1);
|
expect(handler.callCount).toBe(2);
|
||||||
page.off('request', onResponse);
|
page.off('request', onResponse);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
// Still one because we removed the handler.
|
// Still one because we removed the handler.
|
||||||
expect(handler.callCount).toBe(1);
|
expect(handler.callCount).toBe(3);
|
||||||
|
page.off('request', onResponse);
|
||||||
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
expect(handler.callCount).toBe(3);
|
||||||
page.on('request', onResponse);
|
page.on('request', onResponse);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
// Two now because we added the handler back.
|
// Two now because we added the handler back.
|
||||||
expect(handler.callCount).toBe(2);
|
expect(handler.callCount).toBe(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user