perfops-rom
Advanced tools
Comparing version 1.1.16 to 1.1.17
476
dist/rom.js
"use strict"; | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
(function (Promise) { | ||
var QUEUE_LIMIT = 2; | ||
var API_URL = 'https://devnull.perfops.net'; | ||
var RESOURCES_URL = 'https://rum-cdn.perfops.net/providers'; | ||
var RESOURCES_TTL = 5 * 60 * 1000; // Resources list TTL in the LocalStorage | ||
var _ref = // prettier-ignore | ||
function () { | ||
var REPEAT_DELAY = 60 * 1000; // How often the script will measure CDN performance while user staying on the same page | ||
var REPEAT_COUNT = 3; // How many times repeat | ||
var STORE_DATA_INTERVAL = 1000; // How often we should try to send data to the rum-parser | ||
var QUEUE_LIMIT = 2; // prettier-ignore | ||
var _ref = function () { | ||
/* minified */ | ||
@@ -20,7 +41,8 @@ }.toString().indexOf('minified') !== -1 ? { | ||
var clientKey = window.rum ? window.rum.key : undefined; | ||
var globalStoreMeta = null; | ||
var globalResults = []; | ||
var resolvers = []; | ||
var done = false; // prettier-ignore | ||
function formatTiming(value) { | ||
return Math.max(0, Number(value.toFixed(2))); | ||
} // prettier-ignore | ||
function fetch(url) { | ||
@@ -57,4 +79,4 @@ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
function fetchJs(url, cb) { | ||
var script = document.createElement('script'); | ||
var loaded; | ||
var script = document.createElement('script'), | ||
loaded; | ||
@@ -75,8 +97,16 @@ script.onreadystatechange = script.onload = function () { | ||
var url = "".concat(resource.cdnUrl, "?t=").concat(Date.now()); | ||
var domain = new URL(url).hostname; | ||
return fetch(url).then(function (xhr) { | ||
var timing = performance.getEntriesByName(url)[0]; | ||
var result = { | ||
id: resource.id | ||
id: resource.id, | ||
domain: domain | ||
}; | ||
var dnsLookupTime = formatTiming(timing.domainLookupEnd - timing.domainLookupStart); | ||
var tcpTime = formatTiming(timing.connectEnd - timing.connectStart); // In Firefox if connection was cached - secure connection time is calculated | ||
// as a difference between the page is loaded and current request execution started | ||
// which is equal to the time spent on the page. That's why we check if actual tcp connection time is calculated. | ||
var sslTime = tcpTime > 0 ? formatTiming(timing.connectEnd - timing.secureConnectionStart) : 0; | ||
if (xhr.status >= 200 && xhr.status < 300) { | ||
@@ -87,3 +117,5 @@ // Add success response measurements | ||
time: Number((timing.responseEnd - timing.requestStart).toFixed(2)), | ||
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)), | ||
dnsLookupTime: dnsLookupTime, | ||
tcpTime: tcpTime, | ||
sslTime: sslTime, | ||
headers: xhr.getAllResponseHeaders() | ||
@@ -97,3 +129,5 @@ }); | ||
up: 0, | ||
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)), | ||
dnsLookupTime: dnsLookupTime, | ||
tcpTime: tcpTime, | ||
sslTime: sslTime, | ||
headers: xhr.getAllResponseHeaders() | ||
@@ -113,4 +147,126 @@ }); | ||
function fetchResourceList() { | ||
return fetch('https://rum-cdn.perfops.net/providers').then(function (xhr) { | ||
var key = 'perfops-rum-resources'; | ||
var resources = JSON.parse(window.localStorage.getItem(key)); | ||
if (resources && resources.expiry > Date.now()) { | ||
return Promise.resolve(resources.data); | ||
} | ||
return fetch(RESOURCES_URL).then(function (xhr) { | ||
return JSON.parse(xhr.response); | ||
}).then(function (response) { | ||
if (!response || !response.data || !response.data.length) { | ||
throw new Error('Empty response.data'); | ||
} | ||
window.localStorage.setItem(key, JSON.stringify({ | ||
data: response.data, | ||
expiry: Date.now() + RESOURCES_TTL | ||
})); | ||
return response.data; | ||
}).catch(function () { | ||
// eslint-disable-next-line | ||
return { | ||
"data": [{ | ||
"id": 39, | ||
"cdnUrl": "https://cdnperf-rum.cdnetworks.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 17, | ||
"cdnUrl": "https://edgecast-cdn.perfops.io/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 18, | ||
"cdnUrl": "https://azure-perfops.azureedge.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 22, | ||
"cdnUrl": "https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 36, | ||
"cdnUrl": "https://perfops-cc.cdn-tech.io/500b-cc-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 30, | ||
"cdnUrl": "https://perfops.doracdn.com/500b-db-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 10, | ||
"cdnUrl": "https://akamai-perfops2.azureedge.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 20, | ||
"cdnUrl": "https://cdnperf.cachefly.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 5, | ||
"cdnUrl": "https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 12, | ||
"cdnUrl": "https://cdn.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 3, | ||
"cdnUrl": "https://perfops.perfstack.cf-china.info/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 8, | ||
"cdnUrl": "https://perfops.gcdn.co/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 9, | ||
"cdnUrl": "https://1933886249.rsc.cdn77.org/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 14, | ||
"cdnUrl": "https://perfops.r.worldssl.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 4, | ||
"cdnUrl": "https://fastly.jsdelivr.net/gh/ProspectOne/js-test@1.1/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 13, | ||
"cdnUrl": "https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 7, | ||
"cdnUrl": "https://google-cdn.perfops.io/500b-google-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 1, | ||
"cdnUrl": "https://kgmni17536myjst.belugacdn.link/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 35, | ||
"cdnUrl": "https://cdn81795137.blazingcdn.net/500b-blz-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 2, | ||
"cdnUrl": "https://ovh-cdn.perfops.io/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 24, | ||
"cdnUrl": "https://img-cdnperf.mncdn.com/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 11, | ||
"cdnUrl": "https://perfops.b-cdn.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 15, | ||
"cdnUrl": "https://cdnperf-rum.cdnetworks.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 38, | ||
"cdnUrl": "https://perf.psychz.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 6, | ||
"cdnUrl": "https://perfops-ade2.kxcdn.com/500b-bench.jpg", | ||
"p": 1 | ||
}] | ||
}; | ||
}); | ||
@@ -135,3 +291,3 @@ } // eslint-disable-next-line no-unused-vars | ||
if (Math.random() < 1 / oneIn) { | ||
fetch('https://devnull.perfops.net/debug/log', { | ||
fetch("".concat(API_URL, "/debug/log"), { | ||
data: JSON.stringify(data), | ||
@@ -154,167 +310,103 @@ method: 'POST' | ||
function run() { | ||
setTimeout(function () { | ||
fetchResourceList().then(function (response) { | ||
if (!response || !response.data || !response.data.length) { | ||
throw new Error('Empty response.data'); | ||
} | ||
var results = []; | ||
var metadata = { | ||
ua: navigator.userAgent, | ||
hostname: window.location.hostname, | ||
client: clientKey | ||
}; | ||
var storeInterval; | ||
var finished = false; | ||
return response; | ||
}).catch(function () { | ||
return { | ||
"data": [{ | ||
"id": 1, | ||
"cdnUrl": "https://kgmni17536myjst.belugacdn.link/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 30, | ||
"cdnUrl": "https://perfops.doracdn.com/500b-db-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 18, | ||
"cdnUrl": "https://azure-perfops1.azureedge.net/500b-azure-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 24, | ||
"cdnUrl": "https://img-cdnperf.mncdn.com/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 2, | ||
"cdnUrl": "https://ovh-cdn.perfops.io/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 29, | ||
"cdnUrl": "https://25748s.ha.azioncdn.net/500b-az-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 8, | ||
"cdnUrl": "https://perfops.gcdn.co/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 12, | ||
"cdnUrl": "https://cdn.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 7, | ||
"cdnUrl": "https://google-cdn.perfops.io/500b-google-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 38, | ||
"cdnUrl": "https://perf.psychz.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 35, | ||
"cdnUrl": "https://cdn81795137.blazingcdn.net/500b-blz-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 10, | ||
"cdnUrl": "https://akamai-perfops.azureedge.net/500b-aka-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 36, | ||
"cdnUrl": "https://perfops-cc.cdn-tech.io/500b-cc-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 5, | ||
"cdnUrl": "https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 13, | ||
"cdnUrl": "https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 15, | ||
"cdnUrl": "https://cdnperf-rum.cdnetworks.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 14, | ||
"cdnUrl": "https://perfops.r.worldssl.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 17, | ||
"cdnUrl": "https://edgecast-cdn.cdnperf.com/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 22, | ||
"cdnUrl": "https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 11, | ||
"cdnUrl": "https://perfops.b-cdn.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 3, | ||
"cdnUrl": "https://perfops.perfstack.cf-china.info/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 4, | ||
"cdnUrl": "https://fastly.jsdelivr.net/gh/ProspectOne/js-test@1.1/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 9, | ||
"cdnUrl": "https://1933886249.rsc.cdn77.org/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 20, | ||
"cdnUrl": "https://cdnperf.cachefly.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 6, | ||
"cdnUrl": "https://perfops-ade2.kxcdn.com/500b-bench.jpg", | ||
"p": 1 | ||
}] | ||
}; | ||
}).then(function (response) { | ||
var results = []; | ||
var metadata = { | ||
ua: navigator.userAgent, | ||
hostname: window.location.hostname, | ||
client: clientKey | ||
}; | ||
var tooSlow = 0; | ||
var down = 0; | ||
return pMapSeries(response.data, function (resource) { | ||
return fetchResource(resource).then(function (data) { | ||
globalResults.push(data); | ||
var store = function store() { | ||
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
logInfo("Try to store ".concat(results.length, " items")); | ||
if (!data.up) { | ||
down++; | ||
} else if (data.time > 2000) { | ||
tooSlow++; | ||
} // time must be between 3 and 3000 ms | ||
// if 2 or more providers in one batch fail, drop all results | ||
if (finished && results.length === 0) { | ||
logInfo('Store data interval cleared'); | ||
clearInterval(storeInterval); | ||
} | ||
if (results.length < 1) { | ||
logInfo('Batch is empty'); | ||
return; | ||
} | ||
if (down > 1 || data.up && (data.time < 3 || data.time > 3000)) { | ||
return; | ||
} | ||
if (results.length < 3 && !force) { | ||
logInfo('Batch is to small. Wait for more results'); | ||
return; | ||
} | ||
if (results.push(data) >= QUEUE_LIMIT) { | ||
down = 0; | ||
var slow = results.reduce(function (ac, val) { | ||
return ac + (val.time > 2000 ? 1 : 0); | ||
}, 0); // All the measurements in a batch are slow. Probably something with a user's internet connection. Skip the batch. | ||
if (tooSlow < QUEUE_LIMIT) { | ||
tooSlow = 0; | ||
} else { | ||
tooSlow = 0; | ||
return results.splice(0, results.length); | ||
if (slow === results.length) { | ||
logInfo("Skip batch of a ".concat(slow, " slow probes")); | ||
results.splice(0, slow); | ||
return; | ||
} | ||
storeResults(metadata, results.splice(0, results.length)).then(function () { | ||
return logInfo("Results stored"); | ||
}).catch(function (data) { | ||
var _results; | ||
return (_results = results).push.apply(_results, _toConsumableArray(data)); | ||
}); | ||
}; | ||
var numberOfRepeat = 0; | ||
var processor = function processor() { | ||
finished = false; // Clean up before new run. | ||
clearInterval(storeInterval); // Clear previous interval | ||
results = []; // Remove outdated probe results if they aren't stored till now. | ||
storeInterval = setInterval(store, STORE_DATA_INTERVAL); // Set new interval for data storing | ||
fetchResourceList().then(function (response) { | ||
var chunkedData = function (array, n) { | ||
return Array.from(Array(Math.ceil(array.length / n)), function (_, i) { | ||
return array.slice(i * n, i * n + n); | ||
}); | ||
}(response, QUEUE_LIMIT); | ||
return pMapSeries(chunkedData, function (resources) { | ||
var down = 0; | ||
return Promise.all(resources.map(function (resource) { | ||
return fetchResource(resource).then(function (data) { | ||
if (!data.up) { | ||
down++; | ||
} // time must be between 3 and 3000 ms | ||
// if 2 or more providers in one batch fail, drop all results | ||
if (down > 1 || data.up && (data.time < 3 || data.time > 3000)) { | ||
return; | ||
} | ||
return storeResults(metadata, results.splice(0, results.length)); | ||
} | ||
}); | ||
}).then(function () { | ||
if (down <= 1 && results.length) { | ||
return storeResults(metadata, results); | ||
} | ||
results.push(data); | ||
}); | ||
})); | ||
}); | ||
}).then(logInfo, logError).then(function () { | ||
done = true; | ||
resolvers.forEach(function (resolve) { | ||
return resolve(); | ||
}); | ||
finished = true; | ||
numberOfRepeat += 1; | ||
store(true); | ||
}).then(function () { | ||
if (numberOfRepeat < REPEAT_COUNT) { | ||
setTimeout(processor, REPEAT_DELAY); | ||
} | ||
}); | ||
}, 1000); | ||
}; // eslint-disable-next-line comma-dangle | ||
// prettier-ignore | ||
setTimeout(processor, 1000); | ||
} | ||
function storeResults(metadata, data) { | ||
return fetch('https://devnull.perfops.net/rum/v1', { | ||
return fetch("".concat(API_URL, "/rum/v1"), { | ||
data: JSON.stringify({ | ||
@@ -325,5 +417,6 @@ metadata: metadata, | ||
method: 'POST' | ||
}).then(function (request) { | ||
globalStoreMeta = JSON.parse(request.response); | ||
}).catch(logError); | ||
}).catch(function (err) { | ||
logError(err); | ||
throw data; | ||
}); | ||
} | ||
@@ -340,6 +433,27 @@ | ||
onLoad(function () { | ||
if (typeof window.performance === 'undefined') { | ||
/** | ||
* Try to prevent loading the script at all for the major bots/crawlers. | ||
* This is the first line defence against serving our scripts to crawlers. | ||
* Warns in console if we aren't loading, to aid support. | ||
**/ | ||
var knownBots = ['bot', 'headless', 'google', 'baidu', 'bing', 'msn', 'duckduckbot', 'teoma', 'slurp', 'yandex', 'phantomjs', 'pingdom', 'ahrefsbot']; | ||
var botString = knownBots.join('|'); | ||
var botTestRegex = new RegExp(botString, 'i'); | ||
var isProbablyBot = botTestRegex.test(window.navigator.userAgent); | ||
if (isProbablyBot) { | ||
console.warn('PerfOps RUM not launching due to suspicious userAgent:', window.navigator.userAgent); | ||
return; | ||
} | ||
if (typeof window.performance === 'undefined') { | ||
return; | ||
} // Clear performance API entries buffer when full | ||
performance.onresourcetimingbufferfull = function () { | ||
logInfo('clear performance resource buffer'); | ||
performance.clearResourceTimings(); | ||
}; | ||
if (typeof Promise === 'function') { | ||
@@ -354,26 +468,2 @@ return run(); | ||
}); | ||
window.perfopsRumJs = { | ||
getResults: function getResults() { | ||
return new Promise(function (resolve) { | ||
if (done) { | ||
return resolve(globalResults); | ||
} | ||
resolvers.push(function () { | ||
return resolve(globalResults); | ||
}); | ||
}); | ||
}, | ||
getStoreMeta: function getStoreMeta() { | ||
return new Promise(function (resolve) { | ||
if (done) { | ||
return resolve(globalStoreMeta); | ||
} | ||
resolvers.push(function () { | ||
return resolve(globalStoreMeta); | ||
}); | ||
}); | ||
} | ||
}; | ||
})(window.Promise); |
@@ -1,1 +0,1 @@ | ||
"use strict";!function(u){var n,t=-1!==function(){}.toString().indexOf("minified")?{logInfo:console.log,logError:console.error}:{logInfo:function(){},logError:function(){}},e=t.logInfo,a=t.logError,c=window.rum?window.rum.key:void 0,r=null,d=[],o=[],p=!1;function i(r,n){var t=1<arguments.length&&void 0!==n?n:{},e=t.cb,o=void 0===e?function(){}:e,c=t.data,d=t.method,p=void 0===d?"GET":d,i=t.timeout,s=void 0===i?3e3:i;return new u(function(n,t){var e=new XMLHttpRequest;e.onload=function(){return n(e)},e.onerror=e.ontimeout=function(){a(e),t(new Error("Status ".concat(e.status,". Response: ").concat(e.statusText)))},e.open(p,r),e.timeout=s,o(e),e.send(c)})}function s(){setTimeout(function(){i("https://rum-cdn.perfops.net/providers").then(function(n){return JSON.parse(n.response)}).then(function(n){if(!n||!n.data||!n.data.length)throw new Error("Empty response.data");return n}).catch(function(){return{data:[{id:1,cdnUrl:"https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",p:1},{id:30,cdnUrl:"https://perfops.doracdn.com/500b-db-bench.jpg",p:1},{id:18,cdnUrl:"https://azure-perfops1.azureedge.net/500b-azure-bench.jpg",p:1},{id:24,cdnUrl:"https://img-cdnperf.mncdn.com/500b-bench.jpg",p:0},{id:2,cdnUrl:"https://ovh-cdn.perfops.io/500b-bench.jpg",p:0},{id:29,cdnUrl:"https://25748s.ha.azioncdn.net/500b-az-bench.jpg",p:0},{id:8,cdnUrl:"https://perfops.gcdn.co/500b-bench.jpg",p:1},{id:12,cdnUrl:"https://cdn.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",p:1},{id:7,cdnUrl:"https://google-cdn.perfops.io/500b-google-bench.jpg",p:1},{id:38,cdnUrl:"https://perf.psychz.net/500b-bench.jpg",p:0},{id:35,cdnUrl:"https://cdn81795137.blazingcdn.net/500b-blz-bench.jpg",p:1},{id:10,cdnUrl:"https://akamai-perfops.azureedge.net/500b-aka-bench.jpg",p:1},{id:36,cdnUrl:"https://perfops-cc.cdn-tech.io/500b-cc-bench.jpg",p:0},{id:5,cdnUrl:"https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",p:1},{id:13,cdnUrl:"https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",p:1},{id:15,cdnUrl:"https://cdnperf-rum.cdnetworks.net/500b-bench.jpg",p:1},{id:14,cdnUrl:"https://perfops.r.worldssl.net/500b-bench.jpg",p:1},{id:17,cdnUrl:"https://edgecast-cdn.cdnperf.com/500b-bench.jpg",p:1},{id:22,cdnUrl:"https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg",p:0},{id:11,cdnUrl:"https://perfops.b-cdn.net/500b-bench.jpg",p:1},{id:3,cdnUrl:"https://perfops.perfstack.cf-china.info/500b-bench.jpg",p:1},{id:4,cdnUrl:"https://fastly.jsdelivr.net/gh/ProspectOne/js-test@1.1/500b-bench.jpg",p:1},{id:9,cdnUrl:"https://1933886249.rsc.cdn77.org/500b-bench.jpg",p:1},{id:20,cdnUrl:"https://cdnperf.cachefly.net/500b-bench.jpg",p:1},{id:6,cdnUrl:"https://perfops-ade2.kxcdn.com/500b-bench.jpg",p:1}]}}).then(function(n){var t=[],e={ua:navigator.userAgent,hostname:window.location.hostname,client:c},r=0,o=0;return function(n,r){return n.reduce(function(n,e){return n.then(function(t){return r(e).then(function(n){return t.push(n),t})})},u.resolve([]))}(n.data,function(n){return function(r){var o="".concat(r.cdnUrl,"?t=").concat(Date.now());return i(o).then(function(n){var t=performance.getEntriesByName(o)[0],e={id:r.id};return 200<=n.status&&n.status<300&&(e=Object.assign({},e,{up:1,time:Number((t.responseEnd-t.requestStart).toFixed(2)),dnsLookupTime:Number((t.domainLookupEnd-t.domainLookupStart).toFixed(2)),headers:n.getAllResponseHeaders()})),300<=n.status&&n.status<=500&&(e=Object.assign({},e,{up:0,dnsLookupTime:Number((t.domainLookupEnd-t.domainLookupStart).toFixed(2)),headers:n.getAllResponseHeaders()})),e}).catch(function(){return{id:r.id,up:0}})}(n).then(function(n){if(d.push(n),n.up?2e3<n.time&&r++:o++,!(1<o||n.up&&(n.time<3||3e3<n.time)))return 2<=t.push(n)?(o=0,r<2?(r=0,h(e,t.splice(0,t.length))):(r=0,t.splice(0,t.length))):void 0})}).then(function(){if(o<=1&&t.length)return h(e,t)})}).then(e,a).then(function(){p=!0,o.forEach(function(n){return n()})})},1e3)}function h(n,t){return i("https://devnull.perfops.net/rum/v1",{data:JSON.stringify({metadata:n,data:t}),method:"POST"}).then(function(n){r=JSON.parse(n.response)}).catch(a)}n=function(){if(void 0!==window.performance)return"function"==typeof u?s():void function(n,t){var e,r=document.createElement("script");r.onreadystatechange=r.onload=function(){e||t(),e=!0},r.setAttribute("src",n),document.body.appendChild(r)}("https://cdn.jsdelivr.net/npm/es6-promise@4.2.4/dist/es6-promise.min.js",function(){u=window.ES6Promise,s()})},"complete"===document.readyState?n():window.addEventListener("load",n),window.perfopsRumJs={getResults:function(){return new u(function(n){if(p)return n(d);o.push(function(){return n(d)})})},getStoreMeta:function(){return new u(function(n){if(p)return n(r);o.push(function(){return n(r)})})}}}(window.Promise); | ||
"use strict";function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,n){if(e){if("string"==typeof e)return _arrayLikeToArray(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,n):void 0}}function _iterableToArray(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}!function(d){var e,a="https://devnull.perfops.net",s="https://rum-cdn.perfops.net/providers",p=3e5,n=-1!==function(){}.toString().indexOf("minified")?{logInfo:console.log,logError:console.error}:{logInfo:function(){},logError:function(){}},u=n.logInfo,l=n.logError,h=window.rum?window.rum.key:void 0;function f(e){return Math.max(0,Number(e.toFixed(2)))}function g(r,e){var n=1<arguments.length&&void 0!==e?e:{},t=n.cb,o=void 0===t?function(){}:t,c=n.data,i=n.method,a=void 0===i?"GET":i,s=n.timeout,p=void 0===s?3e3:s;return new d(function(e,n){var t=new XMLHttpRequest;t.onload=function(){return e(t)},t.onerror=t.ontimeout=function(){l(t),n(new Error("Status ".concat(t.status,". Response: ").concat(t.statusText)))},t.open(a,r),t.timeout=p,o(t),t.send(c)})}function t(){function n(e){var n=0<arguments.length&&void 0!==e&&e;if(u("Try to store ".concat(o.length," items")),i&&0===o.length&&(u("Store data interval cleared"),clearInterval(r)),o.length<1)u("Batch is empty");else if(o.length<3&&!n)u("Batch is to small. Wait for more results");else{var t=o.reduce(function(e,n){return e+(2e3<n.time?1:0)},0);if(t===o.length)return u("Skip batch of a ".concat(t," slow probes")),void o.splice(0,t);(function(e,n){return g("".concat(a,"/rum/v1"),{data:JSON.stringify({metadata:e,data:n}),method:"POST"}).catch(function(e){throw l(e),n})})(c,o.splice(0,o.length)).then(function(){return u("Results stored")}).catch(function(e){var n;return(n=o).push.apply(n,_toConsumableArray(e))})}}var r,o=[],c={ua:navigator.userAgent,hostname:window.location.hostname,client:h},i=!1,t=0;setTimeout(function e(){i=!1,clearInterval(r),o=[],r=setInterval(n,1e3),function(){var n="perfops-rum-resources",e=JSON.parse(window.localStorage.getItem(n));return e&&e.expiry>Date.now()?d.resolve(e.data):g(s).then(function(e){return JSON.parse(e.response)}).then(function(e){if(!e||!e.data||!e.data.length)throw new Error("Empty response.data");return window.localStorage.setItem(n,JSON.stringify({data:e.data,expiry:Date.now()+p})),e.data}).catch(function(){return{data:[{id:39,cdnUrl:"https://cdnperf-rum.cdnetworks.net/500b-bench.jpg",p:0},{id:17,cdnUrl:"https://edgecast-cdn.perfops.io/500b-bench.jpg",p:1},{id:18,cdnUrl:"https://azure-perfops.azureedge.net/500b-bench.jpg",p:1},{id:22,cdnUrl:"https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg",p:0},{id:36,cdnUrl:"https://perfops-cc.cdn-tech.io/500b-cc-bench.jpg",p:0},{id:30,cdnUrl:"https://perfops.doracdn.com/500b-db-bench.jpg",p:1},{id:10,cdnUrl:"https://akamai-perfops2.azureedge.net/500b-bench.jpg",p:1},{id:20,cdnUrl:"https://cdnperf.cachefly.net/500b-bench.jpg",p:1},{id:5,cdnUrl:"https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",p:1},{id:12,cdnUrl:"https://cdn.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",p:1},{id:3,cdnUrl:"https://perfops.perfstack.cf-china.info/500b-bench.jpg",p:1},{id:8,cdnUrl:"https://perfops.gcdn.co/500b-bench.jpg",p:1},{id:9,cdnUrl:"https://1933886249.rsc.cdn77.org/500b-bench.jpg",p:1},{id:14,cdnUrl:"https://perfops.r.worldssl.net/500b-bench.jpg",p:1},{id:4,cdnUrl:"https://fastly.jsdelivr.net/gh/ProspectOne/js-test@1.1/500b-bench.jpg",p:1},{id:13,cdnUrl:"https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",p:1},{id:7,cdnUrl:"https://google-cdn.perfops.io/500b-google-bench.jpg",p:1},{id:1,cdnUrl:"https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",p:1},{id:35,cdnUrl:"https://cdn81795137.blazingcdn.net/500b-blz-bench.jpg",p:1},{id:2,cdnUrl:"https://ovh-cdn.perfops.io/500b-bench.jpg",p:1},{id:24,cdnUrl:"https://img-cdnperf.mncdn.com/500b-bench.jpg",p:0},{id:11,cdnUrl:"https://perfops.b-cdn.net/500b-bench.jpg",p:1},{id:15,cdnUrl:"https://cdnperf-rum.cdnetworks.net/500b-bench.jpg",p:1},{id:38,cdnUrl:"https://perf.psychz.net/500b-bench.jpg",p:0},{id:6,cdnUrl:"https://perfops-ade2.kxcdn.com/500b-bench.jpg",p:1}]}})}().then(function(e){var t;return function(e,r){return e.reduce(function(e,t){return e.then(function(n){return r(t).then(function(e){return n.push(e),n})})},d.resolve([]))}((t=e,Array.from(Array(Math.ceil(t.length/2)),function(e,n){return t.slice(2*n,2*n+2)})),function(e){var n=0;return d.all(e.map(function(e){return function(i){var a="".concat(i.cdnUrl,"?t=").concat(Date.now()),s=new URL(a).hostname;return g(a).then(function(e){var n=performance.getEntriesByName(a)[0],t={id:i.id,domain:s},r=f(n.domainLookupEnd-n.domainLookupStart),o=f(n.connectEnd-n.connectStart),c=0<o?f(n.connectEnd-n.secureConnectionStart):0;return 200<=e.status&&e.status<300&&(t=Object.assign({},t,{up:1,time:Number((n.responseEnd-n.requestStart).toFixed(2)),dnsLookupTime:r,tcpTime:o,sslTime:c,headers:e.getAllResponseHeaders()})),300<=e.status&&e.status<=500&&(t=Object.assign({},t,{up:0,dnsLookupTime:r,tcpTime:o,sslTime:c,headers:e.getAllResponseHeaders()})),t}).catch(function(){return{id:i.id,up:0}})}(e).then(function(e){e.up||n++,1<n||e.up&&(e.time<3||3e3<e.time)||o.push(e)})}))})}).then(u,l).then(function(){t+=1,n(i=!0)}).then(function(){t<3&&setTimeout(e,6e4)})},1e3)}e=function(){var e=["bot","headless","google","baidu","bing","msn","duckduckbot","teoma","slurp","yandex","phantomjs","pingdom","ahrefsbot"].join("|");if(new RegExp(e,"i").test(window.navigator.userAgent))console.warn("PerfOps RUM not launching due to suspicious userAgent:",window.navigator.userAgent);else if(void 0!==window.performance){if(performance.onresourcetimingbufferfull=function(){u("clear performance resource buffer"),performance.clearResourceTimings()},"function"==typeof d)return t();!function(e,n){var t,r=document.createElement("script");r.onreadystatechange=r.onload=function(){t||n(),t=!0},r.setAttribute("src",e),document.body.appendChild(r)}("https://cdn.jsdelivr.net/npm/es6-promise@4.2.4/dist/es6-promise.min.js",function(){d=window.ES6Promise,t()})}},"complete"===document.readyState?e():window.addEventListener("load",e)}(window.Promise); |
476
dist/rom3.js
"use strict"; | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
(function (Promise) { | ||
var QUEUE_LIMIT = 2; | ||
var API_URL = 'https://devnull.perfops.net'; | ||
var RESOURCES_URL = 'https://rum-cdn.perfops.net/providers'; | ||
var RESOURCES_TTL = 5 * 60 * 1000; // Resources list TTL in the LocalStorage | ||
var _ref = // prettier-ignore | ||
function () { | ||
var REPEAT_DELAY = 60 * 1000; // How often the script will measure CDN performance while user staying on the same page | ||
var REPEAT_COUNT = 3; // How many times repeat | ||
var STORE_DATA_INTERVAL = 1000; // How often we should try to send data to the rum-parser | ||
var QUEUE_LIMIT = 2; // prettier-ignore | ||
var _ref = function () { | ||
/* minified */ | ||
@@ -20,7 +41,8 @@ }.toString().indexOf('minified') !== -1 ? { | ||
var clientKey = window.rum ? window.rum.key : undefined; | ||
var globalStoreMeta = null; | ||
var globalResults = []; | ||
var resolvers = []; | ||
var done = false; // prettier-ignore | ||
function formatTiming(value) { | ||
return Math.max(0, Number(value.toFixed(2))); | ||
} // prettier-ignore | ||
function fetch(url) { | ||
@@ -57,4 +79,4 @@ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
function fetchJs(url, cb) { | ||
var script = document.createElement('script'); | ||
var loaded; | ||
var script = document.createElement('script'), | ||
loaded; | ||
@@ -75,8 +97,16 @@ script.onreadystatechange = script.onload = function () { | ||
var url = "".concat(resource.cdnUrl, "?t=").concat(Date.now()); | ||
var domain = new URL(url).hostname; | ||
return fetch(url).then(function (xhr) { | ||
var timing = performance.getEntriesByName(url)[0]; | ||
var result = { | ||
id: resource.id | ||
id: resource.id, | ||
domain: domain | ||
}; | ||
var dnsLookupTime = formatTiming(timing.domainLookupEnd - timing.domainLookupStart); | ||
var tcpTime = formatTiming(timing.connectEnd - timing.connectStart); // In Firefox if connection was cached - secure connection time is calculated | ||
// as a difference between the page is loaded and current request execution started | ||
// which is equal to the time spent on the page. That's why we check if actual tcp connection time is calculated. | ||
var sslTime = tcpTime > 0 ? formatTiming(timing.connectEnd - timing.secureConnectionStart) : 0; | ||
if (xhr.status >= 200 && xhr.status < 300) { | ||
@@ -87,3 +117,5 @@ // Add success response measurements | ||
time: Number((timing.responseEnd - timing.requestStart).toFixed(2)), | ||
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)), | ||
dnsLookupTime: dnsLookupTime, | ||
tcpTime: tcpTime, | ||
sslTime: sslTime, | ||
headers: xhr.getAllResponseHeaders() | ||
@@ -97,3 +129,5 @@ }); | ||
up: 0, | ||
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)), | ||
dnsLookupTime: dnsLookupTime, | ||
tcpTime: tcpTime, | ||
sslTime: sslTime, | ||
headers: xhr.getAllResponseHeaders() | ||
@@ -113,4 +147,126 @@ }); | ||
function fetchResourceList() { | ||
return fetch('https://rum-cdn.perfops.net/providers').then(function (xhr) { | ||
var key = 'perfops-rum-resources'; | ||
var resources = JSON.parse(window.localStorage.getItem(key)); | ||
if (resources && resources.expiry > Date.now()) { | ||
return Promise.resolve(resources.data); | ||
} | ||
return fetch(RESOURCES_URL).then(function (xhr) { | ||
return JSON.parse(xhr.response); | ||
}).then(function (response) { | ||
if (!response || !response.data || !response.data.length) { | ||
throw new Error('Empty response.data'); | ||
} | ||
window.localStorage.setItem(key, JSON.stringify({ | ||
data: response.data, | ||
expiry: Date.now() + RESOURCES_TTL | ||
})); | ||
return response.data; | ||
}).catch(function () { | ||
// eslint-disable-next-line | ||
return { | ||
"data": [{ | ||
"id": 39, | ||
"cdnUrl": "https://cdnperf-rum.cdnetworks.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 17, | ||
"cdnUrl": "https://edgecast-cdn.perfops.io/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 18, | ||
"cdnUrl": "https://azure-perfops.azureedge.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 22, | ||
"cdnUrl": "https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 36, | ||
"cdnUrl": "https://perfops-cc.cdn-tech.io/500b-cc-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 30, | ||
"cdnUrl": "https://perfops.doracdn.com/500b-db-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 10, | ||
"cdnUrl": "https://akamai-perfops2.azureedge.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 20, | ||
"cdnUrl": "https://cdnperf.cachefly.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 5, | ||
"cdnUrl": "https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 12, | ||
"cdnUrl": "https://cdn.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 3, | ||
"cdnUrl": "https://perfops.perfstack.cf-china.info/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 8, | ||
"cdnUrl": "https://perfops.gcdn.co/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 9, | ||
"cdnUrl": "https://1933886249.rsc.cdn77.org/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 14, | ||
"cdnUrl": "https://perfops.r.worldssl.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 4, | ||
"cdnUrl": "https://fastly.jsdelivr.net/gh/ProspectOne/js-test@1.1/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 13, | ||
"cdnUrl": "https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 7, | ||
"cdnUrl": "https://google-cdn.perfops.io/500b-google-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 1, | ||
"cdnUrl": "https://kgmni17536myjst.belugacdn.link/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 35, | ||
"cdnUrl": "https://cdn81795137.blazingcdn.net/500b-blz-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 2, | ||
"cdnUrl": "https://ovh-cdn.perfops.io/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 24, | ||
"cdnUrl": "https://img-cdnperf.mncdn.com/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 11, | ||
"cdnUrl": "https://perfops.b-cdn.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 15, | ||
"cdnUrl": "https://cdnperf-rum.cdnetworks.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 38, | ||
"cdnUrl": "https://perf.psychz.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 6, | ||
"cdnUrl": "https://perfops-ade2.kxcdn.com/500b-bench.jpg", | ||
"p": 1 | ||
}] | ||
}; | ||
}); | ||
@@ -135,3 +291,3 @@ } // eslint-disable-next-line no-unused-vars | ||
if (Math.random() < 1 / oneIn) { | ||
fetch('https://devnull.perfops.net/debug/log', { | ||
fetch("".concat(API_URL, "/debug/log"), { | ||
data: JSON.stringify(data), | ||
@@ -154,167 +310,103 @@ method: 'POST' | ||
function run() { | ||
setTimeout(function () { | ||
fetchResourceList().then(function (response) { | ||
if (!response || !response.data || !response.data.length) { | ||
throw new Error('Empty response.data'); | ||
} | ||
var results = []; | ||
var metadata = { | ||
ua: navigator.userAgent, | ||
hostname: window.location.hostname, | ||
client: clientKey | ||
}; | ||
var storeInterval; | ||
var finished = false; | ||
return response; | ||
}).catch(function () { | ||
return { | ||
"data": [{ | ||
"id": 1, | ||
"cdnUrl": "https://kgmni17536myjst.belugacdn.link/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 30, | ||
"cdnUrl": "https://perfops.doracdn.com/500b-db-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 18, | ||
"cdnUrl": "https://azure-perfops1.azureedge.net/500b-azure-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 24, | ||
"cdnUrl": "https://img-cdnperf.mncdn.com/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 2, | ||
"cdnUrl": "https://ovh-cdn.perfops.io/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 29, | ||
"cdnUrl": "https://25748s.ha.azioncdn.net/500b-az-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 8, | ||
"cdnUrl": "https://perfops.gcdn.co/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 12, | ||
"cdnUrl": "https://cdn.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 7, | ||
"cdnUrl": "https://google-cdn.perfops.io/500b-google-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 38, | ||
"cdnUrl": "https://perf.psychz.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 35, | ||
"cdnUrl": "https://cdn81795137.blazingcdn.net/500b-blz-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 10, | ||
"cdnUrl": "https://akamai-perfops.azureedge.net/500b-aka-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 36, | ||
"cdnUrl": "https://perfops-cc.cdn-tech.io/500b-cc-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 5, | ||
"cdnUrl": "https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 13, | ||
"cdnUrl": "https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 15, | ||
"cdnUrl": "https://cdnperf-rum.cdnetworks.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 14, | ||
"cdnUrl": "https://perfops.r.worldssl.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 17, | ||
"cdnUrl": "https://edgecast-cdn.cdnperf.com/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 22, | ||
"cdnUrl": "https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg", | ||
"p": 0 | ||
}, { | ||
"id": 11, | ||
"cdnUrl": "https://perfops.b-cdn.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 3, | ||
"cdnUrl": "https://perfops.perfstack.cf-china.info/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 4, | ||
"cdnUrl": "https://fastly.jsdelivr.net/gh/ProspectOne/js-test@1.1/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 9, | ||
"cdnUrl": "https://1933886249.rsc.cdn77.org/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 20, | ||
"cdnUrl": "https://cdnperf.cachefly.net/500b-bench.jpg", | ||
"p": 1 | ||
}, { | ||
"id": 6, | ||
"cdnUrl": "https://perfops-ade2.kxcdn.com/500b-bench.jpg", | ||
"p": 1 | ||
}] | ||
}; | ||
}).then(function (response) { | ||
var results = []; | ||
var metadata = { | ||
ua: navigator.userAgent, | ||
hostname: window.location.hostname, | ||
client: clientKey | ||
}; | ||
var tooSlow = 0; | ||
var down = 0; | ||
return pMapSeries(response.data, function (resource) { | ||
return fetchResource(resource).then(function (data) { | ||
globalResults.push(data); | ||
var store = function store() { | ||
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
logInfo("Try to store ".concat(results.length, " items")); | ||
if (!data.up) { | ||
down++; | ||
} else if (data.time > 2000) { | ||
tooSlow++; | ||
} // time must be between 3 and 3000 ms | ||
// if 2 or more providers in one batch fail, drop all results | ||
if (finished && results.length === 0) { | ||
logInfo('Store data interval cleared'); | ||
clearInterval(storeInterval); | ||
} | ||
if (results.length < 1) { | ||
logInfo('Batch is empty'); | ||
return; | ||
} | ||
if (down > 1 || data.up && (data.time < 3 || data.time > 3000)) { | ||
return; | ||
} | ||
if (results.length < 3 && !force) { | ||
logInfo('Batch is to small. Wait for more results'); | ||
return; | ||
} | ||
if (results.push(data) >= QUEUE_LIMIT) { | ||
down = 0; | ||
var slow = results.reduce(function (ac, val) { | ||
return ac + (val.time > 2000 ? 1 : 0); | ||
}, 0); // All the measurements in a batch are slow. Probably something with a user's internet connection. Skip the batch. | ||
if (tooSlow < QUEUE_LIMIT) { | ||
tooSlow = 0; | ||
} else { | ||
tooSlow = 0; | ||
return results.splice(0, results.length); | ||
if (slow === results.length) { | ||
logInfo("Skip batch of a ".concat(slow, " slow probes")); | ||
results.splice(0, slow); | ||
return; | ||
} | ||
storeResults(metadata, results.splice(0, results.length)).then(function () { | ||
return logInfo("Results stored"); | ||
}).catch(function (data) { | ||
var _results; | ||
return (_results = results).push.apply(_results, _toConsumableArray(data)); | ||
}); | ||
}; | ||
var numberOfRepeat = 0; | ||
var processor = function processor() { | ||
finished = false; // Clean up before new run. | ||
clearInterval(storeInterval); // Clear previous interval | ||
results = []; // Remove outdated probe results if they aren't stored till now. | ||
storeInterval = setInterval(store, STORE_DATA_INTERVAL); // Set new interval for data storing | ||
fetchResourceList().then(function (response) { | ||
var chunkedData = function (array, n) { | ||
return Array.from(Array(Math.ceil(array.length / n)), function (_, i) { | ||
return array.slice(i * n, i * n + n); | ||
}); | ||
}(response, QUEUE_LIMIT); | ||
return pMapSeries(chunkedData, function (resources) { | ||
var down = 0; | ||
return Promise.all(resources.map(function (resource) { | ||
return fetchResource(resource).then(function (data) { | ||
if (!data.up) { | ||
down++; | ||
} // time must be between 3 and 3000 ms | ||
// if 2 or more providers in one batch fail, drop all results | ||
if (down > 1 || data.up && (data.time < 3 || data.time > 3000)) { | ||
return; | ||
} | ||
return storeResults(metadata, results.splice(0, results.length)); | ||
} | ||
}); | ||
}).then(function () { | ||
if (down <= 1 && results.length) { | ||
return storeResults(metadata, results); | ||
} | ||
results.push(data); | ||
}); | ||
})); | ||
}); | ||
}).then(logInfo, logError).then(function () { | ||
done = true; | ||
resolvers.forEach(function (resolve) { | ||
return resolve(); | ||
}); | ||
finished = true; | ||
numberOfRepeat += 1; | ||
store(true); | ||
}).then(function () { | ||
if (numberOfRepeat < REPEAT_COUNT) { | ||
setTimeout(processor, REPEAT_DELAY); | ||
} | ||
}); | ||
}, 3000); | ||
}; // eslint-disable-next-line comma-dangle | ||
// prettier-ignore | ||
setTimeout(processor, 3000); | ||
} | ||
function storeResults(metadata, data) { | ||
return fetch('https://devnull.perfops.net/rum/v1', { | ||
return fetch("".concat(API_URL, "/rum/v1"), { | ||
data: JSON.stringify({ | ||
@@ -325,5 +417,6 @@ metadata: metadata, | ||
method: 'POST' | ||
}).then(function (request) { | ||
globalStoreMeta = JSON.parse(request.response); | ||
}).catch(logError); | ||
}).catch(function (err) { | ||
logError(err); | ||
throw data; | ||
}); | ||
} | ||
@@ -340,6 +433,27 @@ | ||
onLoad(function () { | ||
if (typeof window.performance === 'undefined') { | ||
/** | ||
* Try to prevent loading the script at all for the major bots/crawlers. | ||
* This is the first line defence against serving our scripts to crawlers. | ||
* Warns in console if we aren't loading, to aid support. | ||
**/ | ||
var knownBots = ['bot', 'headless', 'google', 'baidu', 'bing', 'msn', 'duckduckbot', 'teoma', 'slurp', 'yandex', 'phantomjs', 'pingdom', 'ahrefsbot']; | ||
var botString = knownBots.join('|'); | ||
var botTestRegex = new RegExp(botString, 'i'); | ||
var isProbablyBot = botTestRegex.test(window.navigator.userAgent); | ||
if (isProbablyBot) { | ||
console.warn('PerfOps RUM not launching due to suspicious userAgent:', window.navigator.userAgent); | ||
return; | ||
} | ||
if (typeof window.performance === 'undefined') { | ||
return; | ||
} // Clear performance API entries buffer when full | ||
performance.onresourcetimingbufferfull = function () { | ||
logInfo('clear performance resource buffer'); | ||
performance.clearResourceTimings(); | ||
}; | ||
if (typeof Promise === 'function') { | ||
@@ -354,26 +468,2 @@ return run(); | ||
}); | ||
window.perfopsRumJs = { | ||
getResults: function getResults() { | ||
return new Promise(function (resolve) { | ||
if (done) { | ||
return resolve(globalResults); | ||
} | ||
resolvers.push(function () { | ||
return resolve(globalResults); | ||
}); | ||
}); | ||
}, | ||
getStoreMeta: function getStoreMeta() { | ||
return new Promise(function (resolve) { | ||
if (done) { | ||
return resolve(globalStoreMeta); | ||
} | ||
resolvers.push(function () { | ||
return resolve(globalStoreMeta); | ||
}); | ||
}); | ||
} | ||
}; | ||
})(window.Promise); |
@@ -1,1 +0,1 @@ | ||
"use strict";!function(u){var n,t=-1!==function(){}.toString().indexOf("minified")?{logInfo:console.log,logError:console.error}:{logInfo:function(){},logError:function(){}},e=t.logInfo,a=t.logError,c=window.rum?window.rum.key:void 0,r=null,d=[],o=[],p=!1;function i(r,n){var t=1<arguments.length&&void 0!==n?n:{},e=t.cb,o=void 0===e?function(){}:e,c=t.data,d=t.method,p=void 0===d?"GET":d,i=t.timeout,s=void 0===i?3e3:i;return new u(function(n,t){var e=new XMLHttpRequest;e.onload=function(){return n(e)},e.onerror=e.ontimeout=function(){a(e),t(new Error("Status ".concat(e.status,". Response: ").concat(e.statusText)))},e.open(p,r),e.timeout=s,o(e),e.send(c)})}function s(){setTimeout(function(){i("https://rum-cdn.perfops.net/providers").then(function(n){return JSON.parse(n.response)}).then(function(n){if(!n||!n.data||!n.data.length)throw new Error("Empty response.data");return n}).catch(function(){return{data:[{id:1,cdnUrl:"https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",p:1},{id:30,cdnUrl:"https://perfops.doracdn.com/500b-db-bench.jpg",p:1},{id:18,cdnUrl:"https://azure-perfops1.azureedge.net/500b-azure-bench.jpg",p:1},{id:24,cdnUrl:"https://img-cdnperf.mncdn.com/500b-bench.jpg",p:0},{id:2,cdnUrl:"https://ovh-cdn.perfops.io/500b-bench.jpg",p:0},{id:29,cdnUrl:"https://25748s.ha.azioncdn.net/500b-az-bench.jpg",p:0},{id:8,cdnUrl:"https://perfops.gcdn.co/500b-bench.jpg",p:1},{id:12,cdnUrl:"https://cdn.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",p:1},{id:7,cdnUrl:"https://google-cdn.perfops.io/500b-google-bench.jpg",p:1},{id:38,cdnUrl:"https://perf.psychz.net/500b-bench.jpg",p:0},{id:35,cdnUrl:"https://cdn81795137.blazingcdn.net/500b-blz-bench.jpg",p:1},{id:10,cdnUrl:"https://akamai-perfops.azureedge.net/500b-aka-bench.jpg",p:1},{id:36,cdnUrl:"https://perfops-cc.cdn-tech.io/500b-cc-bench.jpg",p:0},{id:5,cdnUrl:"https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",p:1},{id:13,cdnUrl:"https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",p:1},{id:15,cdnUrl:"https://cdnperf-rum.cdnetworks.net/500b-bench.jpg",p:1},{id:14,cdnUrl:"https://perfops.r.worldssl.net/500b-bench.jpg",p:1},{id:17,cdnUrl:"https://edgecast-cdn.cdnperf.com/500b-bench.jpg",p:1},{id:22,cdnUrl:"https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg",p:0},{id:11,cdnUrl:"https://perfops.b-cdn.net/500b-bench.jpg",p:1},{id:3,cdnUrl:"https://perfops.perfstack.cf-china.info/500b-bench.jpg",p:1},{id:4,cdnUrl:"https://fastly.jsdelivr.net/gh/ProspectOne/js-test@1.1/500b-bench.jpg",p:1},{id:9,cdnUrl:"https://1933886249.rsc.cdn77.org/500b-bench.jpg",p:1},{id:20,cdnUrl:"https://cdnperf.cachefly.net/500b-bench.jpg",p:1},{id:6,cdnUrl:"https://perfops-ade2.kxcdn.com/500b-bench.jpg",p:1}]}}).then(function(n){var t=[],e={ua:navigator.userAgent,hostname:window.location.hostname,client:c},r=0,o=0;return function(n,r){return n.reduce(function(n,e){return n.then(function(t){return r(e).then(function(n){return t.push(n),t})})},u.resolve([]))}(n.data,function(n){return function(r){var o="".concat(r.cdnUrl,"?t=").concat(Date.now());return i(o).then(function(n){var t=performance.getEntriesByName(o)[0],e={id:r.id};return 200<=n.status&&n.status<300&&(e=Object.assign({},e,{up:1,time:Number((t.responseEnd-t.requestStart).toFixed(2)),dnsLookupTime:Number((t.domainLookupEnd-t.domainLookupStart).toFixed(2)),headers:n.getAllResponseHeaders()})),300<=n.status&&n.status<=500&&(e=Object.assign({},e,{up:0,dnsLookupTime:Number((t.domainLookupEnd-t.domainLookupStart).toFixed(2)),headers:n.getAllResponseHeaders()})),e}).catch(function(){return{id:r.id,up:0}})}(n).then(function(n){if(d.push(n),n.up?2e3<n.time&&r++:o++,!(1<o||n.up&&(n.time<3||3e3<n.time)))return 2<=t.push(n)?(o=0,r<2?(r=0,h(e,t.splice(0,t.length))):(r=0,t.splice(0,t.length))):void 0})}).then(function(){if(o<=1&&t.length)return h(e,t)})}).then(e,a).then(function(){p=!0,o.forEach(function(n){return n()})})},3e3)}function h(n,t){return i("https://devnull.perfops.net/rum/v1",{data:JSON.stringify({metadata:n,data:t}),method:"POST"}).then(function(n){r=JSON.parse(n.response)}).catch(a)}n=function(){if(void 0!==window.performance)return"function"==typeof u?s():void function(n,t){var e,r=document.createElement("script");r.onreadystatechange=r.onload=function(){e||t(),e=!0},r.setAttribute("src",n),document.body.appendChild(r)}("https://cdn.jsdelivr.net/npm/es6-promise@4.2.4/dist/es6-promise.min.js",function(){u=window.ES6Promise,s()})},"complete"===document.readyState?n():window.addEventListener("load",n),window.perfopsRumJs={getResults:function(){return new u(function(n){if(p)return n(d);o.push(function(){return n(d)})})},getStoreMeta:function(){return new u(function(n){if(p)return n(r);o.push(function(){return n(r)})})}}}(window.Promise); | ||
"use strict";function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,n){if(e){if("string"==typeof e)return _arrayLikeToArray(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,n):void 0}}function _iterableToArray(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}!function(d){var e,a="https://devnull.perfops.net",s="https://rum-cdn.perfops.net/providers",p=3e5,n=-1!==function(){}.toString().indexOf("minified")?{logInfo:console.log,logError:console.error}:{logInfo:function(){},logError:function(){}},u=n.logInfo,l=n.logError,h=window.rum?window.rum.key:void 0;function f(e){return Math.max(0,Number(e.toFixed(2)))}function g(r,e){var n=1<arguments.length&&void 0!==e?e:{},t=n.cb,o=void 0===t?function(){}:t,c=n.data,i=n.method,a=void 0===i?"GET":i,s=n.timeout,p=void 0===s?3e3:s;return new d(function(e,n){var t=new XMLHttpRequest;t.onload=function(){return e(t)},t.onerror=t.ontimeout=function(){l(t),n(new Error("Status ".concat(t.status,". Response: ").concat(t.statusText)))},t.open(a,r),t.timeout=p,o(t),t.send(c)})}function t(){function n(e){var n=0<arguments.length&&void 0!==e&&e;if(u("Try to store ".concat(o.length," items")),i&&0===o.length&&(u("Store data interval cleared"),clearInterval(r)),o.length<1)u("Batch is empty");else if(o.length<3&&!n)u("Batch is to small. Wait for more results");else{var t=o.reduce(function(e,n){return e+(2e3<n.time?1:0)},0);if(t===o.length)return u("Skip batch of a ".concat(t," slow probes")),void o.splice(0,t);(function(e,n){return g("".concat(a,"/rum/v1"),{data:JSON.stringify({metadata:e,data:n}),method:"POST"}).catch(function(e){throw l(e),n})})(c,o.splice(0,o.length)).then(function(){return u("Results stored")}).catch(function(e){var n;return(n=o).push.apply(n,_toConsumableArray(e))})}}var r,o=[],c={ua:navigator.userAgent,hostname:window.location.hostname,client:h},i=!1,t=0;setTimeout(function e(){i=!1,clearInterval(r),o=[],r=setInterval(n,1e3),function(){var n="perfops-rum-resources",e=JSON.parse(window.localStorage.getItem(n));return e&&e.expiry>Date.now()?d.resolve(e.data):g(s).then(function(e){return JSON.parse(e.response)}).then(function(e){if(!e||!e.data||!e.data.length)throw new Error("Empty response.data");return window.localStorage.setItem(n,JSON.stringify({data:e.data,expiry:Date.now()+p})),e.data}).catch(function(){return{data:[{id:39,cdnUrl:"https://cdnperf-rum.cdnetworks.net/500b-bench.jpg",p:0},{id:17,cdnUrl:"https://edgecast-cdn.perfops.io/500b-bench.jpg",p:1},{id:18,cdnUrl:"https://azure-perfops.azureedge.net/500b-bench.jpg",p:1},{id:22,cdnUrl:"https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg",p:0},{id:36,cdnUrl:"https://perfops-cc.cdn-tech.io/500b-cc-bench.jpg",p:0},{id:30,cdnUrl:"https://perfops.doracdn.com/500b-db-bench.jpg",p:1},{id:10,cdnUrl:"https://akamai-perfops2.azureedge.net/500b-bench.jpg",p:1},{id:20,cdnUrl:"https://cdnperf.cachefly.net/500b-bench.jpg",p:1},{id:5,cdnUrl:"https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",p:1},{id:12,cdnUrl:"https://cdn.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",p:1},{id:3,cdnUrl:"https://perfops.perfstack.cf-china.info/500b-bench.jpg",p:1},{id:8,cdnUrl:"https://perfops.gcdn.co/500b-bench.jpg",p:1},{id:9,cdnUrl:"https://1933886249.rsc.cdn77.org/500b-bench.jpg",p:1},{id:14,cdnUrl:"https://perfops.r.worldssl.net/500b-bench.jpg",p:1},{id:4,cdnUrl:"https://fastly.jsdelivr.net/gh/ProspectOne/js-test@1.1/500b-bench.jpg",p:1},{id:13,cdnUrl:"https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",p:1},{id:7,cdnUrl:"https://google-cdn.perfops.io/500b-google-bench.jpg",p:1},{id:1,cdnUrl:"https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",p:1},{id:35,cdnUrl:"https://cdn81795137.blazingcdn.net/500b-blz-bench.jpg",p:1},{id:2,cdnUrl:"https://ovh-cdn.perfops.io/500b-bench.jpg",p:1},{id:24,cdnUrl:"https://img-cdnperf.mncdn.com/500b-bench.jpg",p:0},{id:11,cdnUrl:"https://perfops.b-cdn.net/500b-bench.jpg",p:1},{id:15,cdnUrl:"https://cdnperf-rum.cdnetworks.net/500b-bench.jpg",p:1},{id:38,cdnUrl:"https://perf.psychz.net/500b-bench.jpg",p:0},{id:6,cdnUrl:"https://perfops-ade2.kxcdn.com/500b-bench.jpg",p:1}]}})}().then(function(e){var t;return function(e,r){return e.reduce(function(e,t){return e.then(function(n){return r(t).then(function(e){return n.push(e),n})})},d.resolve([]))}((t=e,Array.from(Array(Math.ceil(t.length/2)),function(e,n){return t.slice(2*n,2*n+2)})),function(e){var n=0;return d.all(e.map(function(e){return function(i){var a="".concat(i.cdnUrl,"?t=").concat(Date.now()),s=new URL(a).hostname;return g(a).then(function(e){var n=performance.getEntriesByName(a)[0],t={id:i.id,domain:s},r=f(n.domainLookupEnd-n.domainLookupStart),o=f(n.connectEnd-n.connectStart),c=0<o?f(n.connectEnd-n.secureConnectionStart):0;return 200<=e.status&&e.status<300&&(t=Object.assign({},t,{up:1,time:Number((n.responseEnd-n.requestStart).toFixed(2)),dnsLookupTime:r,tcpTime:o,sslTime:c,headers:e.getAllResponseHeaders()})),300<=e.status&&e.status<=500&&(t=Object.assign({},t,{up:0,dnsLookupTime:r,tcpTime:o,sslTime:c,headers:e.getAllResponseHeaders()})),t}).catch(function(){return{id:i.id,up:0}})}(e).then(function(e){e.up||n++,1<n||e.up&&(e.time<3||3e3<e.time)||o.push(e)})}))})}).then(u,l).then(function(){t+=1,n(i=!0)}).then(function(){t<3&&setTimeout(e,6e4)})},3e3)}e=function(){var e=["bot","headless","google","baidu","bing","msn","duckduckbot","teoma","slurp","yandex","phantomjs","pingdom","ahrefsbot"].join("|");if(new RegExp(e,"i").test(window.navigator.userAgent))console.warn("PerfOps RUM not launching due to suspicious userAgent:",window.navigator.userAgent);else if(void 0!==window.performance){if(performance.onresourcetimingbufferfull=function(){u("clear performance resource buffer"),performance.clearResourceTimings()},"function"==typeof d)return t();!function(e,n){var t,r=document.createElement("script");r.onreadystatechange=r.onload=function(){t||n(),t=!0},r.setAttribute("src",e),document.body.appendChild(r)}("https://cdn.jsdelivr.net/npm/es6-promise@4.2.4/dist/es6-promise.min.js",function(){d=window.ES6Promise,t()})}},"complete"===document.readyState?e():window.addEventListener("load",e)}(window.Promise); |
{ | ||
"name": "perfops-rom", | ||
"version": "1.1.16", | ||
"version": "1.1.17", | ||
"jsdelivr": "./dist/rom3.min.js", | ||
@@ -5,0 +5,0 @@ "description": "RUM code for https://perfops.net/", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
44918
776
9