Never sent 'requestfinished' event without passing actual request

It turns out we're not receiving 'Network.requestWillBeSent' event
for every requestId.

This patch makes sure we don't dispatch `requestfinished` and
`requestfailed` events without passing actual request.

References #168
This commit is contained in:
Andrey Lushnikov
2017-07-29 18:16:15 -07:00
parent 8e8517026f
commit 67f4264162
2 changed files with 11 additions and 0 deletions

View File

@@ -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);
}