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
|
||||
): EventEmitter {
|
||||
if (eventName === 'request') {
|
||||
const wrap = (event: HTTPRequest) => {
|
||||
event.enqueueInterceptAction(() =>
|
||||
handler(event as PageEventObject[K])
|
||||
);
|
||||
};
|
||||
const wrap =
|
||||
this._handlerMap.get(handler) ||
|
||||
((event: HTTPRequest) => {
|
||||
event.enqueueInterceptAction(() =>
|
||||
handler(event as PageEventObject[K])
|
||||
);
|
||||
});
|
||||
|
||||
this._handlerMap.set(handler, wrap);
|
||||
|
||||
|
@ -153,17 +153,21 @@ describe('Page', function () {
|
||||
}
|
||||
};
|
||||
|
||||
page.on('request', onResponse);
|
||||
page.on('request', onResponse);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(handler.callCount).toBe(1);
|
||||
expect(handler.callCount).toBe(2);
|
||||
page.off('request', onResponse);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
// 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);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
// 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