surfnperf 1.6.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 50958281f857e08c1ed12fc53cc4c4530cac1407
4
- data.tar.gz: 8c3db9e7ede7da9a2bef33dfabffaa1ae5b171e7
2
+ SHA256:
3
+ metadata.gz: 5e187fe30d46408bd3cb199399bec37b181575a6a0a46f74e85ec2b18ceb14ba
4
+ data.tar.gz: 43be9b4d8225ced42bd22d5c05b398d5e6cade18c2b0a9aa8e025c5831494e54
5
5
  SHA512:
6
- metadata.gz: dd14809a82a59e4259484aec6376d227eb8cd0841fec83accd71746596291fb4117ef69109112f4f301d9b00a18f3d550e759fb2b6dc82c57a07fc2d050d975d
7
- data.tar.gz: 5e7650df5585fc60e783afa2373adb1d5d0ff6a0d5ec989d2bd216cf8887f296f907e28238346df184312c545c4e58cb1945a133d9250a841ed10c75472b49e9
6
+ metadata.gz: 3a6223477af43b8cf3a3668cb6fed81e869d874d58efa206760c1632924fbe8c0e6d2029e0498e6bdd3d119f92ef5e07129be72197eac3c2d3d92b49ebee4cda
7
+ data.tar.gz: e636c063e65c667f97810e953e57a368a1a529ff7de8d75bdb4fd6ec6ba7ff0f03f7b7c16029dcf8cbf9731f6159300ce274883f803371a0cff5c17f11a6a4f7
data/README.md CHANGED
@@ -13,7 +13,7 @@ Check out the [JavaScript API](https://github.com/Comcast/Surf-N-Perf/wiki/JavaS
13
13
 
14
14
  Available as an [NPM Module](https://www.npmjs.com/package/surfnperf), [Ruby Gem](https://rubygems.org/gems/surfnperf), and a [Bower](https://bower.io/) package.
15
15
 
16
- [![Build Status](https://travis-ci.org/Comcast/Surf-N-Perf.svg?branch=master)](https://travis-ci.org/Comcast/Surf-N-Perf)
16
+ ![Build Status](https://github.com/Comcast/Surf-N-Perf/actions/workflows/test.yml/badge.svg)
17
17
 
18
18
  ## Usage
19
19
 
@@ -120,9 +120,9 @@ That provides support for the following:
120
120
  - A `"firstPaintFrame"` mark (available in the best possible format for the browser, either a [User Timing Mark](http://www.w3.org/TR/user-timing/#performancemark), [DOMHighResTimeStamp](http://www.w3.org/TR/hr-time/#sec-DOMHighResTimeStamp), or [DOMTimeStamp](https://developer.mozilla.org/en-US/docs/Web/API/DOMTimeStamp)) that approximates the Time To First Paint in browsers that [support `window.requestAnimationFrame`](http://caniuse.com/#feat=requestanimationframe).
121
121
  - The initial `visibilityState` as well as listeners for the `"visibilitychange"` event, enabling the ability to calculate how much time the page was hidden when you call `surfnperf.getHiddenTime()`. This is of particular importance as [Chrome as of version 57](https://developers.google.com/web/updates/2017/03/background_tabs) and [Firefox as of version 57](https://blog.mozilla.org/blog/2017/09/26/firefox-quantum-beta-developer-edition/) limit the resources assigned to background (hidden) tabs.
122
122
 
123
- **2.** Then just drop the [surfnperf.min.js](https://github.com/Comcast/Surf-N-Perf/blob/master/surfnperf.min.js) in your codebase and reference that JavaScript file in your HTML document. If you're using [RequireJS](http://requirejs.org/) or [Browserify](http://browserify.org/), it registers itself as 'surfnperf'.
123
+ **2.** Then just drop the [surfnperf.min.js](https://github.com/Comcast/Surf-N-Perf/blob/main/surfnperf.min.js) in your codebase and reference that JavaScript file in your HTML document. If you're using [RequireJS](http://requirejs.org/) or [Browserify](http://browserify.org/), it registers itself as 'surfnperf'.
124
124
 
125
- **3.** (Optional) If you would like access to the [Resource Timing](https://developer.mozilla.org/en-US/docs/Web/API/Resource_Timing_API/Using_the_Resource_Timing_API) helper functions, include [resource-timing.js](https://github.com/Comcast/Surf-N-Perf/blob/master/resource-timing.js) in your codebase and reference that JavaScript file in your HTML document. If you're using [RequireJS](http://requirejs.org/), it registers itself as 'surfnperf/resource-timing', otherwise it is available on `window` as `window.surfnperfRT`.
125
+ **3.** (Optional) If you would like access to the [Resource Timing](https://developer.mozilla.org/en-US/docs/Web/API/Resource_Timing_API/Using_the_Resource_Timing_API) helper functions, include [resource-timing.js](https://github.com/Comcast/Surf-N-Perf/blob/main/resource-timing.js) in your codebase and reference that JavaScript file in your HTML document. If you're using [RequireJS](http://requirejs.org/), it registers itself as 'surfnperf/resource-timing', otherwise it is available on `window` as `window.surfnperfRT`.
126
126
 
127
127
  ### Storing & Retrieving Performance Data
128
128
 
@@ -142,7 +142,7 @@ The [surfnperf Ruby Gem](https://rubygems.org/gems/surfnperf) allows you to quic
142
142
  gem 'surfnperf'
143
143
  ```
144
144
 
145
- After a `$ bundle install`, you'll be able to include the [main JavaScript file](https://github.com/Comcast/Surf-N-Perf/blob/master/surfnperf.js) in your JavaScript manifest by simply adding:
145
+ After a `$ bundle install`, you'll be able to include the [main JavaScript file](https://github.com/Comcast/Surf-N-Perf/blob/main/surfnperf.js) in your JavaScript manifest by simply adding:
146
146
 
147
147
  ```
148
148
  //= require surfnperf
@@ -165,7 +165,7 @@ The [surfnperf Ruby Gem](https://rubygems.org/gems/surfnperf) also allows you to
165
165
  gem "surfnperf", ">=1.1.0"
166
166
  ```
167
167
 
168
- After a `$ bundle install`, you'll be able to include the [main JavaScript file](https://github.com/Comcast/Surf-N-Perf/blob/master/surfnperf.js) in your JavaScript manifest by simply adding:
168
+ After a `$ bundle install`, you'll be able to include the [main JavaScript file](https://github.com/Comcast/Surf-N-Perf/blob/main/surfnperf.js) in your JavaScript manifest by simply adding:
169
169
 
170
170
  ```
171
171
  //= require surfnperf
@@ -197,7 +197,7 @@ Add `surfnperf` to your `Gemfile`:
197
197
  gem 'surfnperf'
198
198
  ```
199
199
 
200
- After a `$ bundle install`, include [surfnperf.js](https://github.com/Comcast/Surf-N-Perf/blob/master/surfnperf.js) in your JavaScript manifest by adding:
200
+ After a `$ bundle install`, include [surfnperf.js](https://github.com/Comcast/Surf-N-Perf/blob/main/surfnperf.js) in your JavaScript manifest by adding:
201
201
 
202
202
  ```
203
203
  //= require surfnperf
@@ -228,4 +228,4 @@ The `grunt dev` process will watch for file updates, so as you modify surfnperf.
228
228
 
229
229
  ## License
230
230
 
231
- Licensed under the [MIT License](https://github.com/Comcast/Surf-N-Perf/blob/master/LICENSE)
231
+ Licensed under the [MIT License](https://github.com/Comcast/Surf-N-Perf/blob/main/LICENSE)
@@ -1 +1,23 @@
1
- !function(a,b){"function"==typeof define&&define.amd?define("surfnperf/resource-timing",["surfnperf"],b):"object"==typeof exports?module.exports=b(require("surfnperf")):a.surfnperfRT=b(a.surfnperf)}(this,function(a){var b=function(a,b){if(Array.prototype.indexOf)return-1!=a.indexOf(b);var c,d=a.length;for(c=0;c<d;c++)if(a[c]===b)return!0;return!1},c=function(){this._resourceTiming=null,this.initialize()},d=c.prototype;return d.initialize=function(){window.performance?(this._resourceTiming=!!window.performance.getEntriesByType,this._perf=function(){return window.performance}):this._resourceTiming=!1},d._inList=function(a,c){return c=c||{},c.hasOwnProperty("whitelist")?b(c.whitelist,a):!c.hasOwnProperty("blacklist")||!b(c.blacklist,a)},d._getURLOrigin=function(a){var b=document.createElement("a");return b.href=a,b.protocol+"//"+b.host},d.getOrigins=function(a){if(this._resourceTiming){var c=this.getResources(),d=[];for(var e in c){var f=this._getURLOrigin(c[e].name);!b(d,f)&&this._inList(f,a)&&0===f.indexOf("http")&&d.push(f)}return d}return null},d.getResourcesFromOrigin=function(a,b){if(this._resourceTiming){for(var c=this.getResources(),d=[],e=0,f=c.length;e<f;e++){this._getURLOrigin(c[e].name)===a&&(b?d.push(c[e][b]):d.push(c[e]))}return d}return null},d.getResourceNamesFromOrigin=function(a){return this.getResourcesFromOrigin(a,"name")},d.getLocation=function(){return window.location},d._name=function(a){if("/"==a.charAt(0)){var b=this.getLocation();return b.protocol+"//"+b.host+a}return a},d.getResources=function(a){return this._resourceTiming?a?this._perf().getEntriesByName(this._name(a),"resource"):this._perf().getEntriesByType("resource"):null},d.getResourceCount=function(a){return this._resourceTiming?this.getResources(a).length:null},d.getResource=function(a,b){if(this._resourceTiming){if("string"==typeof a){var c=this.getResources(a),d=0;return b&&("object"==typeof b?d=b.index||0:"number"!=typeof b&&"string"!=typeof b||(d=b)),"last"===d&&(d=c.length-1),c[d]}return a}return null},d.getLastResource=function(a){return this._resourceTiming?this.getResource(a,"last"):null},d.duration=function(b,c,d,e){if(this._resourceTiming){var f=this.getResource(b,e);return f?0!==f[c]&&0!==f[d]&&a._roundedDuration(f[c],f[d],e):void 0}return null},d.getStart=function(b,c){if(this._resourceTiming){var d=this.getResource(b,c);return d?a._round(d.startTime,c):void 0}return null},d.getEnd=function(b,c){if(this._resourceTiming){var d=this.getResource(b,c);return d?a._round(d.responseEnd,c):void 0}return null},d.getFullRequestLoadTime=function(b,c){if(this._resourceTiming){var d=this.getResource(b,c);return d?a._round(d.duration,c):void 0}return null},d.getNetworkTime=function(a,b){return this._resourceTiming?this.duration(a,"fetchStart","connectEnd",b):null},d.getServerTime=function(a,b){return this._resourceTiming?this.duration(a,"requestStart","responseEnd",b):null},d.getBlockingTime=function(a,b){if(this._resourceTiming){var c=this.getResource(a,b);return c?c.connectEnd&&c.connectEnd===c.fetchStart?this.duration(a,"connectEnd","requestStart",b):!!c.domainLookupStart&&this.duration(a,"fetchStart","domainLookupStart",b):void 0}return null},d.getNetworkDuration=function(b,c){if(!this._resourceTiming)return null;var d=this.getResource(b,c);if(d){if(d.domainLookupStart){c=c||{};var e={decimalPlaces:15,index:c.index},f=this.duration(b,"domainLookupStart","domainLookupEnd",e),g=this.duration(b,"connectStart","connectEnd",e),h=this.duration(b,"requestStart","responseEnd",e);return a._round(f+g+h,c)}return!1}},new c});
1
+ /*!
2
+ * @license
3
+ * Copyright 2015-2022 Comcast Cable Communications Management, LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ !function(a,b){"function"==typeof define&&define.amd?define("surfnperf/resource-timing",["surfnperf"],b):"object"==typeof exports?module.exports=b(require("surfnperf")):a.surfnperfRT=b(a.surfnperf)}(this,function(a){var b=function(a,b){if(Array.prototype.indexOf)return-1!=a.indexOf(b);var c,d=a.length;for(c=0;c<d;c++)if(a[c]===b)return!0;return!1},c=function(){this._resourceTiming=null,this.initialize()},d=c.prototype;return d.initialize=function(){window.performance?(this._resourceTiming=!!window.performance.getEntriesByType,this._perf=function(){return window.performance}):this._resourceTiming=!1},d._inList=function(a,c){return c=c||{},c.hasOwnProperty("whitelist")?b(c.whitelist,a):!c.hasOwnProperty("blacklist")||!b(c.blacklist,a)},d._getURLOrigin=function(a){var b=document.createElement("a");return b.href=a,b.protocol+"//"+b.host},d.getOrigins=function(a){if(this._resourceTiming){var c=this.getResources(),d=[];for(var e in c){var f=this._getURLOrigin(c[e].name);!b(d,f)&&this._inList(f,a)&&0===f.indexOf("http")&&d.push(f)}return d}return null},d.getResourcesFromOrigin=function(a,b){if(this._resourceTiming){for(var c=this.getResources(),d=[],e=0,f=c.length;e<f;e++){this._getURLOrigin(c[e].name)===a&&(b?d.push(c[e][b]):d.push(c[e]))}return d}return null},d.getResourceNamesFromOrigin=function(a){return this.getResourcesFromOrigin(a,"name")},d.getLocation=function(){return window.location},d._name=function(a){if("/"==a.charAt(0)){var b=this.getLocation();return b.protocol+"//"+b.host+a}return a},d.getResources=function(a){return this._resourceTiming?a?this._perf().getEntriesByName(this._name(a),"resource"):this._perf().getEntriesByType("resource"):null},d.getResourceCount=function(a){return this._resourceTiming?this.getResources(a).length:null},d.getResource=function(a,b){if(this._resourceTiming){if("string"==typeof a){var c=this.getResources(a),d=0;return b&&("object"==typeof b?d=b.index||0:"number"!=typeof b&&"string"!=typeof b||(d=b)),"last"===d&&(d=c.length-1),c[d]}return a}return null},d.getLastResource=function(a){return this._resourceTiming?this.getResource(a,"last"):null},d.duration=function(b,c,d,e){if(this._resourceTiming){var f=this.getResource(b,e);return f?0!==f[c]&&0!==f[d]&&a._roundedDuration(f[c],f[d],e):void 0}return null},d.getStart=function(b,c){if(this._resourceTiming){var d=this.getResource(b,c);return d?a._round(d.startTime,c):void 0}return null},d.getEnd=function(b,c){if(this._resourceTiming){var d=this.getResource(b,c);return d?a._round(d.responseEnd,c):void 0}return null},d.getFullRequestLoadTime=function(b,c){if(this._resourceTiming){var d=this.getResource(b,c);return d?a._round(d.duration,c):void 0}return null},d.getNetworkTime=function(a,b){return this._resourceTiming?this.duration(a,"fetchStart","connectEnd",b):null},d.getServerTime=function(a,b){return this._resourceTiming?this.duration(a,"requestStart","responseEnd",b):null},d.getBlockingTime=function(a,b){if(this._resourceTiming){var c=this.getResource(a,b);return c?c.connectEnd&&c.connectEnd===c.fetchStart?this.duration(a,"connectEnd","requestStart",b):!!c.domainLookupStart&&this.duration(a,"fetchStart","domainLookupStart",b):void 0}return null},d.getNetworkDuration=function(b,c){if(!this._resourceTiming)return null;var d=this.getResource(b,c);if(d){if(d.domainLookupStart){c=c||{};var e={decimalPlaces:15,index:c.index},f=this.duration(b,"domainLookupStart","domainLookupEnd",e),g=this.duration(b,"connectStart","connectEnd",e),h=this.duration(b,"requestStart","responseEnd",e);return a._round(f+g+h,c)}return!1}},new c});
@@ -1,5 +1,6 @@
1
1
  /*!
2
- * Copyright 2015-2018 Comcast Cable Communications Management, LLC
2
+ * @license
3
+ * Copyright 2015-2022 Comcast Cable Communications Management, LLC
3
4
  *
4
5
  * Permission is hereby granted, free of charge, to any person obtaining a copy
5
6
  * of this software and associated documentation files (the "Software"), to deal
@@ -143,7 +144,7 @@
143
144
  SNPProto._performanceTimingL2 = function(eventKey) {
144
145
  var delta = this.getTimingMark('loadEventEnd', 'DOM') - this.getTimingMark(eventKey, 'DOM'),
145
146
  value = window.SURF_N_PERF.highResMarks.loadEventEnd - delta;
146
- return(value < 0) ? 0 : this._round(value, {
147
+ return (value < 0) ? 0 : this._round(value, {
147
148
  decimalPlaces: 10
148
149
  });
149
150
  };
@@ -269,7 +270,7 @@
269
270
  SNPProto._setMeasure = function(startMark, endMark) {
270
271
  try {
271
272
  this.userTiming().measure(this._measureName(startMark, endMark), startMark, endMark);
272
- } catch(e) {
273
+ } catch (e) {
273
274
  if(window.console && window.console.error) {
274
275
  if(e && e.message) {
275
276
  console.error("Surf-N-Perf Exception:", e.message);
@@ -425,8 +426,26 @@
425
426
  * @memberOf SurfNPerf
426
427
  */
427
428
  SNPProto.getFirstPaint = function(options) {
428
- if(this.chromeLoadTimes()) {
429
- return this._roundedDuration(this.getTimingMark('navigationStart', 'DOM'), this.chromeLoadTimes().firstPaintTime * 1000, options);
429
+ if(this._supportsPaintAPI()) {
430
+ var firstPaint = window.performance.getEntriesByName('first-paint')[0] || {};
431
+ return this._roundedDuration(this.getTimingMark('navigationStart', 'DOM'), firstPaint.startTime, options);
432
+ } else if(this.msFirstPaint()) {
433
+ return this._roundedDuration(this.getTimingMark('navigationStart', 'DOM'), this.msFirstPaint(), options);
434
+ } else {
435
+ return null;
436
+ }
437
+ };
438
+
439
+ /**
440
+ * Time to first contentful paint (browser-reported time for the render of any content from the DOM)
441
+ *
442
+ * @returns {integer} time in ms
443
+ * @memberOf SurfNPerf
444
+ */
445
+ SNPProto.getFirstContentfulPaint = function(options) {
446
+ if(this._supportsPaintAPI()) {
447
+ var firstPaint = window.performance.getEntriesByName('first-contentful-paint')[0] || {};
448
+ return this._roundedDuration(this.getTimingMark('navigationStart', 'DOM'), firstPaint.startTime, options);
430
449
  } else if(this.msFirstPaint()) {
431
450
  return this._roundedDuration(this.getTimingMark('navigationStart', 'DOM'), this.msFirstPaint(), options);
432
451
  } else {
@@ -452,12 +471,8 @@
452
471
  }
453
472
  };
454
473
 
455
- SNPProto.chromeLoadTimes = function() {
456
- if(window.chrome && window.chrome.loadTimes) {
457
- return window.chrome.loadTimes();
458
- } else {
459
- return undefined;
460
- }
474
+ SNPProto._supportsPaintAPI = function() {
475
+ return window.performance && window.performance.getEntriesByName && 'PerformancePaintTiming' in window;
461
476
  };
462
477
 
463
478
  SNPProto.msFirstPaint = function() {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surfnperf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Riviello
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-23 00:00:00.000000000 Z
11
+ date: 2022-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,8 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubyforge_project:
77
- rubygems_version: 2.6.13
76
+ rubygems_version: 3.0.3.1
78
77
  signing_key:
79
78
  specification_version: 4
80
79
  summary: Micro-library for gathering frontend web page performance data