diff --git a/lib/NetworkManager.js b/lib/NetworkManager.js index e82f2596..623d8c8f 100644 --- a/lib/NetworkManager.js +++ b/lib/NetworkManager.js @@ -114,6 +114,10 @@ class NetworkManager extends EventEmitter { */ _onLoadingFinished(event) { let request = this._idToRequest.get(event.requestId); + // For certain requestIds we never receive requestWillBeSent event. + // @see https://github.com/GoogleChrome/puppeteer/issues/168 + if (!request) + return; this._idToRequest.delete(event.requestId); this.emit(NetworkManager.Events.RequestFinished, request); } @@ -123,6 +127,10 @@ class NetworkManager extends EventEmitter { */ _onLoadingFailed(event) { let request = this._idToRequest.get(event.requestId); + // For certain requestIds we never receive requestWillBeSent event. + // @see https://github.com/GoogleChrome/puppeteer/issues/168 + if (!request) + return; this._idToRequest.delete(event.requestId); this.emit(NetworkManager.Events.RequestFailed, request); } diff --git a/test/test.js b/test/test.js index a0b39e13..f95bf7de 100644 --- a/test/test.js +++ b/test/test.js @@ -457,6 +457,9 @@ describe('Puppeteer', function() { expect(error.message).toContain('Cannot navigate to invalid URL'); })); it('should fail when navigating to bad SSL', SX(async function() { + page.on('request', request => expect(request).toBeTruthy()); + page.on('requestfinished', request => expect(request).toBeTruthy()); + page.on('requestfailed', request => expect(request).toBeTruthy()); let error = null; try { await page.navigate(HTTPS_PREFIX + '/empty.html');