surfnperf 1.6.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +7 -7
- data/vendor/assets/javascripts/resource-timing.js +23 -1
- data/vendor/assets/javascripts/surfnperf.js +26 -11
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5e187fe30d46408bd3cb199399bec37b181575a6a0a46f74e85ec2b18ceb14ba
|
4
|
+
data.tar.gz: 43be9b4d8225ced42bd22d5c05b398d5e6cade18c2b0a9aa8e025c5831494e54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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/
|
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/
|
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/
|
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/
|
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/
|
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/
|
231
|
+
Licensed under the [MIT License](https://github.com/Comcast/Surf-N-Perf/blob/main/LICENSE)
|
@@ -1 +1,23 @@
|
|
1
|
-
|
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
|
-
*
|
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.
|
429
|
-
|
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.
|
456
|
-
|
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:
|
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:
|
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
|
-
|
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
|