surfnperf 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6e345d399d2630f3f58b9c21268597cf1d68beb9
4
- data.tar.gz: 32baf5b753846d060524f9e195d87010251b5f2e
2
+ SHA256:
3
+ metadata.gz: 5e187fe30d46408bd3cb199399bec37b181575a6a0a46f74e85ec2b18ceb14ba
4
+ data.tar.gz: 43be9b4d8225ced42bd22d5c05b398d5e6cade18c2b0a9aa8e025c5831494e54
5
5
  SHA512:
6
- metadata.gz: e53a18f7868588de15cb06dfc0b6dbcf9c89bca28ea6694047bbd68fb2fb4e6b26eb950cafb24c0aa39689535e7ced3bde9f378380168a3982d49fbf1e57fb9f
7
- data.tar.gz: 0a711e5ab7c218d6274c94d2886e51814e15407cff9648dd08d8e337092ef7feea7775aaf0e0568c728bbb441309cb5d0db03f8dffc33463c701588315cefb87
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,12 +120,18 @@ 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
+
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`.
124
126
 
125
127
  ### Storing & Retrieving Performance Data
126
128
 
127
129
  Details in the [JavaScript API](https://github.com/Comcast/Surf-N-Perf/wiki/JavaScript-API) page in the wiki
128
130
 
131
+ ### Resource Timing Helper Functions
132
+
133
+ Documented in the [JSDoc-generated Documentation](http://comcast.github.io/Surf-N-Perf/docs/SurfNPerfRT.html)
134
+
129
135
  ## Ruby Project Integration
130
136
 
131
137
  ### Using within a Rails project
@@ -136,7 +142,7 @@ The [surfnperf Ruby Gem](https://rubygems.org/gems/surfnperf) allows you to quic
136
142
  gem 'surfnperf'
137
143
  ```
138
144
 
139
- 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:
140
146
 
141
147
  ```
142
148
  //= require surfnperf
@@ -159,7 +165,7 @@ The [surfnperf Ruby Gem](https://rubygems.org/gems/surfnperf) also allows you to
159
165
  gem "surfnperf", ">=1.1.0"
160
166
  ```
161
167
 
162
- 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:
163
169
 
164
170
  ```
165
171
  //= require surfnperf
@@ -191,7 +197,7 @@ Add `surfnperf` to your `Gemfile`:
191
197
  gem 'surfnperf'
192
198
  ```
193
199
 
194
- 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:
195
201
 
196
202
  ```
197
203
  //= require surfnperf
@@ -222,4 +228,4 @@ The `grunt dev` process will watch for file updates, so as you modify surfnperf.
222
228
 
223
229
  ## License
224
230
 
225
- 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)
@@ -0,0 +1,23 @@
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 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.5.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: 2017-10-13 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
@@ -52,6 +52,7 @@ files:
52
52
  - lib/surfnperf/extension.rb
53
53
  - lib/surfnperf/rails.rb
54
54
  - lib/utils.rb
55
+ - vendor/assets/javascripts/resource-timing.js
55
56
  - vendor/assets/javascripts/surfnperf.js
56
57
  homepage: http://comcast.github.io/Surf-N-Perf/
57
58
  licenses:
@@ -72,8 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
73
  - !ruby/object:Gem::Version
73
74
  version: '0'
74
75
  requirements: []
75
- rubyforge_project:
76
- rubygems_version: 2.6.13
76
+ rubygems_version: 3.0.3.1
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Micro-library for gathering frontend web page performance data