From c99545f6d16e64878c4f33ff777fba6fbd15e53b Mon Sep 17 00:00:00 2001 From: Brad Greenwald Date: Mon, 3 Oct 2016 17:18:39 -0700 Subject: [PATCH] Add graceful handling of exceeding browser 150 performance entry limit. --- lib/Http/HttpModule.js | 9 ++++++++- lib/Http/LatencyModule.js | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Http/HttpModule.js b/lib/Http/HttpModule.js index 42639e8..1e580dc 100755 --- a/lib/Http/HttpModule.js +++ b/lib/Http/HttpModule.js @@ -292,8 +292,15 @@ export default class HttpModule extends EventDispatcher { // XMLHttpRequest, we must wait for another process tick to check for a refreshed list. setTimeout((lastURLToken => { return () => { + let resourceEntries = performance.getEntriesByType('resource'); + + // Check the timing entries for possible browser limit. + if( resourceEntries.length >= 150 ) { + console.warn('The browser Performance API may have exceeded its recommended limit of 150. See https://developer.mozilla.org/en-US/docs/Web/API/Performance/setResourceTimingBufferSize'); + } + // Filter the timing entries to return only the one concerned by the last request made - let entries = performance.getEntriesByType('resource').filter(function(entry) { + let entries = resourceEntries.filter(function(entry) { return ~entry.name.indexOf(lastURLToken); }); diff --git a/lib/Http/LatencyModule.js b/lib/Http/LatencyModule.js index 219b69c..e50cf8f 100644 --- a/lib/Http/LatencyModule.js +++ b/lib/Http/LatencyModule.js @@ -212,6 +212,11 @@ export default class LatencyModule extends HttpModule { // With Resource Timing API if (!xhr) { this._getTimingEntry(entry => { + if( !entry ) { + console.warn(`Network JS could not find a performance entry for ${ this._lastURLToken }.`) + return + } + // The latency calculation differs between an HTTP and an HTTPS connection // See: http://www.w3.org/TR/resource-timing/#processing-model let latency = !entry.secureConnectionStart