perfume.js
Advanced tools
Comparing version 3.0.0-rc.1 to 3.0.0-rc.2
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("perfume.js")):"function"==typeof define&&define.amd?define("perfume.js/angular",["exports","@angular/core","perfume.js"],t):t(((e=e||self).perfume=e.perfume||{},e.perfume.js=e.perfume.js||{},e.perfume.js.angular={}),e.ng.core,e.Perfume)}(this,(function(e,t,n){"use strict";n=n&&n.hasOwnProperty("default")?n.default:n;function r(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}function o(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(r(arguments[t]));return e}var i=new t.InjectionToken("Perfume.js config"),u=function(){function r(t){this.config=t,e.perfume=new n(t)}return r.ngModuleDef=t.ɵɵdefineNgModule({type:r}),r.ngInjectorDef=t.ɵɵdefineInjector({factory:function(e){return new(e||r)(t.ɵɵinject(i))}}),r}();t.NgModule;var f=function(){function n(){this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.timeToInteractiveDuration=0,this.config=e.perfume.config,this.firstPaintDuration=e.perfume.firstPaintDuration,this.firstContentfulPaintDuration=e.perfume.firstContentfulPaintDuration,this.firstInputDelayDuration=e.perfume.firstInputDelayDuration,this.observeFirstContentfulPaint=e.perfume.observeFirstContentfulPaint,this.observeFirstInputDelay=e.perfume.observeFirstInputDelay,this.observeTimeToInteractive=e.perfume.observeTimeToInteractive,this.timeToInteractiveDuration=e.perfume.timeToInteractiveDuration}return n.prototype.start=function(t){e.perfume.start(t)},n.prototype.end=function(t){return e.perfume.end(t)},n.prototype.endPaint=function(t){return e.perfume.endPaint(t)},n.prototype.log=function(t,n){e.perfume.log(t,n)},n.prototype.sendTiming=function(t,n){e.perfume.sendTiming(t,n)},n.ngInjectableDef=t.ɵɵdefineInjectable({token:n,factory:function(e){return new(e||n)},providedIn:null}),n}();t.Injectable;var a=function(){function e(){}return e.forRoot=function(e){return{ngModule:u,providers:[{provide:i,useValue:e},f]}},e.ngModuleDef=t.ɵɵdefineNgModule({type:e}),e.ngInjectorDef=t.ɵɵdefineInjector({factory:function(t){return new(t||e)},imports:[[]]}),e}();t.NgModule,e.NgPerfume=f,e.PERFUME_CONFIG=i,e.PerfumeAfterViewInit=function(t){return function(n){var r=function(){for(var r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];e.perfume.start(t||n.name);var u=function(){return n.apply(this,arguments)};return u.prototype=Object.create(n.prototype),new(u.bind.apply(u,o([void 0],r)))},i=n.prototype.ngAfterViewInit;return n.prototype.ngAfterViewInit=function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];i&&i.apply(this,r),e.perfume.end(t||n.name)},r.prototype=Object.create(n.prototype),r}},e.PerfumeModule=a,e.PerfumeRootModule=u,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("perfume.js")):"function"==typeof define&&define.amd?define("perfume.js/angular",["exports","@angular/core","perfume.js"],t):t(((e=e||self).perfume=e.perfume||{},e.perfume.js=e.perfume.js||{},e.perfume.js.angular={}),e.ng.core,e.Perfume)}(this,function(e,t,n){"use strict";n=n&&n.hasOwnProperty("default")?n.default:n;function r(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}function o(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(r(arguments[t]));return e}var i=new t.InjectionToken("Perfume.js config"),u=function(){function r(t){this.config=t,e.perfume=new n(t)}return r.ngModuleDef=t.ɵɵdefineNgModule({type:r}),r.ngInjectorDef=t.ɵɵdefineInjector({factory:function(e){return new(e||r)(t.ɵɵinject(i))}}),r}();t.NgModule;var f=function(){function n(){this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.timeToInteractiveDuration=0,this.config=e.perfume.config,this.firstPaintDuration=e.perfume.firstPaintDuration,this.firstContentfulPaintDuration=e.perfume.firstContentfulPaintDuration,this.firstInputDelayDuration=e.perfume.firstInputDelayDuration,this.observeFirstContentfulPaint=e.perfume.observeFirstContentfulPaint,this.observeFirstInputDelay=e.perfume.observeFirstInputDelay,this.observeTimeToInteractive=e.perfume.observeTimeToInteractive,this.timeToInteractiveDuration=e.perfume.timeToInteractiveDuration}return n.prototype.start=function(t){e.perfume.start(t)},n.prototype.end=function(t){return e.perfume.end(t)},n.prototype.endPaint=function(t){return e.perfume.endPaint(t)},n.prototype.log=function(t,n){e.perfume.log(t,n)},n.prototype.sendTiming=function(t,n){e.perfume.sendTiming(t,n)},n.ngInjectableDef=t.ɵɵdefineInjectable({token:n,factory:function(e){return new(e||n)},providedIn:null}),n}();t.Injectable;var a=function(){function e(){}return e.forRoot=function(e){return{ngModule:u,providers:[{provide:i,useValue:e},f]}},e.ngModuleDef=t.ɵɵdefineNgModule({type:e}),e.ngInjectorDef=t.ɵɵdefineInjector({factory:function(t){return new(t||e)},imports:[[]]}),e}();t.NgModule,e.NgPerfume=f,e.PERFUME_CONFIG=i,e.PerfumeAfterViewInit=function(t){return function(n){var r=function(){for(var r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];e.perfume.start(t||n.name);var u=function(){return n.apply(this,arguments)};return u.prototype=Object.create(n.prototype),new(u.bind.apply(u,o([void 0],r)))},i=n.prototype.ngAfterViewInit;return n.prototype.ngAfterViewInit=function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];i&&i.apply(this,r),e.perfume.end(t||n.name)},r.prototype=Object.create(n.prototype),r}},e.PerfumeModule=a,e.PerfumeRootModule=u,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=perfume.js-angular.umd.min.js.map |
{ | ||
"name": "perfume.js/angular", | ||
"version": "3.0.0-rc.1", | ||
"version": "3.0.0-rc.2", | ||
"peerDependencies": { | ||
@@ -5,0 +5,0 @@ "@angular/common": "^6.0.0", |
@@ -8,2 +8,6 @@ # Changelog | ||
### Breaking Changes | ||
* **refactor:** Dropped support for EmulatedPerformance | ||
## 3.0.0-beta.0 (2019-9-14) | ||
@@ -10,0 +14,0 @@ |
/*! | ||
* Perfume.js v3.0.0-rc.1 (http://zizzamia.github.io/perfume) | ||
* Perfume.js v3.0.0-rc.2 (http://zizzamia.github.io/perfume) | ||
* Copyright 2018 The Perfume Authors (https://github.com/Zizzamia/perfume.js/graphs/contributors) | ||
@@ -19,3 +19,3 @@ * Licensed under MIT (https://github.com/Zizzamia/perfume.js/blob/master/LICENSE) | ||
firstInputDelay: false, | ||
pageResource: false, | ||
dataConsumption: false, | ||
// Analytics | ||
@@ -31,2 +31,3 @@ googleAnalytics: { | ||
maxMeasureTime: 15000, | ||
maxDataConsumption: 20000, | ||
warning: false, | ||
@@ -38,3 +39,3 @@ debugging: false, | ||
this.firstInputDelayDuration = 0; | ||
this.pageResourceDecodedBodySize = 0; | ||
this.dataConsumption = 0; | ||
this.isHidden = false; | ||
@@ -67,18 +68,21 @@ this.logMetricWarn = 'Please provide a metric name'; | ||
_this.logDebug('observeFirstContentfulPaint'); | ||
_this.observers['fcp'] = resolve; | ||
_this.observers['firstPaint'] = resolve; | ||
_this.observers['firstContentfulPaint'] = resolve; | ||
_this.initFirstPaint(); | ||
}); | ||
} | ||
// FID needs to be initialized as soon as Perfume is available, which returns | ||
// a Promise that can be observed | ||
if (this.config.firstInputDelay) { | ||
this.observeFirstInputDelay = new Promise(function (resolve) { | ||
_this.observers['fid'] = resolve; | ||
_this.initFirstInputDelay(); | ||
// FID needs to be initialized as soon as Perfume is available, | ||
// which returns a Promise that can be observed. | ||
// DataConsumption resolves after FID is triggered | ||
this.observeFirstInputDelay = new Promise(function (resolve) { | ||
_this.observers['firstInputDelay'] = resolve; | ||
_this.initFirstInputDelay(); | ||
}); | ||
// Collects KB information related to resources on the page | ||
if (this.config.dataConsumption) { | ||
this.observeDataConsumption = new Promise(function (resolve) { | ||
_this.observers['dataConsumption'] = resolve; | ||
_this.initDataConsumption(); | ||
}); | ||
} | ||
// | ||
if (this.config.pageResource) { | ||
this.initPageResource(); | ||
} | ||
} | ||
@@ -247,8 +251,10 @@ // Init visibilitychange listener | ||
}); | ||
if (performanceEntry.name === 'first-contentful-paint') { | ||
_this.perfObservers.fcp.disconnect(); | ||
if (_this.perfObservers.firstContentfulPaint && | ||
performanceEntry.name === 'first-contentful-paint') { | ||
_this.perfObservers.firstContentfulPaint.disconnect(); | ||
} | ||
}); | ||
if (options.entryName === 'first-input') { | ||
this.perfObservers.fid.disconnect(); | ||
if (this.perfObservers.firstInputDelay && | ||
options.metricName === 'firstInputDelay') { | ||
this.perfObservers.firstInputDelay.disconnect(); | ||
} | ||
@@ -262,6 +268,22 @@ }; | ||
var decodedBodySize = parseFloat((performanceEntry.decodedBodySize / 1000).toFixed(2)); | ||
_this.pageResourceDecodedBodySize += decodedBodySize; | ||
_this.dataConsumption += decodedBodySize; | ||
} | ||
}); | ||
}; | ||
Perfume.prototype.digestFirstPaintEntries = function (entries) { | ||
this.performanceObserverCb({ | ||
entries: entries, | ||
entryName: 'first-paint', | ||
metricLog: 'First Paint', | ||
metricName: 'firstPaint', | ||
valueLog: 'startTime', | ||
}); | ||
this.performanceObserverCb({ | ||
entries: entries, | ||
entryName: 'first-contentful-paint', | ||
metricLog: 'First Contentful Paint', | ||
metricName: 'firstContentfulPaint', | ||
valueLog: 'startTime', | ||
}); | ||
}; | ||
/** | ||
@@ -272,21 +294,5 @@ * First Paint is essentially the paint after which | ||
Perfume.prototype.initFirstPaint = function () { | ||
var _this = this; | ||
this.logDebug('initFirstPaint'); | ||
try { | ||
this.perfObservers.fcp = this.perf.performanceObserver('paint', function (entries) { | ||
_this.performanceObserverCb({ | ||
entries: entries, | ||
entryName: 'first-paint', | ||
metricLog: 'First Paint', | ||
metricName: 'firstPaint', | ||
valueLog: 'startTime', | ||
}); | ||
_this.performanceObserverCb({ | ||
entries: entries, | ||
entryName: 'first-contentful-paint', | ||
metricLog: 'First Contentful Paint', | ||
metricName: 'firstContentfulPaint', | ||
valueLog: 'startTime', | ||
}); | ||
}); | ||
this.perfObservers.firstContentfulPaint = this.perf.performanceObserver('paint', this.digestFirstPaintEntries); | ||
} | ||
@@ -297,13 +303,14 @@ catch (e) { | ||
}; | ||
Perfume.prototype.digestFirstInputDelayEntries = function (entries) { | ||
this.performanceObserverCb({ | ||
entries: entries, | ||
metricLog: 'First Input Delay', | ||
metricName: 'firstInputDelay', | ||
valueLog: 'duration', | ||
}); | ||
this.disconnectDataConsumption(); | ||
}; | ||
Perfume.prototype.initFirstInputDelay = function () { | ||
var _this = this; | ||
try { | ||
this.perfObservers.fid = this.perf.performanceObserver('first-input', function (entries) { | ||
_this.performanceObserverCb({ | ||
entries: entries, | ||
metricLog: 'First Input Delay', | ||
metricName: 'firstInputDelay', | ||
valueLog: 'duration', | ||
}); | ||
}); | ||
this.perfObservers.firstInputDelay = this.perf.performanceObserver('first-input', this.digestFirstInputDelayEntries); | ||
} | ||
@@ -314,18 +321,26 @@ catch (e) { | ||
}; | ||
Perfume.prototype.initPageResource = function () { | ||
Perfume.prototype.digestDataConsumptionEntries = function (entries) { | ||
this.performanceObserverResourceCb({ | ||
entries: entries, | ||
}); | ||
}; | ||
Perfume.prototype.disconnectDataConsumption = function () { | ||
clearTimeout(this.dataConsumptionTimeout); | ||
if (!this.perfObservers.dataConsumption || !this.dataConsumption) { | ||
return; | ||
} | ||
this.logMetric(this.dataConsumption, 'Data Consumption', 'dataConsumption'); | ||
this.perfObservers.dataConsumption.disconnect(); | ||
}; | ||
Perfume.prototype.initDataConsumption = function () { | ||
var _this = this; | ||
try { | ||
this.perfObservers.pageResource = this.perf.performanceObserver('resource', function (entries) { | ||
_this.performanceObserverResourceCb({ | ||
entries: entries, | ||
}); | ||
}); | ||
// TODO Keep experimenting with this before release it | ||
setTimeout(function () { | ||
_this.perfObservers.pageResource.disconnect(); | ||
}, 5000); | ||
this.perfObservers.dataConsumption = this.perf.performanceObserver('resource', this.digestDataConsumptionEntries); | ||
} | ||
catch (e) { | ||
this.logWarn('initPageResource failed'); | ||
this.logWarn('initDataConsumption failed'); | ||
} | ||
this.dataConsumptionTimeout = setTimeout(function () { | ||
_this.disconnectDataConsumption(); | ||
}, 15000); | ||
}; | ||
@@ -350,5 +365,10 @@ /** | ||
// Stop Analytics and Logging for false negative metrics | ||
if (duration2Decimal > this.config.maxMeasureTime) { | ||
if (metricName !== 'dataConsumption' && | ||
duration2Decimal > this.config.maxMeasureTime) { | ||
return; | ||
} | ||
else if (metricName === 'dataConsumption' && | ||
duration2Decimal > this.config.maxDataConsumption) { | ||
return; | ||
} | ||
// Save metrics in Duration property | ||
@@ -360,8 +380,7 @@ if (metricName === 'firstPaint') { | ||
this.firstContentfulPaintDuration = duration2Decimal; | ||
this.observers['fcp'](duration2Decimal); | ||
} | ||
if (metricName === 'firstInputDelay') { | ||
this.firstInputDelayDuration = duration2Decimal; | ||
this.observers['fid'](duration2Decimal); | ||
} | ||
this.observers[metricName](duration2Decimal); | ||
// Logs the metric in the internal console.log | ||
@@ -368,0 +387,0 @@ this.log(logText, duration2Decimal); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/*! | ||
* Perfume.js v3.0.0-rc.1 (http://zizzamia.github.io/perfume) | ||
* Perfume.js v3.0.0-rc.2 (http://zizzamia.github.io/perfume) | ||
* Copyright 2018 The Perfume Authors (https://github.com/Zizzamia/perfume.js/graphs/contributors) | ||
@@ -21,3 +21,3 @@ * Licensed under MIT (https://github.com/Zizzamia/perfume.js/blob/master/LICENSE) | ||
firstInputDelay: false, | ||
pageResource: false, | ||
dataConsumption: false, | ||
// Analytics | ||
@@ -33,2 +33,3 @@ googleAnalytics: { | ||
maxMeasureTime: 15000, | ||
maxDataConsumption: 20000, | ||
warning: false, | ||
@@ -40,3 +41,3 @@ debugging: false, | ||
this.firstInputDelayDuration = 0; | ||
this.pageResourceDecodedBodySize = 0; | ||
this.dataConsumption = 0; | ||
this.isHidden = false; | ||
@@ -69,18 +70,21 @@ this.logMetricWarn = 'Please provide a metric name'; | ||
_this.logDebug('observeFirstContentfulPaint'); | ||
_this.observers['fcp'] = resolve; | ||
_this.observers['firstPaint'] = resolve; | ||
_this.observers['firstContentfulPaint'] = resolve; | ||
_this.initFirstPaint(); | ||
}); | ||
} | ||
// FID needs to be initialized as soon as Perfume is available, which returns | ||
// a Promise that can be observed | ||
if (this.config.firstInputDelay) { | ||
this.observeFirstInputDelay = new Promise(function (resolve) { | ||
_this.observers['fid'] = resolve; | ||
_this.initFirstInputDelay(); | ||
// FID needs to be initialized as soon as Perfume is available, | ||
// which returns a Promise that can be observed. | ||
// DataConsumption resolves after FID is triggered | ||
this.observeFirstInputDelay = new Promise(function (resolve) { | ||
_this.observers['firstInputDelay'] = resolve; | ||
_this.initFirstInputDelay(); | ||
}); | ||
// Collects KB information related to resources on the page | ||
if (this.config.dataConsumption) { | ||
this.observeDataConsumption = new Promise(function (resolve) { | ||
_this.observers['dataConsumption'] = resolve; | ||
_this.initDataConsumption(); | ||
}); | ||
} | ||
// | ||
if (this.config.pageResource) { | ||
this.initPageResource(); | ||
} | ||
} | ||
@@ -249,8 +253,10 @@ // Init visibilitychange listener | ||
}); | ||
if (performanceEntry.name === 'first-contentful-paint') { | ||
_this.perfObservers.fcp.disconnect(); | ||
if (_this.perfObservers.firstContentfulPaint && | ||
performanceEntry.name === 'first-contentful-paint') { | ||
_this.perfObservers.firstContentfulPaint.disconnect(); | ||
} | ||
}); | ||
if (options.entryName === 'first-input') { | ||
this.perfObservers.fid.disconnect(); | ||
if (this.perfObservers.firstInputDelay && | ||
options.metricName === 'firstInputDelay') { | ||
this.perfObservers.firstInputDelay.disconnect(); | ||
} | ||
@@ -264,6 +270,22 @@ }; | ||
var decodedBodySize = parseFloat((performanceEntry.decodedBodySize / 1000).toFixed(2)); | ||
_this.pageResourceDecodedBodySize += decodedBodySize; | ||
_this.dataConsumption += decodedBodySize; | ||
} | ||
}); | ||
}; | ||
Perfume.prototype.digestFirstPaintEntries = function (entries) { | ||
this.performanceObserverCb({ | ||
entries: entries, | ||
entryName: 'first-paint', | ||
metricLog: 'First Paint', | ||
metricName: 'firstPaint', | ||
valueLog: 'startTime', | ||
}); | ||
this.performanceObserverCb({ | ||
entries: entries, | ||
entryName: 'first-contentful-paint', | ||
metricLog: 'First Contentful Paint', | ||
metricName: 'firstContentfulPaint', | ||
valueLog: 'startTime', | ||
}); | ||
}; | ||
/** | ||
@@ -274,21 +296,5 @@ * First Paint is essentially the paint after which | ||
Perfume.prototype.initFirstPaint = function () { | ||
var _this = this; | ||
this.logDebug('initFirstPaint'); | ||
try { | ||
this.perfObservers.fcp = this.perf.performanceObserver('paint', function (entries) { | ||
_this.performanceObserverCb({ | ||
entries: entries, | ||
entryName: 'first-paint', | ||
metricLog: 'First Paint', | ||
metricName: 'firstPaint', | ||
valueLog: 'startTime', | ||
}); | ||
_this.performanceObserverCb({ | ||
entries: entries, | ||
entryName: 'first-contentful-paint', | ||
metricLog: 'First Contentful Paint', | ||
metricName: 'firstContentfulPaint', | ||
valueLog: 'startTime', | ||
}); | ||
}); | ||
this.perfObservers.firstContentfulPaint = this.perf.performanceObserver('paint', this.digestFirstPaintEntries); | ||
} | ||
@@ -299,13 +305,14 @@ catch (e) { | ||
}; | ||
Perfume.prototype.digestFirstInputDelayEntries = function (entries) { | ||
this.performanceObserverCb({ | ||
entries: entries, | ||
metricLog: 'First Input Delay', | ||
metricName: 'firstInputDelay', | ||
valueLog: 'duration', | ||
}); | ||
this.disconnectDataConsumption(); | ||
}; | ||
Perfume.prototype.initFirstInputDelay = function () { | ||
var _this = this; | ||
try { | ||
this.perfObservers.fid = this.perf.performanceObserver('first-input', function (entries) { | ||
_this.performanceObserverCb({ | ||
entries: entries, | ||
metricLog: 'First Input Delay', | ||
metricName: 'firstInputDelay', | ||
valueLog: 'duration', | ||
}); | ||
}); | ||
this.perfObservers.firstInputDelay = this.perf.performanceObserver('first-input', this.digestFirstInputDelayEntries); | ||
} | ||
@@ -316,18 +323,26 @@ catch (e) { | ||
}; | ||
Perfume.prototype.initPageResource = function () { | ||
Perfume.prototype.digestDataConsumptionEntries = function (entries) { | ||
this.performanceObserverResourceCb({ | ||
entries: entries, | ||
}); | ||
}; | ||
Perfume.prototype.disconnectDataConsumption = function () { | ||
clearTimeout(this.dataConsumptionTimeout); | ||
if (!this.perfObservers.dataConsumption || !this.dataConsumption) { | ||
return; | ||
} | ||
this.logMetric(this.dataConsumption, 'Data Consumption', 'dataConsumption'); | ||
this.perfObservers.dataConsumption.disconnect(); | ||
}; | ||
Perfume.prototype.initDataConsumption = function () { | ||
var _this = this; | ||
try { | ||
this.perfObservers.pageResource = this.perf.performanceObserver('resource', function (entries) { | ||
_this.performanceObserverResourceCb({ | ||
entries: entries, | ||
}); | ||
}); | ||
// TODO Keep experimenting with this before release it | ||
setTimeout(function () { | ||
_this.perfObservers.pageResource.disconnect(); | ||
}, 5000); | ||
this.perfObservers.dataConsumption = this.perf.performanceObserver('resource', this.digestDataConsumptionEntries); | ||
} | ||
catch (e) { | ||
this.logWarn('initPageResource failed'); | ||
this.logWarn('initDataConsumption failed'); | ||
} | ||
this.dataConsumptionTimeout = setTimeout(function () { | ||
_this.disconnectDataConsumption(); | ||
}, 15000); | ||
}; | ||
@@ -352,5 +367,10 @@ /** | ||
// Stop Analytics and Logging for false negative metrics | ||
if (duration2Decimal > this.config.maxMeasureTime) { | ||
if (metricName !== 'dataConsumption' && | ||
duration2Decimal > this.config.maxMeasureTime) { | ||
return; | ||
} | ||
else if (metricName === 'dataConsumption' && | ||
duration2Decimal > this.config.maxDataConsumption) { | ||
return; | ||
} | ||
// Save metrics in Duration property | ||
@@ -362,8 +382,7 @@ if (metricName === 'firstPaint') { | ||
this.firstContentfulPaintDuration = duration2Decimal; | ||
this.observers['fcp'](duration2Decimal); | ||
} | ||
if (metricName === 'firstInputDelay') { | ||
this.firstInputDelayDuration = duration2Decimal; | ||
this.observers['fid'](duration2Decimal); | ||
} | ||
this.observers[metricName](duration2Decimal); | ||
// Logs the metric in the internal console.log | ||
@@ -370,0 +389,0 @@ this.log(logText, duration2Decimal); |
@@ -1,2 +0,2 @@ | ||
var e=function(e,i,t){this.name=e,this.version=i,this.os=t},i=function(e){this.version=e,this.name="node",this.os=process.platform},t=function(){this.bot=!0,this.name="bot",this.version=null,this.os=null},n=3,r=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["vivaldi",/Vivaldi\/([0-9\.]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FBAV\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["searchbot",/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/]],s=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/],["Search Bot",/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/]];function o(){return"undefined"!=typeof navigator?function(i){var o=""!==i&&r.reduce((function(e,t){var n=t[0],r=t[1];if(e)return e;var s=r.exec(i);return!!s&&[n,s]}),!1);if(!o)return null;var a=o[0],u=o[1];if("searchbot"===a)return new t;var c=u[1]&&u[1].split(/[._]/).slice(0,3);c?c.length<n&&(c=c.concat(new Array(n-c.length).fill("0"))):c=[];return new e(a,c.join("."),function(e){var i=s.find((function(i){i[0];return i[1].test(e)}));return i?i[0]:null}(i))}(navigator.userAgent):"undefined"!=typeof process&&process.version?new i(process.version.slice(1)):null}var a,u,c,f,d=function(){return+new Date},h="function"==typeof window.requestIdleCallback,l=function(){function e(e){this.initTime_=e}return Object.defineProperty(e.prototype,"didTimeout",{get:function(){return!1},enumerable:!0,configurable:!0}),e.prototype.timeRemaining=function(){return Math.max(0,50-(d()-this.initTime_))},e}(),p=h?window.requestIdleCallback:function(e){var i=new l(d());return setTimeout((function(){return e(i)}),0)},g=h?window.cancelIdleCallback:function(e){clearTimeout(e)},m="function"==typeof Promise&&Promise.toString().indexOf("[native code]")>-1,b="MutationObserver"in window||"WebKitMutationObserver"in window||"MozMutationObserver"in window,v=m?function(e){Promise.resolve().then(e)}:b?(a=0,u=[],c=new MutationObserver((function(){u.forEach((function(e){return e()})),u=[]})),f=document.createTextNode(""),c.observe(f,{characterData:!0}),function(e){u.push(e),f.data=String(++a%2)}):function(e){},y=0,w=!("object"!=typeof window.safari||!window.safari.pushNotification),k=function(){function e(e){var i=void 0===e?{}:e,t=i.ensureTasksRun,n=void 0!==t&&t,r=i.defaultMinTaskTime,s=void 0===r?y:r;this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.idleCallbackHandle_=null,this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.defaultMinTaskTime_=s,this.ensureTasksRun_=n,this.runTasksImmediately=this.runTasksImmediately.bind(this),this.runTasks_=this.runTasks_.bind(this),this.onVisibilityChange_=this.onVisibilityChange_.bind(this),this.ensureTasksRun_&&(addEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&addEventListener("beforeunload",this.runTasksImmediately,!0))}return e.prototype.pushTask=function(e){this.addTask_(Array.prototype.push,e)},e.prototype.unshiftTask=function(e){this.addTask_(Array.prototype.unshift,e)},e.prototype.runTasksImmediately=function(){this.runTasks_()},e.prototype.hasPendingTasks=function(){return this.taskQueue_.length>0},e.prototype.clearPendingTasks=function(){this.taskQueue_=[],this.cancelScheduledRun_()},e.prototype.getState=function(){return this.state_},e.prototype.destroy=function(){this.taskQueue_=[],this.cancelScheduledRun_(),this.ensureTasksRun_&&(removeEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&removeEventListener("beforeunload",this.runTasksImmediately,!0))},e.prototype.addTask_=function(e,i,t){var n=(void 0===t?{}:t).minTaskTime,r=void 0===n?this.defaultMinTaskTime_:n,s={time:d(),visibilityState:document.visibilityState};e.call(this.taskQueue_,{state:s,task:i,minTaskTime:r}),this.scheduleTasksToRun_()},e.prototype.scheduleTasksToRun_=function(){this.ensureTasksRun_&&"hidden"===document.visibilityState?v(this.runTasks_):this.idleCallbackHandle_||(this.idleCallbackHandle_=p(this.runTasks_))},e.prototype.runTasks_=function(e){if(this.cancelScheduledRun_(),!this.isProcessing_){for(this.isProcessing_=!0;this.hasPendingTasks()&&!T(e,this.taskQueue_[0].minTaskTime);){var i=this.taskQueue_.shift(),t=i.task,n=i.state;this.state_=n,t(n),this.state_=null}this.isProcessing_=!1,this.hasPendingTasks()&&this.scheduleTasksToRun_()}},e.prototype.cancelScheduledRun_=function(){g(this.idleCallbackHandle_),this.idleCallbackHandle_=null},e.prototype.onVisibilityChange_=function(){"hidden"===document.visibilityState&&this.runTasksImmediately()},e}(),T=function(e,i){return!!(e&&e.timeRemaining()<=i)},_=function(){function e(e){this.config=e}return e.supported=function(){return window.performance&&!!performance.now&&!!performance.mark},e.supportedPerformanceObserver=function(){return window.chrome&&"PerformanceObserver"in window},e.prototype.now=function(){return window.performance.now()},e.prototype.mark=function(e,i){var t="mark_"+e+"_"+i;window.performance.mark(t)},e.prototype.measure=function(e,i){var t="mark_"+e+"_start",n="mark_"+e+"_end";return window.performance.measure(e,t,n),this.getDurationByMetric(e,i)},e.prototype.performanceObserver=function(e,i){return this.perfObserver=new PerformanceObserver(this.performanceObserverCb.bind(this,i)),this.perfObserver.observe({type:e,buffered:!0}),this.perfObserver},e.prototype.getDurationByMetric=function(e,i){var t=this.getMeasurementForGivenName(e);return t&&"measure"===t.entryType?t.duration:-1},e.prototype.getMeasurementForGivenName=function(e){var i=window.performance.getEntriesByName(e);return i[i.length-1]},e.prototype.performanceObserverCb=function(e,i){e(i.getEntries())},e}(),P=function(){function e(e){var i=this;void 0===e&&(e={}),this.config={firstContentfulPaint:!1,firstPaint:!1,firstInputDelay:!1,pageResource:!1,googleAnalytics:{enable:!1,timingVar:"name"},browserTracker:!1,logPrefix:"Perfume.js:",logging:!0,maxMeasureTime:15e3,warning:!1,debugging:!1},this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.pageResourceDecodedBodySize=0,this.isHidden=!1,this.logMetricWarn="Please provide a metric name",this.metrics={},this.observers={},this.perfObservers={},this.didVisibilityChange=function(){document.hidden&&(i.isHidden=document.hidden)},this.config=Object.assign({},this.config,e),this.perf=new _(this.config),_.supported()&&(this.config.browserTracker&&(this.browser=o()),_.supportedPerformanceObserver()&&((this.config.firstPaint||this.config.firstContentfulPaint)&&(this.observeFirstContentfulPaint=new Promise((function(e){i.logDebug("observeFirstContentfulPaint"),i.observers.fcp=e,i.initFirstPaint()}))),this.config.firstInputDelay&&(this.observeFirstInputDelay=new Promise((function(e){i.observers.fid=e,i.initFirstInputDelay()}))),this.config.pageResource&&this.initPageResource()),this.onVisibilityChange(),this.queue=new k({ensureTasksRun:!0}))}return e.prototype.start=function(e){this.checkMetricName(e)&&(this.metrics[e]?this.logWarn("Recording already started."):(this.metrics[e]={end:0,start:this.perf.now()},this.perf.mark(e,"start"),this.isHidden=!1))},e.prototype.end=function(e){var i=this;if(this.checkMetricName(e)){var t=this.metrics[e];if(t){t.end=this.perf.now(),this.perf.mark(e,"end");var n=this.perf.measure(e,t),r=parseFloat(n.toFixed(2));return delete this.metrics[e],this.queue.pushTask((function(){i.log(e,r),i.sendTiming(e,r)})),r}this.logWarn("Recording already stopped.")}},e.prototype.endPaint=function(e){var i=this;return new Promise((function(t){setTimeout((function(){var n=i.end(e);t(n)}))}))},e.prototype.log=function(e,i){if(!this.isHidden&&this.config.logging)if(e){var t=i.toFixed(2),n="%c "+this.config.logPrefix+" "+e+" "+t+" ms";window.console.log(n,"color: #ff6d00;font-size:11px;")}else this.logWarn(this.logMetricWarn)},e.prototype.logDebug=function(e,i){void 0===i&&(i=""),this.config.debugging&&window.console.log("Perfume.js debugging "+e+":",i)},e.prototype.sendTiming=function(e,i){if(!this.isHidden){var t=this.config.browserTracker?this.browser:void 0,n=this.addBrowserToMetricName(e);if(this.config.analyticsTracker&&this.config.analyticsTracker(e,i,t),this.config.googleAnalytics.enable)if(window.ga){var r=Math.round(i);window.ga("send","timing",n,this.config.googleAnalytics.timingVar,r)}else this.logWarn("Google Analytics has not been loaded")}},e.prototype.addBrowserToMetricName=function(e){if(!this.config.browserTracker)return e;var i=e;this.browser.name&&(i+="."+this.browser.name.replace(/\s/g,""),this.browser.os&&(i+="."+this.browser.os.replace(/\s/g,"")));return i},e.prototype.checkMetricName=function(e){return!!e||(this.logWarn(this.logMetricWarn),!1)},e.prototype.performanceObserverCb=function(e){var i=this;this.logDebug("performanceObserverCb",e),e.entries.forEach((function(t){i.queue.pushTask((function(){i.config[e.metricName]&&(!e.entryName||e.entryName&&t.name===e.entryName)&&i.logMetric(t[e.valueLog],e.metricLog,e.metricName)})),"first-contentful-paint"===t.name&&i.perfObservers.fcp.disconnect()})),"first-input"===e.entryName&&this.perfObservers.fid.disconnect()},e.prototype.performanceObserverResourceCb=function(e){var i=this;this.logDebug("performanceObserverResourceCb",e),e.entries.forEach((function(e){if(e.decodedBodySize){var t=parseFloat((e.decodedBodySize/1e3).toFixed(2));i.pageResourceDecodedBodySize+=t}}))},e.prototype.initFirstPaint=function(){var e=this;this.logDebug("initFirstPaint");try{this.perfObservers.fcp=this.perf.performanceObserver("paint",(function(i){e.performanceObserverCb({entries:i,entryName:"first-paint",metricLog:"First Paint",metricName:"firstPaint",valueLog:"startTime"}),e.performanceObserverCb({entries:i,entryName:"first-contentful-paint",metricLog:"First Contentful Paint",metricName:"firstContentfulPaint",valueLog:"startTime"})}))}catch(e){this.logWarn("initFirstPaint failed")}},e.prototype.initFirstInputDelay=function(){var e=this;try{this.perfObservers.fid=this.perf.performanceObserver("first-input",(function(i){e.performanceObserverCb({entries:i,metricLog:"First Input Delay",metricName:"firstInputDelay",valueLog:"duration"})}))}catch(e){this.logWarn("initFirstInputDelay failed")}},e.prototype.initPageResource=function(){var e=this;try{this.perfObservers.pageResource=this.perf.performanceObserver("resource",(function(i){e.performanceObserverResourceCb({entries:i})})),setTimeout((function(){e.perfObservers.pageResource.disconnect()}),5e3)}catch(e){this.logWarn("initPageResource failed")}},e.prototype.onVisibilityChange=function(){void 0!==document.hidden&&document.addEventListener("visibilitychange",this.didVisibilityChange)},e.prototype.logMetric=function(e,i,t){var n=parseFloat(e.toFixed(2));n>this.config.maxMeasureTime||("firstPaint"===t&&(this.firstPaintDuration=n),"firstContentfulPaint"===t&&(this.firstContentfulPaintDuration=n,this.observers.fcp(n)),"firstInputDelay"===t&&(this.firstInputDelayDuration=n,this.observers.fid(n)),this.log(i,n),this.sendTiming(t,n))},e.prototype.logWarn=function(e){this.config.warning&&this.config.logging&&window.console.warn(this.config.logPrefix,e)},e}();export default P; | ||
var t=function(t,e,i){this.name=t,this.version=e,this.os=i},e=function(t){this.version=t,this.name="node",this.os=process.platform},i=function(){this.bot=!0,this.name="bot",this.version=null,this.os=null},n=3,s=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["vivaldi",/Vivaldi\/([0-9\.]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FBAV\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["searchbot",/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/]],r=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/],["Search Bot",/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/]];function o(){return"undefined"!=typeof navigator?function(e){var o=""!==e&&s.reduce((function(t,i){var n=i[0],s=i[1];if(t)return t;var r=s.exec(e);return!!r&&[n,r]}),!1);if(!o)return null;var a=o[0],u=o[1];if("searchbot"===a)return new i;var c=u[1]&&u[1].split(/[._]/).slice(0,3);c?c.length<n&&(c=c.concat(new Array(n-c.length).fill("0"))):c=[];return new t(a,c.join("."),function(t){var e=r.find((function(e){e[0];return e[1].test(t)}));return e?e[0]:null}(e))}(navigator.userAgent):"undefined"!=typeof process&&process.version?new e(process.version.slice(1)):null}var a,u,c,f,d=function(){return+new Date},h="function"==typeof window.requestIdleCallback,p=function(){function t(t){this.initTime_=t}return Object.defineProperty(t.prototype,"didTimeout",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype.timeRemaining=function(){return Math.max(0,50-(d()-this.initTime_))},t}(),l=h?window.requestIdleCallback:function(t){var e=new p(d());return setTimeout((function(){return t(e)}),0)},m=h?window.cancelIdleCallback:function(t){clearTimeout(t)},g="function"==typeof Promise&&Promise.toString().indexOf("[native code]")>-1,b="MutationObserver"in window||"WebKitMutationObserver"in window||"MozMutationObserver"in window,v=g?function(t){Promise.resolve().then(t)}:b?(a=0,u=[],c=new MutationObserver((function(){u.forEach((function(t){return t()})),u=[]})),f=document.createTextNode(""),c.observe(f,{characterData:!0}),function(t){u.push(t),f.data=String(++a%2)}):function(t){},y=0,w=!("object"!=typeof window.safari||!window.safari.pushNotification),T=function(){function t(t){var e=void 0===t?{}:t,i=e.ensureTasksRun,n=void 0!==i&&i,s=e.defaultMinTaskTime,r=void 0===s?y:s;this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.idleCallbackHandle_=null,this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.defaultMinTaskTime_=r,this.ensureTasksRun_=n,this.runTasksImmediately=this.runTasksImmediately.bind(this),this.runTasks_=this.runTasks_.bind(this),this.onVisibilityChange_=this.onVisibilityChange_.bind(this),this.ensureTasksRun_&&(addEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&addEventListener("beforeunload",this.runTasksImmediately,!0))}return t.prototype.pushTask=function(t){this.addTask_(Array.prototype.push,t)},t.prototype.unshiftTask=function(t){this.addTask_(Array.prototype.unshift,t)},t.prototype.runTasksImmediately=function(){this.runTasks_()},t.prototype.hasPendingTasks=function(){return this.taskQueue_.length>0},t.prototype.clearPendingTasks=function(){this.taskQueue_=[],this.cancelScheduledRun_()},t.prototype.getState=function(){return this.state_},t.prototype.destroy=function(){this.taskQueue_=[],this.cancelScheduledRun_(),this.ensureTasksRun_&&(removeEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&removeEventListener("beforeunload",this.runTasksImmediately,!0))},t.prototype.addTask_=function(t,e,i){var n=(void 0===i?{}:i).minTaskTime,s=void 0===n?this.defaultMinTaskTime_:n,r={time:d(),visibilityState:document.visibilityState};t.call(this.taskQueue_,{state:r,task:e,minTaskTime:s}),this.scheduleTasksToRun_()},t.prototype.scheduleTasksToRun_=function(){this.ensureTasksRun_&&"hidden"===document.visibilityState?v(this.runTasks_):this.idleCallbackHandle_||(this.idleCallbackHandle_=l(this.runTasks_))},t.prototype.runTasks_=function(t){if(this.cancelScheduledRun_(),!this.isProcessing_){for(this.isProcessing_=!0;this.hasPendingTasks()&&!k(t,this.taskQueue_[0].minTaskTime);){var e=this.taskQueue_.shift(),i=e.task,n=e.state;this.state_=n,i(n),this.state_=null}this.isProcessing_=!1,this.hasPendingTasks()&&this.scheduleTasksToRun_()}},t.prototype.cancelScheduledRun_=function(){m(this.idleCallbackHandle_),this.idleCallbackHandle_=null},t.prototype.onVisibilityChange_=function(){"hidden"===document.visibilityState&&this.runTasksImmediately()},t}(),k=function(t,e){return!!(t&&t.timeRemaining()<=e)},C=function(){function t(t){this.config=t}return t.supported=function(){return window.performance&&!!performance.now&&!!performance.mark},t.supportedPerformanceObserver=function(){return window.chrome&&"PerformanceObserver"in window},t.prototype.now=function(){return window.performance.now()},t.prototype.mark=function(t,e){var i="mark_"+t+"_"+e;window.performance.mark(i)},t.prototype.measure=function(t,e){var i="mark_"+t+"_start",n="mark_"+t+"_end";return window.performance.measure(t,i,n),this.getDurationByMetric(t,e)},t.prototype.performanceObserver=function(t,e){return this.perfObserver=new PerformanceObserver(this.performanceObserverCb.bind(this,e)),this.perfObserver.observe({type:t,buffered:!0}),this.perfObserver},t.prototype.getDurationByMetric=function(t,e){var i=this.getMeasurementForGivenName(t);return i&&"measure"===i.entryType?i.duration:-1},t.prototype.getMeasurementForGivenName=function(t){var e=window.performance.getEntriesByName(t);return e[e.length-1]},t.prototype.performanceObserverCb=function(t,e){t(e.getEntries())},t}(),_=function(){function t(t){var e=this;void 0===t&&(t={}),this.config={firstContentfulPaint:!1,firstPaint:!1,firstInputDelay:!1,dataConsumption:!1,googleAnalytics:{enable:!1,timingVar:"name"},browserTracker:!1,logPrefix:"Perfume.js:",logging:!0,maxMeasureTime:15e3,maxDataConsumption:2e4,warning:!1,debugging:!1},this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.dataConsumption=0,this.isHidden=!1,this.logMetricWarn="Please provide a metric name",this.metrics={},this.observers={},this.perfObservers={},this.didVisibilityChange=function(){document.hidden&&(e.isHidden=document.hidden)},this.config=Object.assign({},this.config,t),this.perf=new C(this.config),C.supported()&&(this.config.browserTracker&&(this.browser=o()),C.supportedPerformanceObserver()&&((this.config.firstPaint||this.config.firstContentfulPaint)&&(this.observeFirstContentfulPaint=new Promise((function(t){e.logDebug("observeFirstContentfulPaint"),e.observers.firstPaint=t,e.observers.firstContentfulPaint=t,e.initFirstPaint()}))),this.observeFirstInputDelay=new Promise((function(t){e.observers.firstInputDelay=t,e.initFirstInputDelay()})),this.config.dataConsumption&&(this.observeDataConsumption=new Promise((function(t){e.observers.dataConsumption=t,e.initDataConsumption()})))),this.onVisibilityChange(),this.queue=new T({ensureTasksRun:!0}))}return t.prototype.start=function(t){this.checkMetricName(t)&&(this.metrics[t]?this.logWarn("Recording already started."):(this.metrics[t]={end:0,start:this.perf.now()},this.perf.mark(t,"start"),this.isHidden=!1))},t.prototype.end=function(t){var e=this;if(this.checkMetricName(t)){var i=this.metrics[t];if(i){i.end=this.perf.now(),this.perf.mark(t,"end");var n=this.perf.measure(t,i),s=parseFloat(n.toFixed(2));return delete this.metrics[t],this.queue.pushTask((function(){e.log(t,s),e.sendTiming(t,s)})),s}this.logWarn("Recording already stopped.")}},t.prototype.endPaint=function(t){var e=this;return new Promise((function(i){setTimeout((function(){var n=e.end(t);i(n)}))}))},t.prototype.log=function(t,e){if(!this.isHidden&&this.config.logging)if(t){var i=e.toFixed(2),n="%c "+this.config.logPrefix+" "+t+" "+i+" ms";window.console.log(n,"color: #ff6d00;font-size:11px;")}else this.logWarn(this.logMetricWarn)},t.prototype.logDebug=function(t,e){void 0===e&&(e=""),this.config.debugging&&window.console.log("Perfume.js debugging "+t+":",e)},t.prototype.sendTiming=function(t,e){if(!this.isHidden){var i=this.config.browserTracker?this.browser:void 0,n=this.addBrowserToMetricName(t);if(this.config.analyticsTracker&&this.config.analyticsTracker(t,e,i),this.config.googleAnalytics.enable)if(window.ga){var s=Math.round(e);window.ga("send","timing",n,this.config.googleAnalytics.timingVar,s)}else this.logWarn("Google Analytics has not been loaded")}},t.prototype.addBrowserToMetricName=function(t){if(!this.config.browserTracker)return t;var e=t;this.browser.name&&(e+="."+this.browser.name.replace(/\s/g,""),this.browser.os&&(e+="."+this.browser.os.replace(/\s/g,"")));return e},t.prototype.checkMetricName=function(t){return!!t||(this.logWarn(this.logMetricWarn),!1)},t.prototype.performanceObserverCb=function(t){var e=this;this.logDebug("performanceObserverCb",t),t.entries.forEach((function(i){e.queue.pushTask((function(){e.config[t.metricName]&&(!t.entryName||t.entryName&&i.name===t.entryName)&&e.logMetric(i[t.valueLog],t.metricLog,t.metricName)})),e.perfObservers.firstContentfulPaint&&"first-contentful-paint"===i.name&&e.perfObservers.firstContentfulPaint.disconnect()})),this.perfObservers.firstInputDelay&&"firstInputDelay"===t.metricName&&this.perfObservers.firstInputDelay.disconnect()},t.prototype.performanceObserverResourceCb=function(t){var e=this;this.logDebug("performanceObserverResourceCb",t),t.entries.forEach((function(t){if(t.decodedBodySize){var i=parseFloat((t.decodedBodySize/1e3).toFixed(2));e.dataConsumption+=i}}))},t.prototype.digestFirstPaintEntries=function(t){this.performanceObserverCb({entries:t,entryName:"first-paint",metricLog:"First Paint",metricName:"firstPaint",valueLog:"startTime"}),this.performanceObserverCb({entries:t,entryName:"first-contentful-paint",metricLog:"First Contentful Paint",metricName:"firstContentfulPaint",valueLog:"startTime"})},t.prototype.initFirstPaint=function(){this.logDebug("initFirstPaint");try{this.perfObservers.firstContentfulPaint=this.perf.performanceObserver("paint",this.digestFirstPaintEntries)}catch(t){this.logWarn("initFirstPaint failed")}},t.prototype.digestFirstInputDelayEntries=function(t){this.performanceObserverCb({entries:t,metricLog:"First Input Delay",metricName:"firstInputDelay",valueLog:"duration"}),this.disconnectDataConsumption()},t.prototype.initFirstInputDelay=function(){try{this.perfObservers.firstInputDelay=this.perf.performanceObserver("first-input",this.digestFirstInputDelayEntries)}catch(t){this.logWarn("initFirstInputDelay failed")}},t.prototype.digestDataConsumptionEntries=function(t){this.performanceObserverResourceCb({entries:t})},t.prototype.disconnectDataConsumption=function(){clearTimeout(this.dataConsumptionTimeout),this.perfObservers.dataConsumption&&this.dataConsumption&&(this.logMetric(this.dataConsumption,"Data Consumption","dataConsumption"),this.perfObservers.dataConsumption.disconnect())},t.prototype.initDataConsumption=function(){var t=this;try{this.perfObservers.dataConsumption=this.perf.performanceObserver("resource",this.digestDataConsumptionEntries)}catch(t){this.logWarn("initDataConsumption failed")}this.dataConsumptionTimeout=setTimeout((function(){t.disconnectDataConsumption()}),15e3)},t.prototype.onVisibilityChange=function(){void 0!==document.hidden&&document.addEventListener("visibilitychange",this.didVisibilityChange)},t.prototype.logMetric=function(t,e,i){var n=parseFloat(t.toFixed(2));"dataConsumption"!==i&&n>this.config.maxMeasureTime||"dataConsumption"===i&&n>this.config.maxDataConsumption||("firstPaint"===i&&(this.firstPaintDuration=n),"firstContentfulPaint"===i&&(this.firstContentfulPaintDuration=n),"firstInputDelay"===i&&(this.firstInputDelayDuration=n),this.observers[i](n),this.log(e,n),this.sendTiming(i,n))},t.prototype.logWarn=function(t){this.config.warning&&this.config.logging&&window.console.warn(this.config.logPrefix,t)},t}();export default _; | ||
//# sourceMappingURL=perfume.esm.min.js.map |
@@ -1,2 +0,2 @@ | ||
var Perfume=function(){"use strict";var e=function(e,i,t){this.name=e,this.version=i,this.os=t},i=function(e){this.version=e,this.name="node",this.os=process.platform},t=function(){this.bot=!0,this.name="bot",this.version=null,this.os=null},n=3,r=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["vivaldi",/Vivaldi\/([0-9\.]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FBAV\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["searchbot",/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/]],s=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/],["Search Bot",/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/]];function o(){return"undefined"!=typeof navigator?function(i){var o=""!==i&&r.reduce((function(e,t){var n=t[0],r=t[1];if(e)return e;var s=r.exec(i);return!!s&&[n,s]}),!1);if(!o)return null;var a=o[0],u=o[1];if("searchbot"===a)return new t;var c=u[1]&&u[1].split(/[._]/).slice(0,3);c?c.length<n&&(c=c.concat(new Array(n-c.length).fill("0"))):c=[];return new e(a,c.join("."),function(e){var i=s.find((function(i){i[0];return i[1].test(e)}));return i?i[0]:null}(i))}(navigator.userAgent):"undefined"!=typeof process&&process.version?new i(process.version.slice(1)):null}var a,u,c,f,d=function(){return+new Date},h="function"==typeof window.requestIdleCallback,l=function(){function e(e){this.initTime_=e}return Object.defineProperty(e.prototype,"didTimeout",{get:function(){return!1},enumerable:!0,configurable:!0}),e.prototype.timeRemaining=function(){return Math.max(0,50-(d()-this.initTime_))},e}(),p=h?window.requestIdleCallback:function(e){var i=new l(d());return setTimeout((function(){return e(i)}),0)},g=h?window.cancelIdleCallback:function(e){clearTimeout(e)},m="function"==typeof Promise&&Promise.toString().indexOf("[native code]")>-1,b="MutationObserver"in window||"WebKitMutationObserver"in window||"MozMutationObserver"in window,v=m?function(e){Promise.resolve().then(e)}:b?(a=0,u=[],c=new MutationObserver((function(){u.forEach((function(e){return e()})),u=[]})),f=document.createTextNode(""),c.observe(f,{characterData:!0}),function(e){u.push(e),f.data=String(++a%2)}):function(e){},y=0,w=!("object"!=typeof window.safari||!window.safari.pushNotification),k=function(){function e(e){var i=void 0===e?{}:e,t=i.ensureTasksRun,n=void 0!==t&&t,r=i.defaultMinTaskTime,s=void 0===r?y:r;this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.idleCallbackHandle_=null,this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.defaultMinTaskTime_=s,this.ensureTasksRun_=n,this.runTasksImmediately=this.runTasksImmediately.bind(this),this.runTasks_=this.runTasks_.bind(this),this.onVisibilityChange_=this.onVisibilityChange_.bind(this),this.ensureTasksRun_&&(addEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&addEventListener("beforeunload",this.runTasksImmediately,!0))}return e.prototype.pushTask=function(e){this.addTask_(Array.prototype.push,e)},e.prototype.unshiftTask=function(e){this.addTask_(Array.prototype.unshift,e)},e.prototype.runTasksImmediately=function(){this.runTasks_()},e.prototype.hasPendingTasks=function(){return this.taskQueue_.length>0},e.prototype.clearPendingTasks=function(){this.taskQueue_=[],this.cancelScheduledRun_()},e.prototype.getState=function(){return this.state_},e.prototype.destroy=function(){this.taskQueue_=[],this.cancelScheduledRun_(),this.ensureTasksRun_&&(removeEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&removeEventListener("beforeunload",this.runTasksImmediately,!0))},e.prototype.addTask_=function(e,i,t){var n=(void 0===t?{}:t).minTaskTime,r=void 0===n?this.defaultMinTaskTime_:n,s={time:d(),visibilityState:document.visibilityState};e.call(this.taskQueue_,{state:s,task:i,minTaskTime:r}),this.scheduleTasksToRun_()},e.prototype.scheduleTasksToRun_=function(){this.ensureTasksRun_&&"hidden"===document.visibilityState?v(this.runTasks_):this.idleCallbackHandle_||(this.idleCallbackHandle_=p(this.runTasks_))},e.prototype.runTasks_=function(e){if(this.cancelScheduledRun_(),!this.isProcessing_){for(this.isProcessing_=!0;this.hasPendingTasks()&&!T(e,this.taskQueue_[0].minTaskTime);){var i=this.taskQueue_.shift(),t=i.task,n=i.state;this.state_=n,t(n),this.state_=null}this.isProcessing_=!1,this.hasPendingTasks()&&this.scheduleTasksToRun_()}},e.prototype.cancelScheduledRun_=function(){g(this.idleCallbackHandle_),this.idleCallbackHandle_=null},e.prototype.onVisibilityChange_=function(){"hidden"===document.visibilityState&&this.runTasksImmediately()},e}(),T=function(e,i){return!!(e&&e.timeRemaining()<=i)},_=function(){function e(e){this.config=e}return e.supported=function(){return window.performance&&!!performance.now&&!!performance.mark},e.supportedPerformanceObserver=function(){return window.chrome&&"PerformanceObserver"in window},e.prototype.now=function(){return window.performance.now()},e.prototype.mark=function(e,i){var t="mark_"+e+"_"+i;window.performance.mark(t)},e.prototype.measure=function(e,i){var t="mark_"+e+"_start",n="mark_"+e+"_end";return window.performance.measure(e,t,n),this.getDurationByMetric(e,i)},e.prototype.performanceObserver=function(e,i){return this.perfObserver=new PerformanceObserver(this.performanceObserverCb.bind(this,i)),this.perfObserver.observe({type:e,buffered:!0}),this.perfObserver},e.prototype.getDurationByMetric=function(e,i){var t=this.getMeasurementForGivenName(e);return t&&"measure"===t.entryType?t.duration:-1},e.prototype.getMeasurementForGivenName=function(e){var i=window.performance.getEntriesByName(e);return i[i.length-1]},e.prototype.performanceObserverCb=function(e,i){e(i.getEntries())},e}();return function(){function e(e){var i=this;void 0===e&&(e={}),this.config={firstContentfulPaint:!1,firstPaint:!1,firstInputDelay:!1,pageResource:!1,googleAnalytics:{enable:!1,timingVar:"name"},browserTracker:!1,logPrefix:"Perfume.js:",logging:!0,maxMeasureTime:15e3,warning:!1,debugging:!1},this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.pageResourceDecodedBodySize=0,this.isHidden=!1,this.logMetricWarn="Please provide a metric name",this.metrics={},this.observers={},this.perfObservers={},this.didVisibilityChange=function(){document.hidden&&(i.isHidden=document.hidden)},this.config=Object.assign({},this.config,e),this.perf=new _(this.config),_.supported()&&(this.config.browserTracker&&(this.browser=o()),_.supportedPerformanceObserver()&&((this.config.firstPaint||this.config.firstContentfulPaint)&&(this.observeFirstContentfulPaint=new Promise((function(e){i.logDebug("observeFirstContentfulPaint"),i.observers.fcp=e,i.initFirstPaint()}))),this.config.firstInputDelay&&(this.observeFirstInputDelay=new Promise((function(e){i.observers.fid=e,i.initFirstInputDelay()}))),this.config.pageResource&&this.initPageResource()),this.onVisibilityChange(),this.queue=new k({ensureTasksRun:!0}))}return e.prototype.start=function(e){this.checkMetricName(e)&&(this.metrics[e]?this.logWarn("Recording already started."):(this.metrics[e]={end:0,start:this.perf.now()},this.perf.mark(e,"start"),this.isHidden=!1))},e.prototype.end=function(e){var i=this;if(this.checkMetricName(e)){var t=this.metrics[e];if(t){t.end=this.perf.now(),this.perf.mark(e,"end");var n=this.perf.measure(e,t),r=parseFloat(n.toFixed(2));return delete this.metrics[e],this.queue.pushTask((function(){i.log(e,r),i.sendTiming(e,r)})),r}this.logWarn("Recording already stopped.")}},e.prototype.endPaint=function(e){var i=this;return new Promise((function(t){setTimeout((function(){var n=i.end(e);t(n)}))}))},e.prototype.log=function(e,i){if(!this.isHidden&&this.config.logging)if(e){var t=i.toFixed(2),n="%c "+this.config.logPrefix+" "+e+" "+t+" ms";window.console.log(n,"color: #ff6d00;font-size:11px;")}else this.logWarn(this.logMetricWarn)},e.prototype.logDebug=function(e,i){void 0===i&&(i=""),this.config.debugging&&window.console.log("Perfume.js debugging "+e+":",i)},e.prototype.sendTiming=function(e,i){if(!this.isHidden){var t=this.config.browserTracker?this.browser:void 0,n=this.addBrowserToMetricName(e);if(this.config.analyticsTracker&&this.config.analyticsTracker(e,i,t),this.config.googleAnalytics.enable)if(window.ga){var r=Math.round(i);window.ga("send","timing",n,this.config.googleAnalytics.timingVar,r)}else this.logWarn("Google Analytics has not been loaded")}},e.prototype.addBrowserToMetricName=function(e){if(!this.config.browserTracker)return e;var i=e;this.browser.name&&(i+="."+this.browser.name.replace(/\s/g,""),this.browser.os&&(i+="."+this.browser.os.replace(/\s/g,"")));return i},e.prototype.checkMetricName=function(e){return!!e||(this.logWarn(this.logMetricWarn),!1)},e.prototype.performanceObserverCb=function(e){var i=this;this.logDebug("performanceObserverCb",e),e.entries.forEach((function(t){i.queue.pushTask((function(){i.config[e.metricName]&&(!e.entryName||e.entryName&&t.name===e.entryName)&&i.logMetric(t[e.valueLog],e.metricLog,e.metricName)})),"first-contentful-paint"===t.name&&i.perfObservers.fcp.disconnect()})),"first-input"===e.entryName&&this.perfObservers.fid.disconnect()},e.prototype.performanceObserverResourceCb=function(e){var i=this;this.logDebug("performanceObserverResourceCb",e),e.entries.forEach((function(e){if(e.decodedBodySize){var t=parseFloat((e.decodedBodySize/1e3).toFixed(2));i.pageResourceDecodedBodySize+=t}}))},e.prototype.initFirstPaint=function(){var e=this;this.logDebug("initFirstPaint");try{this.perfObservers.fcp=this.perf.performanceObserver("paint",(function(i){e.performanceObserverCb({entries:i,entryName:"first-paint",metricLog:"First Paint",metricName:"firstPaint",valueLog:"startTime"}),e.performanceObserverCb({entries:i,entryName:"first-contentful-paint",metricLog:"First Contentful Paint",metricName:"firstContentfulPaint",valueLog:"startTime"})}))}catch(e){this.logWarn("initFirstPaint failed")}},e.prototype.initFirstInputDelay=function(){var e=this;try{this.perfObservers.fid=this.perf.performanceObserver("first-input",(function(i){e.performanceObserverCb({entries:i,metricLog:"First Input Delay",metricName:"firstInputDelay",valueLog:"duration"})}))}catch(e){this.logWarn("initFirstInputDelay failed")}},e.prototype.initPageResource=function(){var e=this;try{this.perfObservers.pageResource=this.perf.performanceObserver("resource",(function(i){e.performanceObserverResourceCb({entries:i})})),setTimeout((function(){e.perfObservers.pageResource.disconnect()}),5e3)}catch(e){this.logWarn("initPageResource failed")}},e.prototype.onVisibilityChange=function(){void 0!==document.hidden&&document.addEventListener("visibilitychange",this.didVisibilityChange)},e.prototype.logMetric=function(e,i,t){var n=parseFloat(e.toFixed(2));n>this.config.maxMeasureTime||("firstPaint"===t&&(this.firstPaintDuration=n),"firstContentfulPaint"===t&&(this.firstContentfulPaintDuration=n,this.observers.fcp(n)),"firstInputDelay"===t&&(this.firstInputDelayDuration=n,this.observers.fid(n)),this.log(i,n),this.sendTiming(t,n))},e.prototype.logWarn=function(e){this.config.warning&&this.config.logging&&window.console.warn(this.config.logPrefix,e)},e}()}(); | ||
var Perfume=function(){"use strict";var t=function(t,e,i){this.name=t,this.version=e,this.os=i},e=function(t){this.version=t,this.name="node",this.os=process.platform},i=function(){this.bot=!0,this.name="bot",this.version=null,this.os=null},n=3,s=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["vivaldi",/Vivaldi\/([0-9\.]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FBAV\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["searchbot",/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/]],r=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/],["Search Bot",/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/]];function o(){return"undefined"!=typeof navigator?function(e){var o=""!==e&&s.reduce((function(t,i){var n=i[0],s=i[1];if(t)return t;var r=s.exec(e);return!!r&&[n,r]}),!1);if(!o)return null;var a=o[0],u=o[1];if("searchbot"===a)return new i;var c=u[1]&&u[1].split(/[._]/).slice(0,3);c?c.length<n&&(c=c.concat(new Array(n-c.length).fill("0"))):c=[];return new t(a,c.join("."),function(t){var e=r.find((function(e){e[0];return e[1].test(t)}));return e?e[0]:null}(e))}(navigator.userAgent):"undefined"!=typeof process&&process.version?new e(process.version.slice(1)):null}var a,u,c,f,d=function(){return+new Date},h="function"==typeof window.requestIdleCallback,p=function(){function t(t){this.initTime_=t}return Object.defineProperty(t.prototype,"didTimeout",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype.timeRemaining=function(){return Math.max(0,50-(d()-this.initTime_))},t}(),l=h?window.requestIdleCallback:function(t){var e=new p(d());return setTimeout((function(){return t(e)}),0)},m=h?window.cancelIdleCallback:function(t){clearTimeout(t)},g="function"==typeof Promise&&Promise.toString().indexOf("[native code]")>-1,b="MutationObserver"in window||"WebKitMutationObserver"in window||"MozMutationObserver"in window,v=g?function(t){Promise.resolve().then(t)}:b?(a=0,u=[],c=new MutationObserver((function(){u.forEach((function(t){return t()})),u=[]})),f=document.createTextNode(""),c.observe(f,{characterData:!0}),function(t){u.push(t),f.data=String(++a%2)}):function(t){},y=0,w=!("object"!=typeof window.safari||!window.safari.pushNotification),T=function(){function t(t){var e=void 0===t?{}:t,i=e.ensureTasksRun,n=void 0!==i&&i,s=e.defaultMinTaskTime,r=void 0===s?y:s;this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.idleCallbackHandle_=null,this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.defaultMinTaskTime_=r,this.ensureTasksRun_=n,this.runTasksImmediately=this.runTasksImmediately.bind(this),this.runTasks_=this.runTasks_.bind(this),this.onVisibilityChange_=this.onVisibilityChange_.bind(this),this.ensureTasksRun_&&(addEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&addEventListener("beforeunload",this.runTasksImmediately,!0))}return t.prototype.pushTask=function(t){this.addTask_(Array.prototype.push,t)},t.prototype.unshiftTask=function(t){this.addTask_(Array.prototype.unshift,t)},t.prototype.runTasksImmediately=function(){this.runTasks_()},t.prototype.hasPendingTasks=function(){return this.taskQueue_.length>0},t.prototype.clearPendingTasks=function(){this.taskQueue_=[],this.cancelScheduledRun_()},t.prototype.getState=function(){return this.state_},t.prototype.destroy=function(){this.taskQueue_=[],this.cancelScheduledRun_(),this.ensureTasksRun_&&(removeEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&removeEventListener("beforeunload",this.runTasksImmediately,!0))},t.prototype.addTask_=function(t,e,i){var n=(void 0===i?{}:i).minTaskTime,s=void 0===n?this.defaultMinTaskTime_:n,r={time:d(),visibilityState:document.visibilityState};t.call(this.taskQueue_,{state:r,task:e,minTaskTime:s}),this.scheduleTasksToRun_()},t.prototype.scheduleTasksToRun_=function(){this.ensureTasksRun_&&"hidden"===document.visibilityState?v(this.runTasks_):this.idleCallbackHandle_||(this.idleCallbackHandle_=l(this.runTasks_))},t.prototype.runTasks_=function(t){if(this.cancelScheduledRun_(),!this.isProcessing_){for(this.isProcessing_=!0;this.hasPendingTasks()&&!k(t,this.taskQueue_[0].minTaskTime);){var e=this.taskQueue_.shift(),i=e.task,n=e.state;this.state_=n,i(n),this.state_=null}this.isProcessing_=!1,this.hasPendingTasks()&&this.scheduleTasksToRun_()}},t.prototype.cancelScheduledRun_=function(){m(this.idleCallbackHandle_),this.idleCallbackHandle_=null},t.prototype.onVisibilityChange_=function(){"hidden"===document.visibilityState&&this.runTasksImmediately()},t}(),k=function(t,e){return!!(t&&t.timeRemaining()<=e)},C=function(){function t(t){this.config=t}return t.supported=function(){return window.performance&&!!performance.now&&!!performance.mark},t.supportedPerformanceObserver=function(){return window.chrome&&"PerformanceObserver"in window},t.prototype.now=function(){return window.performance.now()},t.prototype.mark=function(t,e){var i="mark_"+t+"_"+e;window.performance.mark(i)},t.prototype.measure=function(t,e){var i="mark_"+t+"_start",n="mark_"+t+"_end";return window.performance.measure(t,i,n),this.getDurationByMetric(t,e)},t.prototype.performanceObserver=function(t,e){return this.perfObserver=new PerformanceObserver(this.performanceObserverCb.bind(this,e)),this.perfObserver.observe({type:t,buffered:!0}),this.perfObserver},t.prototype.getDurationByMetric=function(t,e){var i=this.getMeasurementForGivenName(t);return i&&"measure"===i.entryType?i.duration:-1},t.prototype.getMeasurementForGivenName=function(t){var e=window.performance.getEntriesByName(t);return e[e.length-1]},t.prototype.performanceObserverCb=function(t,e){t(e.getEntries())},t}();return function(){function t(t){var e=this;void 0===t&&(t={}),this.config={firstContentfulPaint:!1,firstPaint:!1,firstInputDelay:!1,dataConsumption:!1,googleAnalytics:{enable:!1,timingVar:"name"},browserTracker:!1,logPrefix:"Perfume.js:",logging:!0,maxMeasureTime:15e3,maxDataConsumption:2e4,warning:!1,debugging:!1},this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.dataConsumption=0,this.isHidden=!1,this.logMetricWarn="Please provide a metric name",this.metrics={},this.observers={},this.perfObservers={},this.didVisibilityChange=function(){document.hidden&&(e.isHidden=document.hidden)},this.config=Object.assign({},this.config,t),this.perf=new C(this.config),C.supported()&&(this.config.browserTracker&&(this.browser=o()),C.supportedPerformanceObserver()&&((this.config.firstPaint||this.config.firstContentfulPaint)&&(this.observeFirstContentfulPaint=new Promise((function(t){e.logDebug("observeFirstContentfulPaint"),e.observers.firstPaint=t,e.observers.firstContentfulPaint=t,e.initFirstPaint()}))),this.observeFirstInputDelay=new Promise((function(t){e.observers.firstInputDelay=t,e.initFirstInputDelay()})),this.config.dataConsumption&&(this.observeDataConsumption=new Promise((function(t){e.observers.dataConsumption=t,e.initDataConsumption()})))),this.onVisibilityChange(),this.queue=new T({ensureTasksRun:!0}))}return t.prototype.start=function(t){this.checkMetricName(t)&&(this.metrics[t]?this.logWarn("Recording already started."):(this.metrics[t]={end:0,start:this.perf.now()},this.perf.mark(t,"start"),this.isHidden=!1))},t.prototype.end=function(t){var e=this;if(this.checkMetricName(t)){var i=this.metrics[t];if(i){i.end=this.perf.now(),this.perf.mark(t,"end");var n=this.perf.measure(t,i),s=parseFloat(n.toFixed(2));return delete this.metrics[t],this.queue.pushTask((function(){e.log(t,s),e.sendTiming(t,s)})),s}this.logWarn("Recording already stopped.")}},t.prototype.endPaint=function(t){var e=this;return new Promise((function(i){setTimeout((function(){var n=e.end(t);i(n)}))}))},t.prototype.log=function(t,e){if(!this.isHidden&&this.config.logging)if(t){var i=e.toFixed(2),n="%c "+this.config.logPrefix+" "+t+" "+i+" ms";window.console.log(n,"color: #ff6d00;font-size:11px;")}else this.logWarn(this.logMetricWarn)},t.prototype.logDebug=function(t,e){void 0===e&&(e=""),this.config.debugging&&window.console.log("Perfume.js debugging "+t+":",e)},t.prototype.sendTiming=function(t,e){if(!this.isHidden){var i=this.config.browserTracker?this.browser:void 0,n=this.addBrowserToMetricName(t);if(this.config.analyticsTracker&&this.config.analyticsTracker(t,e,i),this.config.googleAnalytics.enable)if(window.ga){var s=Math.round(e);window.ga("send","timing",n,this.config.googleAnalytics.timingVar,s)}else this.logWarn("Google Analytics has not been loaded")}},t.prototype.addBrowserToMetricName=function(t){if(!this.config.browserTracker)return t;var e=t;this.browser.name&&(e+="."+this.browser.name.replace(/\s/g,""),this.browser.os&&(e+="."+this.browser.os.replace(/\s/g,"")));return e},t.prototype.checkMetricName=function(t){return!!t||(this.logWarn(this.logMetricWarn),!1)},t.prototype.performanceObserverCb=function(t){var e=this;this.logDebug("performanceObserverCb",t),t.entries.forEach((function(i){e.queue.pushTask((function(){e.config[t.metricName]&&(!t.entryName||t.entryName&&i.name===t.entryName)&&e.logMetric(i[t.valueLog],t.metricLog,t.metricName)})),e.perfObservers.firstContentfulPaint&&"first-contentful-paint"===i.name&&e.perfObservers.firstContentfulPaint.disconnect()})),this.perfObservers.firstInputDelay&&"firstInputDelay"===t.metricName&&this.perfObservers.firstInputDelay.disconnect()},t.prototype.performanceObserverResourceCb=function(t){var e=this;this.logDebug("performanceObserverResourceCb",t),t.entries.forEach((function(t){if(t.decodedBodySize){var i=parseFloat((t.decodedBodySize/1e3).toFixed(2));e.dataConsumption+=i}}))},t.prototype.digestFirstPaintEntries=function(t){this.performanceObserverCb({entries:t,entryName:"first-paint",metricLog:"First Paint",metricName:"firstPaint",valueLog:"startTime"}),this.performanceObserverCb({entries:t,entryName:"first-contentful-paint",metricLog:"First Contentful Paint",metricName:"firstContentfulPaint",valueLog:"startTime"})},t.prototype.initFirstPaint=function(){this.logDebug("initFirstPaint");try{this.perfObservers.firstContentfulPaint=this.perf.performanceObserver("paint",this.digestFirstPaintEntries)}catch(t){this.logWarn("initFirstPaint failed")}},t.prototype.digestFirstInputDelayEntries=function(t){this.performanceObserverCb({entries:t,metricLog:"First Input Delay",metricName:"firstInputDelay",valueLog:"duration"}),this.disconnectDataConsumption()},t.prototype.initFirstInputDelay=function(){try{this.perfObservers.firstInputDelay=this.perf.performanceObserver("first-input",this.digestFirstInputDelayEntries)}catch(t){this.logWarn("initFirstInputDelay failed")}},t.prototype.digestDataConsumptionEntries=function(t){this.performanceObserverResourceCb({entries:t})},t.prototype.disconnectDataConsumption=function(){clearTimeout(this.dataConsumptionTimeout),this.perfObservers.dataConsumption&&this.dataConsumption&&(this.logMetric(this.dataConsumption,"Data Consumption","dataConsumption"),this.perfObservers.dataConsumption.disconnect())},t.prototype.initDataConsumption=function(){var t=this;try{this.perfObservers.dataConsumption=this.perf.performanceObserver("resource",this.digestDataConsumptionEntries)}catch(t){this.logWarn("initDataConsumption failed")}this.dataConsumptionTimeout=setTimeout((function(){t.disconnectDataConsumption()}),15e3)},t.prototype.onVisibilityChange=function(){void 0!==document.hidden&&document.addEventListener("visibilitychange",this.didVisibilityChange)},t.prototype.logMetric=function(t,e,i){var n=parseFloat(t.toFixed(2));"dataConsumption"!==i&&n>this.config.maxMeasureTime||"dataConsumption"===i&&n>this.config.maxDataConsumption||("firstPaint"===i&&(this.firstPaintDuration=n),"firstContentfulPaint"===i&&(this.firstContentfulPaintDuration=n),"firstInputDelay"===i&&(this.firstInputDelayDuration=n),this.observers[i](n),this.log(e,n),this.sendTiming(i,n))},t.prototype.logWarn=function(t){this.config.warning&&this.config.logging&&window.console.warn(this.config.logPrefix,t)},t}()}(); | ||
//# sourceMappingURL=perfume.iife.min.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var BrowserInfo=function(e,i,t){this.name=e,this.version=i,this.os=t},NodeInfo=function(e){this.version=e,this.name="node",this.os=process.platform},BotInfo=function(){this.bot=!0,this.name="bot",this.version=null,this.os=null},SEARCHBOX_UA_REGEX=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,SEARCHBOT_OS_REGEX=/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/,REQUIRED_VERSION_PARTS=3,userAgentRules=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["vivaldi",/Vivaldi\/([0-9\.]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FBAV\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["searchbot",SEARCHBOX_UA_REGEX]],operatingSystemRules=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/],["Search Bot",SEARCHBOT_OS_REGEX]];function detect(){return"undefined"!=typeof navigator?parseUserAgent(navigator.userAgent):getNodeVersion()}function parseUserAgent(e){var i=""!==e&&userAgentRules.reduce((function(i,t){var n=t[0],r=t[1];if(i)return i;var s=r.exec(e);return!!s&&[n,s]}),!1);if(!i)return null;var t=i[0],n=i[1];if("searchbot"===t)return new BotInfo;var r=n[1]&&n[1].split(/[._]/).slice(0,3);return r?r.length<REQUIRED_VERSION_PARTS&&(r=r.concat(new Array(REQUIRED_VERSION_PARTS-r.length).fill("0"))):r=[],new BrowserInfo(t,r.join("."),detectOS(e))}function detectOS(e){var i=operatingSystemRules.find((function(i){i[0];return i[1].test(e)}));return i?i[0]:null}function getNodeVersion(){return"undefined"!=typeof process&&process.version?new NodeInfo(process.version.slice(1)):null}var now=function(){return+new Date},supportsRequestIdleCallback_="function"==typeof window.requestIdleCallback,IdleDealine=function(){function e(e){this.initTime_=e}return Object.defineProperty(e.prototype,"didTimeout",{get:function(){return!1},enumerable:!0,configurable:!0}),e.prototype.timeRemaining=function(){return Math.max(0,50-(now()-this.initTime_))},e}(),requestIdleCallbackShim=function(e){var i=new IdleDealine(now());return setTimeout((function(){return e(i)}),0)},cancelIdleCallbackShim=function(e){clearTimeout(e)},rIC=supportsRequestIdleCallback_?window.requestIdleCallback:requestIdleCallbackShim,cIC=supportsRequestIdleCallback_?window.cancelIdleCallback:cancelIdleCallbackShim,supportsPromisesNatively="function"==typeof Promise&&Promise.toString().indexOf("[native code]")>-1,supportsMutationObserver="MutationObserver"in window||"WebKitMutationObserver"in window||"MozMutationObserver"in window,createQueueMicrotaskViaPromises=function(){return function(e){Promise.resolve().then(e)}},createQueueMicrotaskViaMutationObserver=function(){var e=0,i=[],t=new MutationObserver((function(){i.forEach((function(e){return e()})),i=[]})),n=document.createTextNode("");return t.observe(n,{characterData:!0}),function(t){i.push(t),n.data=String(++e%2)}},discardMicrotasks=function(){return function(e){}},queueMicrotask=supportsPromisesNatively?createQueueMicrotaskViaPromises():supportsMutationObserver?createQueueMicrotaskViaMutationObserver():discardMicrotasks(),DEFAULT_MIN_TASK_TIME=0,isSafari_=!("object"!=typeof window.safari||!window.safari.pushNotification),IdleQueue=function(){function e(e){var i=void 0===e?{}:e,t=i.ensureTasksRun,n=void 0!==t&&t,r=i.defaultMinTaskTime,s=void 0===r?DEFAULT_MIN_TASK_TIME:r;this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.idleCallbackHandle_=null,this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.defaultMinTaskTime_=s,this.ensureTasksRun_=n,this.runTasksImmediately=this.runTasksImmediately.bind(this),this.runTasks_=this.runTasks_.bind(this),this.onVisibilityChange_=this.onVisibilityChange_.bind(this),this.ensureTasksRun_&&(addEventListener("visibilitychange",this.onVisibilityChange_,!0),isSafari_&&addEventListener("beforeunload",this.runTasksImmediately,!0))}return e.prototype.pushTask=function(e){this.addTask_(Array.prototype.push,e)},e.prototype.unshiftTask=function(e){this.addTask_(Array.prototype.unshift,e)},e.prototype.runTasksImmediately=function(){this.runTasks_()},e.prototype.hasPendingTasks=function(){return this.taskQueue_.length>0},e.prototype.clearPendingTasks=function(){this.taskQueue_=[],this.cancelScheduledRun_()},e.prototype.getState=function(){return this.state_},e.prototype.destroy=function(){this.taskQueue_=[],this.cancelScheduledRun_(),this.ensureTasksRun_&&(removeEventListener("visibilitychange",this.onVisibilityChange_,!0),isSafari_&&removeEventListener("beforeunload",this.runTasksImmediately,!0))},e.prototype.addTask_=function(e,i,t){var n=(void 0===t?{}:t).minTaskTime,r=void 0===n?this.defaultMinTaskTime_:n,s={time:now(),visibilityState:document.visibilityState};e.call(this.taskQueue_,{state:s,task:i,minTaskTime:r}),this.scheduleTasksToRun_()},e.prototype.scheduleTasksToRun_=function(){this.ensureTasksRun_&&"hidden"===document.visibilityState?queueMicrotask(this.runTasks_):this.idleCallbackHandle_||(this.idleCallbackHandle_=rIC(this.runTasks_))},e.prototype.runTasks_=function(e){if(this.cancelScheduledRun_(),!this.isProcessing_){for(this.isProcessing_=!0;this.hasPendingTasks()&&!shouldYield(e,this.taskQueue_[0].minTaskTime);){var i=this.taskQueue_.shift(),t=i.task,n=i.state;this.state_=n,t(n),this.state_=null}this.isProcessing_=!1,this.hasPendingTasks()&&this.scheduleTasksToRun_()}},e.prototype.cancelScheduledRun_=function(){cIC(this.idleCallbackHandle_),this.idleCallbackHandle_=null},e.prototype.onVisibilityChange_=function(){"hidden"===document.visibilityState&&this.runTasksImmediately()},e}(),shouldYield=function(e,i){return!!(e&&e.timeRemaining()<=i)},Performance=function(){function e(e){this.config=e}return e.supported=function(){return window.performance&&!!performance.now&&!!performance.mark},e.supportedPerformanceObserver=function(){return window.chrome&&"PerformanceObserver"in window},e.prototype.now=function(){return window.performance.now()},e.prototype.mark=function(e,i){var t="mark_"+e+"_"+i;window.performance.mark(t)},e.prototype.measure=function(e,i){var t="mark_"+e+"_start",n="mark_"+e+"_end";return window.performance.measure(e,t,n),this.getDurationByMetric(e,i)},e.prototype.performanceObserver=function(e,i){return this.perfObserver=new PerformanceObserver(this.performanceObserverCb.bind(this,i)),this.perfObserver.observe({type:e,buffered:!0}),this.perfObserver},e.prototype.getDurationByMetric=function(e,i){var t=this.getMeasurementForGivenName(e);return t&&"measure"===t.entryType?t.duration:-1},e.prototype.getMeasurementForGivenName=function(e){var i=window.performance.getEntriesByName(e);return i[i.length-1]},e.prototype.performanceObserverCb=function(e,i){e(i.getEntries())},e}(),Perfume=function(){function e(e){var i=this;void 0===e&&(e={}),this.config={firstContentfulPaint:!1,firstPaint:!1,firstInputDelay:!1,pageResource:!1,googleAnalytics:{enable:!1,timingVar:"name"},browserTracker:!1,logPrefix:"Perfume.js:",logging:!0,maxMeasureTime:15e3,warning:!1,debugging:!1},this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.pageResourceDecodedBodySize=0,this.isHidden=!1,this.logMetricWarn="Please provide a metric name",this.metrics={},this.observers={},this.perfObservers={},this.didVisibilityChange=function(){document.hidden&&(i.isHidden=document.hidden)},this.config=Object.assign({},this.config,e),this.perf=new Performance(this.config),Performance.supported()&&(this.config.browserTracker&&(this.browser=detect()),Performance.supportedPerformanceObserver()&&((this.config.firstPaint||this.config.firstContentfulPaint)&&(this.observeFirstContentfulPaint=new Promise((function(e){i.logDebug("observeFirstContentfulPaint"),i.observers.fcp=e,i.initFirstPaint()}))),this.config.firstInputDelay&&(this.observeFirstInputDelay=new Promise((function(e){i.observers.fid=e,i.initFirstInputDelay()}))),this.config.pageResource&&this.initPageResource()),this.onVisibilityChange(),this.queue=new IdleQueue({ensureTasksRun:!0}))}return e.prototype.start=function(e){this.checkMetricName(e)&&(this.metrics[e]?this.logWarn("Recording already started."):(this.metrics[e]={end:0,start:this.perf.now()},this.perf.mark(e,"start"),this.isHidden=!1))},e.prototype.end=function(e){var i=this;if(this.checkMetricName(e)){var t=this.metrics[e];if(t){t.end=this.perf.now(),this.perf.mark(e,"end");var n=this.perf.measure(e,t),r=parseFloat(n.toFixed(2));return delete this.metrics[e],this.queue.pushTask((function(){i.log(e,r),i.sendTiming(e,r)})),r}this.logWarn("Recording already stopped.")}},e.prototype.endPaint=function(e){var i=this;return new Promise((function(t){setTimeout((function(){var n=i.end(e);t(n)}))}))},e.prototype.log=function(e,i){if(!this.isHidden&&this.config.logging)if(e){var t=i.toFixed(2),n="%c "+this.config.logPrefix+" "+e+" "+t+" ms";window.console.log(n,"color: #ff6d00;font-size:11px;")}else this.logWarn(this.logMetricWarn)},e.prototype.logDebug=function(e,i){void 0===i&&(i=""),this.config.debugging&&window.console.log("Perfume.js debugging "+e+":",i)},e.prototype.sendTiming=function(e,i){if(!this.isHidden){var t=this.config.browserTracker?this.browser:void 0,n=this.addBrowserToMetricName(e);if(this.config.analyticsTracker&&this.config.analyticsTracker(e,i,t),this.config.googleAnalytics.enable)if(window.ga){var r=Math.round(i);window.ga("send","timing",n,this.config.googleAnalytics.timingVar,r)}else this.logWarn("Google Analytics has not been loaded")}},e.prototype.addBrowserToMetricName=function(e){if(!this.config.browserTracker)return e;var i=e;this.browser.name&&(i+="."+this.browser.name.replace(/\s/g,""),this.browser.os&&(i+="."+this.browser.os.replace(/\s/g,"")));return i},e.prototype.checkMetricName=function(e){return!!e||(this.logWarn(this.logMetricWarn),!1)},e.prototype.performanceObserverCb=function(e){var i=this;this.logDebug("performanceObserverCb",e),e.entries.forEach((function(t){i.queue.pushTask((function(){i.config[e.metricName]&&(!e.entryName||e.entryName&&t.name===e.entryName)&&i.logMetric(t[e.valueLog],e.metricLog,e.metricName)})),"first-contentful-paint"===t.name&&i.perfObservers.fcp.disconnect()})),"first-input"===e.entryName&&this.perfObservers.fid.disconnect()},e.prototype.performanceObserverResourceCb=function(e){var i=this;this.logDebug("performanceObserverResourceCb",e),e.entries.forEach((function(e){if(e.decodedBodySize){var t=parseFloat((e.decodedBodySize/1e3).toFixed(2));i.pageResourceDecodedBodySize+=t}}))},e.prototype.initFirstPaint=function(){var e=this;this.logDebug("initFirstPaint");try{this.perfObservers.fcp=this.perf.performanceObserver("paint",(function(i){e.performanceObserverCb({entries:i,entryName:"first-paint",metricLog:"First Paint",metricName:"firstPaint",valueLog:"startTime"}),e.performanceObserverCb({entries:i,entryName:"first-contentful-paint",metricLog:"First Contentful Paint",metricName:"firstContentfulPaint",valueLog:"startTime"})}))}catch(e){this.logWarn("initFirstPaint failed")}},e.prototype.initFirstInputDelay=function(){var e=this;try{this.perfObservers.fid=this.perf.performanceObserver("first-input",(function(i){e.performanceObserverCb({entries:i,metricLog:"First Input Delay",metricName:"firstInputDelay",valueLog:"duration"})}))}catch(e){this.logWarn("initFirstInputDelay failed")}},e.prototype.initPageResource=function(){var e=this;try{this.perfObservers.pageResource=this.perf.performanceObserver("resource",(function(i){e.performanceObserverResourceCb({entries:i})})),setTimeout((function(){e.perfObservers.pageResource.disconnect()}),5e3)}catch(e){this.logWarn("initPageResource failed")}},e.prototype.onVisibilityChange=function(){void 0!==document.hidden&&document.addEventListener("visibilitychange",this.didVisibilityChange)},e.prototype.logMetric=function(e,i,t){var n=parseFloat(e.toFixed(2));n>this.config.maxMeasureTime||("firstPaint"===t&&(this.firstPaintDuration=n),"firstContentfulPaint"===t&&(this.firstContentfulPaintDuration=n,this.observers.fcp(n)),"firstInputDelay"===t&&(this.firstInputDelayDuration=n,this.observers.fid(n)),this.log(i,n),this.sendTiming(t,n))},e.prototype.logWarn=function(e){this.config.warning&&this.config.logging&&window.console.warn(this.config.logPrefix,e)},e}();module.exports=Perfume; | ||
"use strict";var BrowserInfo=function(e,t,i){this.name=e,this.version=t,this.os=i},NodeInfo=function(e){this.version=e,this.name="node",this.os=process.platform},BotInfo=function(){this.bot=!0,this.name="bot",this.version=null,this.os=null},SEARCHBOX_UA_REGEX=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,SEARCHBOT_OS_REGEX=/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/,REQUIRED_VERSION_PARTS=3,userAgentRules=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["vivaldi",/Vivaldi\/([0-9\.]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FBAV\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["searchbot",SEARCHBOX_UA_REGEX]],operatingSystemRules=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/],["Search Bot",SEARCHBOT_OS_REGEX]];function detect(){return"undefined"!=typeof navigator?parseUserAgent(navigator.userAgent):getNodeVersion()}function parseUserAgent(e){var t=""!==e&&userAgentRules.reduce((function(t,i){var n=i[0],s=i[1];if(t)return t;var r=s.exec(e);return!!r&&[n,r]}),!1);if(!t)return null;var i=t[0],n=t[1];if("searchbot"===i)return new BotInfo;var s=n[1]&&n[1].split(/[._]/).slice(0,3);return s?s.length<REQUIRED_VERSION_PARTS&&(s=s.concat(new Array(REQUIRED_VERSION_PARTS-s.length).fill("0"))):s=[],new BrowserInfo(i,s.join("."),detectOS(e))}function detectOS(e){var t=operatingSystemRules.find((function(t){t[0];return t[1].test(e)}));return t?t[0]:null}function getNodeVersion(){return"undefined"!=typeof process&&process.version?new NodeInfo(process.version.slice(1)):null}var now=function(){return+new Date},supportsRequestIdleCallback_="function"==typeof window.requestIdleCallback,IdleDealine=function(){function e(e){this.initTime_=e}return Object.defineProperty(e.prototype,"didTimeout",{get:function(){return!1},enumerable:!0,configurable:!0}),e.prototype.timeRemaining=function(){return Math.max(0,50-(now()-this.initTime_))},e}(),requestIdleCallbackShim=function(e){var t=new IdleDealine(now());return setTimeout((function(){return e(t)}),0)},cancelIdleCallbackShim=function(e){clearTimeout(e)},rIC=supportsRequestIdleCallback_?window.requestIdleCallback:requestIdleCallbackShim,cIC=supportsRequestIdleCallback_?window.cancelIdleCallback:cancelIdleCallbackShim,supportsPromisesNatively="function"==typeof Promise&&Promise.toString().indexOf("[native code]")>-1,supportsMutationObserver="MutationObserver"in window||"WebKitMutationObserver"in window||"MozMutationObserver"in window,createQueueMicrotaskViaPromises=function(){return function(e){Promise.resolve().then(e)}},createQueueMicrotaskViaMutationObserver=function(){var e=0,t=[],i=new MutationObserver((function(){t.forEach((function(e){return e()})),t=[]})),n=document.createTextNode("");return i.observe(n,{characterData:!0}),function(i){t.push(i),n.data=String(++e%2)}},discardMicrotasks=function(){return function(e){}},queueMicrotask=supportsPromisesNatively?createQueueMicrotaskViaPromises():supportsMutationObserver?createQueueMicrotaskViaMutationObserver():discardMicrotasks(),DEFAULT_MIN_TASK_TIME=0,isSafari_=!("object"!=typeof window.safari||!window.safari.pushNotification),IdleQueue=function(){function e(e){var t=void 0===e?{}:e,i=t.ensureTasksRun,n=void 0!==i&&i,s=t.defaultMinTaskTime,r=void 0===s?DEFAULT_MIN_TASK_TIME:s;this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.idleCallbackHandle_=null,this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.defaultMinTaskTime_=r,this.ensureTasksRun_=n,this.runTasksImmediately=this.runTasksImmediately.bind(this),this.runTasks_=this.runTasks_.bind(this),this.onVisibilityChange_=this.onVisibilityChange_.bind(this),this.ensureTasksRun_&&(addEventListener("visibilitychange",this.onVisibilityChange_,!0),isSafari_&&addEventListener("beforeunload",this.runTasksImmediately,!0))}return e.prototype.pushTask=function(e){this.addTask_(Array.prototype.push,e)},e.prototype.unshiftTask=function(e){this.addTask_(Array.prototype.unshift,e)},e.prototype.runTasksImmediately=function(){this.runTasks_()},e.prototype.hasPendingTasks=function(){return this.taskQueue_.length>0},e.prototype.clearPendingTasks=function(){this.taskQueue_=[],this.cancelScheduledRun_()},e.prototype.getState=function(){return this.state_},e.prototype.destroy=function(){this.taskQueue_=[],this.cancelScheduledRun_(),this.ensureTasksRun_&&(removeEventListener("visibilitychange",this.onVisibilityChange_,!0),isSafari_&&removeEventListener("beforeunload",this.runTasksImmediately,!0))},e.prototype.addTask_=function(e,t,i){var n=(void 0===i?{}:i).minTaskTime,s=void 0===n?this.defaultMinTaskTime_:n,r={time:now(),visibilityState:document.visibilityState};e.call(this.taskQueue_,{state:r,task:t,minTaskTime:s}),this.scheduleTasksToRun_()},e.prototype.scheduleTasksToRun_=function(){this.ensureTasksRun_&&"hidden"===document.visibilityState?queueMicrotask(this.runTasks_):this.idleCallbackHandle_||(this.idleCallbackHandle_=rIC(this.runTasks_))},e.prototype.runTasks_=function(e){if(this.cancelScheduledRun_(),!this.isProcessing_){for(this.isProcessing_=!0;this.hasPendingTasks()&&!shouldYield(e,this.taskQueue_[0].minTaskTime);){var t=this.taskQueue_.shift(),i=t.task,n=t.state;this.state_=n,i(n),this.state_=null}this.isProcessing_=!1,this.hasPendingTasks()&&this.scheduleTasksToRun_()}},e.prototype.cancelScheduledRun_=function(){cIC(this.idleCallbackHandle_),this.idleCallbackHandle_=null},e.prototype.onVisibilityChange_=function(){"hidden"===document.visibilityState&&this.runTasksImmediately()},e}(),shouldYield=function(e,t){return!!(e&&e.timeRemaining()<=t)},Performance=function(){function e(e){this.config=e}return e.supported=function(){return window.performance&&!!performance.now&&!!performance.mark},e.supportedPerformanceObserver=function(){return window.chrome&&"PerformanceObserver"in window},e.prototype.now=function(){return window.performance.now()},e.prototype.mark=function(e,t){var i="mark_"+e+"_"+t;window.performance.mark(i)},e.prototype.measure=function(e,t){var i="mark_"+e+"_start",n="mark_"+e+"_end";return window.performance.measure(e,i,n),this.getDurationByMetric(e,t)},e.prototype.performanceObserver=function(e,t){return this.perfObserver=new PerformanceObserver(this.performanceObserverCb.bind(this,t)),this.perfObserver.observe({type:e,buffered:!0}),this.perfObserver},e.prototype.getDurationByMetric=function(e,t){var i=this.getMeasurementForGivenName(e);return i&&"measure"===i.entryType?i.duration:-1},e.prototype.getMeasurementForGivenName=function(e){var t=window.performance.getEntriesByName(e);return t[t.length-1]},e.prototype.performanceObserverCb=function(e,t){e(t.getEntries())},e}(),Perfume=function(){function e(e){var t=this;void 0===e&&(e={}),this.config={firstContentfulPaint:!1,firstPaint:!1,firstInputDelay:!1,dataConsumption:!1,googleAnalytics:{enable:!1,timingVar:"name"},browserTracker:!1,logPrefix:"Perfume.js:",logging:!0,maxMeasureTime:15e3,maxDataConsumption:2e4,warning:!1,debugging:!1},this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.dataConsumption=0,this.isHidden=!1,this.logMetricWarn="Please provide a metric name",this.metrics={},this.observers={},this.perfObservers={},this.didVisibilityChange=function(){document.hidden&&(t.isHidden=document.hidden)},this.config=Object.assign({},this.config,e),this.perf=new Performance(this.config),Performance.supported()&&(this.config.browserTracker&&(this.browser=detect()),Performance.supportedPerformanceObserver()&&((this.config.firstPaint||this.config.firstContentfulPaint)&&(this.observeFirstContentfulPaint=new Promise((function(e){t.logDebug("observeFirstContentfulPaint"),t.observers.firstPaint=e,t.observers.firstContentfulPaint=e,t.initFirstPaint()}))),this.observeFirstInputDelay=new Promise((function(e){t.observers.firstInputDelay=e,t.initFirstInputDelay()})),this.config.dataConsumption&&(this.observeDataConsumption=new Promise((function(e){t.observers.dataConsumption=e,t.initDataConsumption()})))),this.onVisibilityChange(),this.queue=new IdleQueue({ensureTasksRun:!0}))}return e.prototype.start=function(e){this.checkMetricName(e)&&(this.metrics[e]?this.logWarn("Recording already started."):(this.metrics[e]={end:0,start:this.perf.now()},this.perf.mark(e,"start"),this.isHidden=!1))},e.prototype.end=function(e){var t=this;if(this.checkMetricName(e)){var i=this.metrics[e];if(i){i.end=this.perf.now(),this.perf.mark(e,"end");var n=this.perf.measure(e,i),s=parseFloat(n.toFixed(2));return delete this.metrics[e],this.queue.pushTask((function(){t.log(e,s),t.sendTiming(e,s)})),s}this.logWarn("Recording already stopped.")}},e.prototype.endPaint=function(e){var t=this;return new Promise((function(i){setTimeout((function(){var n=t.end(e);i(n)}))}))},e.prototype.log=function(e,t){if(!this.isHidden&&this.config.logging)if(e){var i=t.toFixed(2),n="%c "+this.config.logPrefix+" "+e+" "+i+" ms";window.console.log(n,"color: #ff6d00;font-size:11px;")}else this.logWarn(this.logMetricWarn)},e.prototype.logDebug=function(e,t){void 0===t&&(t=""),this.config.debugging&&window.console.log("Perfume.js debugging "+e+":",t)},e.prototype.sendTiming=function(e,t){if(!this.isHidden){var i=this.config.browserTracker?this.browser:void 0,n=this.addBrowserToMetricName(e);if(this.config.analyticsTracker&&this.config.analyticsTracker(e,t,i),this.config.googleAnalytics.enable)if(window.ga){var s=Math.round(t);window.ga("send","timing",n,this.config.googleAnalytics.timingVar,s)}else this.logWarn("Google Analytics has not been loaded")}},e.prototype.addBrowserToMetricName=function(e){if(!this.config.browserTracker)return e;var t=e;this.browser.name&&(t+="."+this.browser.name.replace(/\s/g,""),this.browser.os&&(t+="."+this.browser.os.replace(/\s/g,"")));return t},e.prototype.checkMetricName=function(e){return!!e||(this.logWarn(this.logMetricWarn),!1)},e.prototype.performanceObserverCb=function(e){var t=this;this.logDebug("performanceObserverCb",e),e.entries.forEach((function(i){t.queue.pushTask((function(){t.config[e.metricName]&&(!e.entryName||e.entryName&&i.name===e.entryName)&&t.logMetric(i[e.valueLog],e.metricLog,e.metricName)})),t.perfObservers.firstContentfulPaint&&"first-contentful-paint"===i.name&&t.perfObservers.firstContentfulPaint.disconnect()})),this.perfObservers.firstInputDelay&&"firstInputDelay"===e.metricName&&this.perfObservers.firstInputDelay.disconnect()},e.prototype.performanceObserverResourceCb=function(e){var t=this;this.logDebug("performanceObserverResourceCb",e),e.entries.forEach((function(e){if(e.decodedBodySize){var i=parseFloat((e.decodedBodySize/1e3).toFixed(2));t.dataConsumption+=i}}))},e.prototype.digestFirstPaintEntries=function(e){this.performanceObserverCb({entries:e,entryName:"first-paint",metricLog:"First Paint",metricName:"firstPaint",valueLog:"startTime"}),this.performanceObserverCb({entries:e,entryName:"first-contentful-paint",metricLog:"First Contentful Paint",metricName:"firstContentfulPaint",valueLog:"startTime"})},e.prototype.initFirstPaint=function(){this.logDebug("initFirstPaint");try{this.perfObservers.firstContentfulPaint=this.perf.performanceObserver("paint",this.digestFirstPaintEntries)}catch(e){this.logWarn("initFirstPaint failed")}},e.prototype.digestFirstInputDelayEntries=function(e){this.performanceObserverCb({entries:e,metricLog:"First Input Delay",metricName:"firstInputDelay",valueLog:"duration"}),this.disconnectDataConsumption()},e.prototype.initFirstInputDelay=function(){try{this.perfObservers.firstInputDelay=this.perf.performanceObserver("first-input",this.digestFirstInputDelayEntries)}catch(e){this.logWarn("initFirstInputDelay failed")}},e.prototype.digestDataConsumptionEntries=function(e){this.performanceObserverResourceCb({entries:e})},e.prototype.disconnectDataConsumption=function(){clearTimeout(this.dataConsumptionTimeout),this.perfObservers.dataConsumption&&this.dataConsumption&&(this.logMetric(this.dataConsumption,"Data Consumption","dataConsumption"),this.perfObservers.dataConsumption.disconnect())},e.prototype.initDataConsumption=function(){var e=this;try{this.perfObservers.dataConsumption=this.perf.performanceObserver("resource",this.digestDataConsumptionEntries)}catch(e){this.logWarn("initDataConsumption failed")}this.dataConsumptionTimeout=setTimeout((function(){e.disconnectDataConsumption()}),15e3)},e.prototype.onVisibilityChange=function(){void 0!==document.hidden&&document.addEventListener("visibilitychange",this.didVisibilityChange)},e.prototype.logMetric=function(e,t,i){var n=parseFloat(e.toFixed(2));"dataConsumption"!==i&&n>this.config.maxMeasureTime||"dataConsumption"===i&&n>this.config.maxDataConsumption||("firstPaint"===i&&(this.firstPaintDuration=n),"firstContentfulPaint"===i&&(this.firstContentfulPaintDuration=n),"firstInputDelay"===i&&(this.firstInputDelayDuration=n),this.observers[i](n),this.log(t,n),this.sendTiming(i,n))},e.prototype.logWarn=function(e){this.config.warning&&this.config.logging&&window.console.warn(this.config.logPrefix,e)},e}();module.exports=Perfume; | ||
//# sourceMappingURL=perfume.min.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(e=e||self).Perfume=i()}(this,(function(){"use strict";var e=function(e,i,t){this.name=e,this.version=i,this.os=t},i=function(e){this.version=e,this.name="node",this.os=process.platform},t=function(){this.bot=!0,this.name="bot",this.version=null,this.os=null},n=3,r=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["vivaldi",/Vivaldi\/([0-9\.]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FBAV\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["searchbot",/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/]],s=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/],["Search Bot",/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/]];function o(){return"undefined"!=typeof navigator?function(i){var o=""!==i&&r.reduce((function(e,t){var n=t[0],r=t[1];if(e)return e;var s=r.exec(i);return!!s&&[n,s]}),!1);if(!o)return null;var a=o[0],u=o[1];if("searchbot"===a)return new t;var c=u[1]&&u[1].split(/[._]/).slice(0,3);c?c.length<n&&(c=c.concat(new Array(n-c.length).fill("0"))):c=[];return new e(a,c.join("."),function(e){var i=s.find((function(i){i[0];return i[1].test(e)}));return i?i[0]:null}(i))}(navigator.userAgent):"undefined"!=typeof process&&process.version?new i(process.version.slice(1)):null}var a,u,c,f,d=function(){return+new Date},h="function"==typeof window.requestIdleCallback,l=function(){function e(e){this.initTime_=e}return Object.defineProperty(e.prototype,"didTimeout",{get:function(){return!1},enumerable:!0,configurable:!0}),e.prototype.timeRemaining=function(){return Math.max(0,50-(d()-this.initTime_))},e}(),p=h?window.requestIdleCallback:function(e){var i=new l(d());return setTimeout((function(){return e(i)}),0)},m=h?window.cancelIdleCallback:function(e){clearTimeout(e)},g="function"==typeof Promise&&Promise.toString().indexOf("[native code]")>-1,b="MutationObserver"in window||"WebKitMutationObserver"in window||"MozMutationObserver"in window,v=g?function(e){Promise.resolve().then(e)}:b?(a=0,u=[],c=new MutationObserver((function(){u.forEach((function(e){return e()})),u=[]})),f=document.createTextNode(""),c.observe(f,{characterData:!0}),function(e){u.push(e),f.data=String(++a%2)}):function(e){},y=0,w=!("object"!=typeof window.safari||!window.safari.pushNotification),k=function(){function e(e){var i=void 0===e?{}:e,t=i.ensureTasksRun,n=void 0!==t&&t,r=i.defaultMinTaskTime,s=void 0===r?y:r;this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.idleCallbackHandle_=null,this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.defaultMinTaskTime_=s,this.ensureTasksRun_=n,this.runTasksImmediately=this.runTasksImmediately.bind(this),this.runTasks_=this.runTasks_.bind(this),this.onVisibilityChange_=this.onVisibilityChange_.bind(this),this.ensureTasksRun_&&(addEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&addEventListener("beforeunload",this.runTasksImmediately,!0))}return e.prototype.pushTask=function(e){this.addTask_(Array.prototype.push,e)},e.prototype.unshiftTask=function(e){this.addTask_(Array.prototype.unshift,e)},e.prototype.runTasksImmediately=function(){this.runTasks_()},e.prototype.hasPendingTasks=function(){return this.taskQueue_.length>0},e.prototype.clearPendingTasks=function(){this.taskQueue_=[],this.cancelScheduledRun_()},e.prototype.getState=function(){return this.state_},e.prototype.destroy=function(){this.taskQueue_=[],this.cancelScheduledRun_(),this.ensureTasksRun_&&(removeEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&removeEventListener("beforeunload",this.runTasksImmediately,!0))},e.prototype.addTask_=function(e,i,t){var n=(void 0===t?{}:t).minTaskTime,r=void 0===n?this.defaultMinTaskTime_:n,s={time:d(),visibilityState:document.visibilityState};e.call(this.taskQueue_,{state:s,task:i,minTaskTime:r}),this.scheduleTasksToRun_()},e.prototype.scheduleTasksToRun_=function(){this.ensureTasksRun_&&"hidden"===document.visibilityState?v(this.runTasks_):this.idleCallbackHandle_||(this.idleCallbackHandle_=p(this.runTasks_))},e.prototype.runTasks_=function(e){if(this.cancelScheduledRun_(),!this.isProcessing_){for(this.isProcessing_=!0;this.hasPendingTasks()&&!T(e,this.taskQueue_[0].minTaskTime);){var i=this.taskQueue_.shift(),t=i.task,n=i.state;this.state_=n,t(n),this.state_=null}this.isProcessing_=!1,this.hasPendingTasks()&&this.scheduleTasksToRun_()}},e.prototype.cancelScheduledRun_=function(){m(this.idleCallbackHandle_),this.idleCallbackHandle_=null},e.prototype.onVisibilityChange_=function(){"hidden"===document.visibilityState&&this.runTasksImmediately()},e}(),T=function(e,i){return!!(e&&e.timeRemaining()<=i)},_=function(){function e(e){this.config=e}return e.supported=function(){return window.performance&&!!performance.now&&!!performance.mark},e.supportedPerformanceObserver=function(){return window.chrome&&"PerformanceObserver"in window},e.prototype.now=function(){return window.performance.now()},e.prototype.mark=function(e,i){var t="mark_"+e+"_"+i;window.performance.mark(t)},e.prototype.measure=function(e,i){var t="mark_"+e+"_start",n="mark_"+e+"_end";return window.performance.measure(e,t,n),this.getDurationByMetric(e,i)},e.prototype.performanceObserver=function(e,i){return this.perfObserver=new PerformanceObserver(this.performanceObserverCb.bind(this,i)),this.perfObserver.observe({type:e,buffered:!0}),this.perfObserver},e.prototype.getDurationByMetric=function(e,i){var t=this.getMeasurementForGivenName(e);return t&&"measure"===t.entryType?t.duration:-1},e.prototype.getMeasurementForGivenName=function(e){var i=window.performance.getEntriesByName(e);return i[i.length-1]},e.prototype.performanceObserverCb=function(e,i){e(i.getEntries())},e}();return function(){function e(e){var i=this;void 0===e&&(e={}),this.config={firstContentfulPaint:!1,firstPaint:!1,firstInputDelay:!1,pageResource:!1,googleAnalytics:{enable:!1,timingVar:"name"},browserTracker:!1,logPrefix:"Perfume.js:",logging:!0,maxMeasureTime:15e3,warning:!1,debugging:!1},this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.pageResourceDecodedBodySize=0,this.isHidden=!1,this.logMetricWarn="Please provide a metric name",this.metrics={},this.observers={},this.perfObservers={},this.didVisibilityChange=function(){document.hidden&&(i.isHidden=document.hidden)},this.config=Object.assign({},this.config,e),this.perf=new _(this.config),_.supported()&&(this.config.browserTracker&&(this.browser=o()),_.supportedPerformanceObserver()&&((this.config.firstPaint||this.config.firstContentfulPaint)&&(this.observeFirstContentfulPaint=new Promise((function(e){i.logDebug("observeFirstContentfulPaint"),i.observers.fcp=e,i.initFirstPaint()}))),this.config.firstInputDelay&&(this.observeFirstInputDelay=new Promise((function(e){i.observers.fid=e,i.initFirstInputDelay()}))),this.config.pageResource&&this.initPageResource()),this.onVisibilityChange(),this.queue=new k({ensureTasksRun:!0}))}return e.prototype.start=function(e){this.checkMetricName(e)&&(this.metrics[e]?this.logWarn("Recording already started."):(this.metrics[e]={end:0,start:this.perf.now()},this.perf.mark(e,"start"),this.isHidden=!1))},e.prototype.end=function(e){var i=this;if(this.checkMetricName(e)){var t=this.metrics[e];if(t){t.end=this.perf.now(),this.perf.mark(e,"end");var n=this.perf.measure(e,t),r=parseFloat(n.toFixed(2));return delete this.metrics[e],this.queue.pushTask((function(){i.log(e,r),i.sendTiming(e,r)})),r}this.logWarn("Recording already stopped.")}},e.prototype.endPaint=function(e){var i=this;return new Promise((function(t){setTimeout((function(){var n=i.end(e);t(n)}))}))},e.prototype.log=function(e,i){if(!this.isHidden&&this.config.logging)if(e){var t=i.toFixed(2),n="%c "+this.config.logPrefix+" "+e+" "+t+" ms";window.console.log(n,"color: #ff6d00;font-size:11px;")}else this.logWarn(this.logMetricWarn)},e.prototype.logDebug=function(e,i){void 0===i&&(i=""),this.config.debugging&&window.console.log("Perfume.js debugging "+e+":",i)},e.prototype.sendTiming=function(e,i){if(!this.isHidden){var t=this.config.browserTracker?this.browser:void 0,n=this.addBrowserToMetricName(e);if(this.config.analyticsTracker&&this.config.analyticsTracker(e,i,t),this.config.googleAnalytics.enable)if(window.ga){var r=Math.round(i);window.ga("send","timing",n,this.config.googleAnalytics.timingVar,r)}else this.logWarn("Google Analytics has not been loaded")}},e.prototype.addBrowserToMetricName=function(e){if(!this.config.browserTracker)return e;var i=e;this.browser.name&&(i+="."+this.browser.name.replace(/\s/g,""),this.browser.os&&(i+="."+this.browser.os.replace(/\s/g,"")));return i},e.prototype.checkMetricName=function(e){return!!e||(this.logWarn(this.logMetricWarn),!1)},e.prototype.performanceObserverCb=function(e){var i=this;this.logDebug("performanceObserverCb",e),e.entries.forEach((function(t){i.queue.pushTask((function(){i.config[e.metricName]&&(!e.entryName||e.entryName&&t.name===e.entryName)&&i.logMetric(t[e.valueLog],e.metricLog,e.metricName)})),"first-contentful-paint"===t.name&&i.perfObservers.fcp.disconnect()})),"first-input"===e.entryName&&this.perfObservers.fid.disconnect()},e.prototype.performanceObserverResourceCb=function(e){var i=this;this.logDebug("performanceObserverResourceCb",e),e.entries.forEach((function(e){if(e.decodedBodySize){var t=parseFloat((e.decodedBodySize/1e3).toFixed(2));i.pageResourceDecodedBodySize+=t}}))},e.prototype.initFirstPaint=function(){var e=this;this.logDebug("initFirstPaint");try{this.perfObservers.fcp=this.perf.performanceObserver("paint",(function(i){e.performanceObserverCb({entries:i,entryName:"first-paint",metricLog:"First Paint",metricName:"firstPaint",valueLog:"startTime"}),e.performanceObserverCb({entries:i,entryName:"first-contentful-paint",metricLog:"First Contentful Paint",metricName:"firstContentfulPaint",valueLog:"startTime"})}))}catch(e){this.logWarn("initFirstPaint failed")}},e.prototype.initFirstInputDelay=function(){var e=this;try{this.perfObservers.fid=this.perf.performanceObserver("first-input",(function(i){e.performanceObserverCb({entries:i,metricLog:"First Input Delay",metricName:"firstInputDelay",valueLog:"duration"})}))}catch(e){this.logWarn("initFirstInputDelay failed")}},e.prototype.initPageResource=function(){var e=this;try{this.perfObservers.pageResource=this.perf.performanceObserver("resource",(function(i){e.performanceObserverResourceCb({entries:i})})),setTimeout((function(){e.perfObservers.pageResource.disconnect()}),5e3)}catch(e){this.logWarn("initPageResource failed")}},e.prototype.onVisibilityChange=function(){void 0!==document.hidden&&document.addEventListener("visibilitychange",this.didVisibilityChange)},e.prototype.logMetric=function(e,i,t){var n=parseFloat(e.toFixed(2));n>this.config.maxMeasureTime||("firstPaint"===t&&(this.firstPaintDuration=n),"firstContentfulPaint"===t&&(this.firstContentfulPaintDuration=n,this.observers.fcp(n)),"firstInputDelay"===t&&(this.firstInputDelayDuration=n,this.observers.fid(n)),this.log(i,n),this.sendTiming(t,n))},e.prototype.logWarn=function(e){this.config.warning&&this.config.logging&&window.console.warn(this.config.logPrefix,e)},e}()})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Perfume=e()}(this,(function(){"use strict";var t=function(t,e,i){this.name=t,this.version=e,this.os=i},e=function(t){this.version=t,this.name="node",this.os=process.platform},i=function(){this.bot=!0,this.name="bot",this.version=null,this.os=null},n=3,s=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["vivaldi",/Vivaldi\/([0-9\.]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FBAV\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["searchbot",/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/]],r=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/],["Search Bot",/(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/]];function o(){return"undefined"!=typeof navigator?function(e){var o=""!==e&&s.reduce((function(t,i){var n=i[0],s=i[1];if(t)return t;var r=s.exec(e);return!!r&&[n,r]}),!1);if(!o)return null;var a=o[0],u=o[1];if("searchbot"===a)return new i;var c=u[1]&&u[1].split(/[._]/).slice(0,3);c?c.length<n&&(c=c.concat(new Array(n-c.length).fill("0"))):c=[];return new t(a,c.join("."),function(t){var e=r.find((function(e){e[0];return e[1].test(t)}));return e?e[0]:null}(e))}(navigator.userAgent):"undefined"!=typeof process&&process.version?new e(process.version.slice(1)):null}var a,u,c,f,d=function(){return+new Date},h="function"==typeof window.requestIdleCallback,p=function(){function t(t){this.initTime_=t}return Object.defineProperty(t.prototype,"didTimeout",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype.timeRemaining=function(){return Math.max(0,50-(d()-this.initTime_))},t}(),l=h?window.requestIdleCallback:function(t){var e=new p(d());return setTimeout((function(){return t(e)}),0)},m=h?window.cancelIdleCallback:function(t){clearTimeout(t)},g="function"==typeof Promise&&Promise.toString().indexOf("[native code]")>-1,b="MutationObserver"in window||"WebKitMutationObserver"in window||"MozMutationObserver"in window,v=g?function(t){Promise.resolve().then(t)}:b?(a=0,u=[],c=new MutationObserver((function(){u.forEach((function(t){return t()})),u=[]})),f=document.createTextNode(""),c.observe(f,{characterData:!0}),function(t){u.push(t),f.data=String(++a%2)}):function(t){},y=0,w=!("object"!=typeof window.safari||!window.safari.pushNotification),T=function(){function t(t){var e=void 0===t?{}:t,i=e.ensureTasksRun,n=void 0!==i&&i,s=e.defaultMinTaskTime,r=void 0===s?y:s;this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.idleCallbackHandle_=null,this.taskQueue_=[],this.isProcessing_=!1,this.state_=null,this.defaultMinTaskTime_=r,this.ensureTasksRun_=n,this.runTasksImmediately=this.runTasksImmediately.bind(this),this.runTasks_=this.runTasks_.bind(this),this.onVisibilityChange_=this.onVisibilityChange_.bind(this),this.ensureTasksRun_&&(addEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&addEventListener("beforeunload",this.runTasksImmediately,!0))}return t.prototype.pushTask=function(t){this.addTask_(Array.prototype.push,t)},t.prototype.unshiftTask=function(t){this.addTask_(Array.prototype.unshift,t)},t.prototype.runTasksImmediately=function(){this.runTasks_()},t.prototype.hasPendingTasks=function(){return this.taskQueue_.length>0},t.prototype.clearPendingTasks=function(){this.taskQueue_=[],this.cancelScheduledRun_()},t.prototype.getState=function(){return this.state_},t.prototype.destroy=function(){this.taskQueue_=[],this.cancelScheduledRun_(),this.ensureTasksRun_&&(removeEventListener("visibilitychange",this.onVisibilityChange_,!0),w&&removeEventListener("beforeunload",this.runTasksImmediately,!0))},t.prototype.addTask_=function(t,e,i){var n=(void 0===i?{}:i).minTaskTime,s=void 0===n?this.defaultMinTaskTime_:n,r={time:d(),visibilityState:document.visibilityState};t.call(this.taskQueue_,{state:r,task:e,minTaskTime:s}),this.scheduleTasksToRun_()},t.prototype.scheduleTasksToRun_=function(){this.ensureTasksRun_&&"hidden"===document.visibilityState?v(this.runTasks_):this.idleCallbackHandle_||(this.idleCallbackHandle_=l(this.runTasks_))},t.prototype.runTasks_=function(t){if(this.cancelScheduledRun_(),!this.isProcessing_){for(this.isProcessing_=!0;this.hasPendingTasks()&&!k(t,this.taskQueue_[0].minTaskTime);){var e=this.taskQueue_.shift(),i=e.task,n=e.state;this.state_=n,i(n),this.state_=null}this.isProcessing_=!1,this.hasPendingTasks()&&this.scheduleTasksToRun_()}},t.prototype.cancelScheduledRun_=function(){m(this.idleCallbackHandle_),this.idleCallbackHandle_=null},t.prototype.onVisibilityChange_=function(){"hidden"===document.visibilityState&&this.runTasksImmediately()},t}(),k=function(t,e){return!!(t&&t.timeRemaining()<=e)},C=function(){function t(t){this.config=t}return t.supported=function(){return window.performance&&!!performance.now&&!!performance.mark},t.supportedPerformanceObserver=function(){return window.chrome&&"PerformanceObserver"in window},t.prototype.now=function(){return window.performance.now()},t.prototype.mark=function(t,e){var i="mark_"+t+"_"+e;window.performance.mark(i)},t.prototype.measure=function(t,e){var i="mark_"+t+"_start",n="mark_"+t+"_end";return window.performance.measure(t,i,n),this.getDurationByMetric(t,e)},t.prototype.performanceObserver=function(t,e){return this.perfObserver=new PerformanceObserver(this.performanceObserverCb.bind(this,e)),this.perfObserver.observe({type:t,buffered:!0}),this.perfObserver},t.prototype.getDurationByMetric=function(t,e){var i=this.getMeasurementForGivenName(t);return i&&"measure"===i.entryType?i.duration:-1},t.prototype.getMeasurementForGivenName=function(t){var e=window.performance.getEntriesByName(t);return e[e.length-1]},t.prototype.performanceObserverCb=function(t,e){t(e.getEntries())},t}();return function(){function t(t){var e=this;void 0===t&&(t={}),this.config={firstContentfulPaint:!1,firstPaint:!1,firstInputDelay:!1,dataConsumption:!1,googleAnalytics:{enable:!1,timingVar:"name"},browserTracker:!1,logPrefix:"Perfume.js:",logging:!0,maxMeasureTime:15e3,maxDataConsumption:2e4,warning:!1,debugging:!1},this.firstPaintDuration=0,this.firstContentfulPaintDuration=0,this.firstInputDelayDuration=0,this.dataConsumption=0,this.isHidden=!1,this.logMetricWarn="Please provide a metric name",this.metrics={},this.observers={},this.perfObservers={},this.didVisibilityChange=function(){document.hidden&&(e.isHidden=document.hidden)},this.config=Object.assign({},this.config,t),this.perf=new C(this.config),C.supported()&&(this.config.browserTracker&&(this.browser=o()),C.supportedPerformanceObserver()&&((this.config.firstPaint||this.config.firstContentfulPaint)&&(this.observeFirstContentfulPaint=new Promise((function(t){e.logDebug("observeFirstContentfulPaint"),e.observers.firstPaint=t,e.observers.firstContentfulPaint=t,e.initFirstPaint()}))),this.observeFirstInputDelay=new Promise((function(t){e.observers.firstInputDelay=t,e.initFirstInputDelay()})),this.config.dataConsumption&&(this.observeDataConsumption=new Promise((function(t){e.observers.dataConsumption=t,e.initDataConsumption()})))),this.onVisibilityChange(),this.queue=new T({ensureTasksRun:!0}))}return t.prototype.start=function(t){this.checkMetricName(t)&&(this.metrics[t]?this.logWarn("Recording already started."):(this.metrics[t]={end:0,start:this.perf.now()},this.perf.mark(t,"start"),this.isHidden=!1))},t.prototype.end=function(t){var e=this;if(this.checkMetricName(t)){var i=this.metrics[t];if(i){i.end=this.perf.now(),this.perf.mark(t,"end");var n=this.perf.measure(t,i),s=parseFloat(n.toFixed(2));return delete this.metrics[t],this.queue.pushTask((function(){e.log(t,s),e.sendTiming(t,s)})),s}this.logWarn("Recording already stopped.")}},t.prototype.endPaint=function(t){var e=this;return new Promise((function(i){setTimeout((function(){var n=e.end(t);i(n)}))}))},t.prototype.log=function(t,e){if(!this.isHidden&&this.config.logging)if(t){var i=e.toFixed(2),n="%c "+this.config.logPrefix+" "+t+" "+i+" ms";window.console.log(n,"color: #ff6d00;font-size:11px;")}else this.logWarn(this.logMetricWarn)},t.prototype.logDebug=function(t,e){void 0===e&&(e=""),this.config.debugging&&window.console.log("Perfume.js debugging "+t+":",e)},t.prototype.sendTiming=function(t,e){if(!this.isHidden){var i=this.config.browserTracker?this.browser:void 0,n=this.addBrowserToMetricName(t);if(this.config.analyticsTracker&&this.config.analyticsTracker(t,e,i),this.config.googleAnalytics.enable)if(window.ga){var s=Math.round(e);window.ga("send","timing",n,this.config.googleAnalytics.timingVar,s)}else this.logWarn("Google Analytics has not been loaded")}},t.prototype.addBrowserToMetricName=function(t){if(!this.config.browserTracker)return t;var e=t;this.browser.name&&(e+="."+this.browser.name.replace(/\s/g,""),this.browser.os&&(e+="."+this.browser.os.replace(/\s/g,"")));return e},t.prototype.checkMetricName=function(t){return!!t||(this.logWarn(this.logMetricWarn),!1)},t.prototype.performanceObserverCb=function(t){var e=this;this.logDebug("performanceObserverCb",t),t.entries.forEach((function(i){e.queue.pushTask((function(){e.config[t.metricName]&&(!t.entryName||t.entryName&&i.name===t.entryName)&&e.logMetric(i[t.valueLog],t.metricLog,t.metricName)})),e.perfObservers.firstContentfulPaint&&"first-contentful-paint"===i.name&&e.perfObservers.firstContentfulPaint.disconnect()})),this.perfObservers.firstInputDelay&&"firstInputDelay"===t.metricName&&this.perfObservers.firstInputDelay.disconnect()},t.prototype.performanceObserverResourceCb=function(t){var e=this;this.logDebug("performanceObserverResourceCb",t),t.entries.forEach((function(t){if(t.decodedBodySize){var i=parseFloat((t.decodedBodySize/1e3).toFixed(2));e.dataConsumption+=i}}))},t.prototype.digestFirstPaintEntries=function(t){this.performanceObserverCb({entries:t,entryName:"first-paint",metricLog:"First Paint",metricName:"firstPaint",valueLog:"startTime"}),this.performanceObserverCb({entries:t,entryName:"first-contentful-paint",metricLog:"First Contentful Paint",metricName:"firstContentfulPaint",valueLog:"startTime"})},t.prototype.initFirstPaint=function(){this.logDebug("initFirstPaint");try{this.perfObservers.firstContentfulPaint=this.perf.performanceObserver("paint",this.digestFirstPaintEntries)}catch(t){this.logWarn("initFirstPaint failed")}},t.prototype.digestFirstInputDelayEntries=function(t){this.performanceObserverCb({entries:t,metricLog:"First Input Delay",metricName:"firstInputDelay",valueLog:"duration"}),this.disconnectDataConsumption()},t.prototype.initFirstInputDelay=function(){try{this.perfObservers.firstInputDelay=this.perf.performanceObserver("first-input",this.digestFirstInputDelayEntries)}catch(t){this.logWarn("initFirstInputDelay failed")}},t.prototype.digestDataConsumptionEntries=function(t){this.performanceObserverResourceCb({entries:t})},t.prototype.disconnectDataConsumption=function(){clearTimeout(this.dataConsumptionTimeout),this.perfObservers.dataConsumption&&this.dataConsumption&&(this.logMetric(this.dataConsumption,"Data Consumption","dataConsumption"),this.perfObservers.dataConsumption.disconnect())},t.prototype.initDataConsumption=function(){var t=this;try{this.perfObservers.dataConsumption=this.perf.performanceObserver("resource",this.digestDataConsumptionEntries)}catch(t){this.logWarn("initDataConsumption failed")}this.dataConsumptionTimeout=setTimeout((function(){t.disconnectDataConsumption()}),15e3)},t.prototype.onVisibilityChange=function(){void 0!==document.hidden&&document.addEventListener("visibilitychange",this.didVisibilityChange)},t.prototype.logMetric=function(t,e,i){var n=parseFloat(t.toFixed(2));"dataConsumption"!==i&&n>this.config.maxMeasureTime||"dataConsumption"===i&&n>this.config.maxDataConsumption||("firstPaint"===i&&(this.firstPaintDuration=n),"firstContentfulPaint"===i&&(this.firstContentfulPaintDuration=n),"firstInputDelay"===i&&(this.firstInputDelayDuration=n),this.observers[i](n),this.log(e,n),this.sendTiming(i,n))},t.prototype.logWarn=function(t){this.config.warning&&this.config.logging&&window.console.warn(this.config.logPrefix,t)},t}()})); | ||
//# sourceMappingURL=perfume.umd.min.js.map |
/*! | ||
* Perfume.js v3.0.0-rc.1 (http://zizzamia.github.io/perfume) | ||
* Perfume.js v3.0.0-rc.2 (http://zizzamia.github.io/perfume) | ||
* Copyright 2018 The Perfume Authors (https://github.com/Zizzamia/perfume.js/graphs/contributors) | ||
@@ -12,3 +12,3 @@ * Licensed under MIT (https://github.com/Zizzamia/perfume.js/blob/master/LICENSE) | ||
firstPaint: boolean; | ||
pageResource: boolean; | ||
dataConsumption: boolean; | ||
analyticsTracker?: (metricName: string, duration: number, browser?: BrowserInfo | any) => void; | ||
@@ -20,2 +20,3 @@ browserTracker?: boolean; | ||
maxMeasureTime: number; | ||
maxDataConsumption: number; | ||
warning: boolean; | ||
@@ -28,3 +29,3 @@ debugging: boolean; | ||
firstPaint?: boolean; | ||
pageResource?: boolean; | ||
dataConsumption?: boolean; | ||
analyticsTracker?: (metricName: string, duration: number, browser?: BrowserInfo | any) => void; | ||
@@ -36,2 +37,3 @@ browserTracker?: boolean; | ||
maxMeasureTime?: number; | ||
maxDataConsumption?: number; | ||
warning?: boolean; | ||
@@ -77,6 +79,9 @@ debugging?: boolean; | ||
firstInputDelayDuration: number; | ||
pageResourceDecodedBodySize: number; | ||
dataConsumption: number; | ||
observeFirstPaint?: Promise<number>; | ||
observeFirstContentfulPaint?: Promise<number>; | ||
observeFirstInputDelay?: Promise<number>; | ||
observeDataConsumption?: Promise<number>; | ||
private browser; | ||
private dataConsumptionTimeout; | ||
private isHidden; | ||
@@ -126,2 +131,3 @@ private logMetricWarn; | ||
private performanceObserverResourceCb; | ||
private digestFirstPaintEntries; | ||
/** | ||
@@ -132,4 +138,7 @@ * First Paint is essentially the paint after which | ||
private initFirstPaint; | ||
private digestFirstInputDelayEntries; | ||
private initFirstInputDelay; | ||
private initPageResource; | ||
private digestDataConsumptionEntries; | ||
private disconnectDataConsumption; | ||
private initDataConsumption; | ||
/** | ||
@@ -136,0 +145,0 @@ * From visibilitychange listener it saves only when |
{ | ||
"name": "perfume.js", | ||
"version": "3.0.0-rc.1", | ||
"version": "3.0.0-rc.2", | ||
"description": "JavaScript library that measures First (Contentful) Paint (FP/FCP) and First Input Delay (FID). Annotates components’ performance for Vanilla and Angular applications, into the DevTools timeline. Reports all the results to Google Analytics or your favorite tracking tool.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
533528
3358