mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(Page): remove event listeners to avoid MaxListenersExceededWarning
This patch starts to properly clean up event listeners on a failed navigation (Page.goto).
This commit is contained in:
parent
53531c9a92
commit
215b3497c7
@ -384,6 +384,7 @@ class Page extends EventEmitter {
|
|||||||
await this._client.send('Page.navigate', {url, referrer});
|
await this._client.send('Page.navigate', {url, referrer});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
watcher.cancel();
|
watcher.cancel();
|
||||||
|
helper.removeEventListeners([listener]);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
const error = await navigationPromise;
|
const error = await navigationPromise;
|
||||||
|
@ -753,6 +753,15 @@ describe('Page', function() {
|
|||||||
process.removeListener('warning', warningHandler);
|
process.removeListener('warning', warningHandler);
|
||||||
expect(warning).toBe(null);
|
expect(warning).toBe(null);
|
||||||
}));
|
}));
|
||||||
|
it('should not leak listeners during bad navigation', SX(async function() {
|
||||||
|
let warning = null;
|
||||||
|
const warningHandler = w => warning = w;
|
||||||
|
process.on('warning', warningHandler);
|
||||||
|
for (let i = 0; i < 20; ++i)
|
||||||
|
await page.goto('asdf').catch(e => {/* swallow navigation error */});
|
||||||
|
process.removeListener('warning', warningHandler);
|
||||||
|
expect(warning).toBe(null);
|
||||||
|
}));
|
||||||
it('should navigate to dataURL and fire dataURL requests', SX(async function() {
|
it('should navigate to dataURL and fire dataURL requests', SX(async function() {
|
||||||
const requests = [];
|
const requests = [];
|
||||||
page.on('request', request => requests.push(request));
|
page.on('request', request => requests.push(request));
|
||||||
|
Loading…
Reference in New Issue
Block a user