Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

perfops-rom

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

perfops-rom - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

618

dist/rom.js
"use strict";
(function (LocalPromise) {
var RESOURCES_URL = 'https://api.perfops.net/rum-cdn.php';
var RESOURCES_TTL = 5 * 60 * 1000; // Resources list TTL in the LocalStorage
(function (Promise) {
var QUEUE_LIMIT = 2;
var REPEAT_DELAY = 60 * 1000; // How often the script will measure CDN performance while user staying on the same page
var _ref = function () {
/* minified */
}.toString().indexOf('minified') !== -1 ? {
logInfo: console.log,
logError: console.error
} : {
logInfo: function logInfo() {},
logError: function logError() {}
},
logInfo = _ref.logInfo,
logError = _ref.logError;
/**
* 1. Load Promise shim
* 2. Timeout before start
* 3. Fetch providers list
* 3.1. Check in LocalStorage if list already fetched
* 3.2. Fetch from the server and store to LocalStorage
* 4. Run probes
* 4.1. Run as WebWorker if supported
* 4.2. Run as a regular script instead
* 5. Set timeout to run again later
*/
var clientKey = window.rum ? window.rum.key : undefined;
var globalStoreMeta = null;
var globalResults = [];
var resolvers = [];
var done = false;
/**
* @param { MessageEvent } event
*/
function fetch(url) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref2$cb = _ref2.cb,
cb = _ref2$cb === void 0 ? function () {} : _ref2$cb,
data = _ref2.data,
_ref2$method = _ref2.method,
method = _ref2$method === void 0 ? 'GET' : _ref2$method,
_ref2$timeout = _ref2.timeout,
timeout = _ref2$timeout === void 0 ? 3000 : _ref2$timeout;
function workerProcessor(event) {
var API_URL = 'https://devnull.perfops.net/rum/v1';
var QUEUE_LIMIT = 3; // eslint-disable-next-line no-undef
var LocalPromise = typeof Promise === 'function' ? Promise : ES6Promise;
var _ref = function () {
/* minified */
}.toString().indexOf('minified') !== -1 ? {
logInfo: console.log,
logError: console.error
} : {
logInfo: function logInfo() {},
logError: function logError() {}
},
logInfo = _ref.logInfo,
logError = _ref.logError;
var _event$data = event.data,
client = _event$data.client,
hostname = _event$data.hostname,
resources = _event$data.resources;
function pMapSeries(array, fn) {
return array.reduce(function (acc, value) {
return acc.then(function (array) {
return fn(value).then(function (result) {
return array.push(result), array;
});
});
}, LocalPromise.resolve([]));
}
/**
* Worker scoped implementation
*/
function fetch(url) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref2$cb = _ref2.cb,
cb = _ref2$cb === void 0 ? function () {} : _ref2$cb,
data = _ref2.data,
_ref2$method = _ref2.method,
method = _ref2$method === void 0 ? 'GET' : _ref2$method,
_ref2$timeout = _ref2.timeout,
timeout = _ref2$timeout === void 0 ? 3000 : _ref2$timeout;
return new LocalPromise(_fetchHandler(url, cb, data, method, timeout));
}
function fetchResource(resource) {
var url = "".concat(resource.cdnUrl, "?t=").concat(Date.now());
return fetch(url).then(function (xhr) {
var timing = performance.getEntriesByName(url)[0]; // Workaround for performance API limit of 250 entries
performance.clearResourceTimings();
var result = {
id: resource.id
};
if (xhr.status >= 200 && xhr.status < 300) {
// Add success response measurements
result = Object.assign({}, result, {
up: 1,
time: Number((timing.responseEnd - timing.requestStart).toFixed(2)),
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)),
tcpTime: Number((timing.connectEnd - timing.connectStart).toFixed(2)),
sslTime: Number((timing.connectEnd - timing.secureConnectionStart).toFixed(2)),
headers: xhr.getAllResponseHeaders()
});
}
if (xhr.status >= 300 && xhr.status <= 500) {
// HTTP Redirect/Error
result = Object.assign({}, result, {
up: 0,
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)),
headers: xhr.getAllResponseHeaders()
});
}
return result;
}).catch(function () {
return {
id: resource.id,
up: 0
};
});
}
function storeResults(metadata, data) {
return fetch(API_URL, {
data: JSON.stringify({
metadata: metadata,
data: data
}),
method: 'POST'
}).catch(logError);
}
return LocalPromise.resolve(resources).then(function (response) {
var metadata = {
ua: navigator.userAgent,
hostname: hostname,
client: client
};
var tooSlow = 0;
var down = 0;
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) {
return LocalPromise.all(resources.map(function (resource) {
return fetchResource(resource).then(function (data) {
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 (down > 1 || data.up && (data.time < 3 || data.time > 3000)) {
return;
}
return data;
});
})).then(function (res) {
down = 0;
if (tooSlow < QUEUE_LIMIT) {
tooSlow = 0;
} else {
tooSlow = 0;
return;
}
return storeResults(metadata, res);
});
});
}).then(logInfo, logError).then(function () {
return postMessage(true);
});
}
/**
* Common handler for fetch functions in the main thread and in the worker.
* Because worker do not share the code with the parent we can't just use
* regular fetch function there so must define local one in the worker.
*/
function _fetchHandler(url, cb, data, method, timeout) {
return function (resolve, reject) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();

@@ -190,2 +42,3 @@

xhr.onerror = xhr.ontimeout = function () {
logError(xhr);
reject(new Error("Status ".concat(xhr.status, ". Response: ").concat(xhr.statusText)));

@@ -199,130 +52,53 @@ };

xhr.send(data);
};
});
}
/**
* Local implementation
*/
function fetchJs(url, cb) {
var script = document.createElement('script'),
loaded;
function fetch(url) {
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref3$cb = _ref3.cb,
cb = _ref3$cb === void 0 ? function () {} : _ref3$cb,
data = _ref3.data,
_ref3$method = _ref3.method,
method = _ref3$method === void 0 ? 'GET' : _ref3$method,
_ref3$timeout = _ref3.timeout,
timeout = _ref3$timeout === void 0 ? 3000 : _ref3$timeout;
script.onreadystatechange = script.onload = function () {
if (!loaded) {
cb();
}
return new LocalPromise(_fetchHandler(url, cb, data, method, timeout));
loaded = true;
};
script.setAttribute('src', url);
document.body.appendChild(script);
}
function fetchResourceList() {
var key = 'perfops-rum-resources';
var resources = JSON.parse(window.localStorage.getItem(key));
function fetchResource(resource) {
var url = "".concat(resource.cdnUrl, "?t=").concat(Date.now());
return fetch(url).then(function (xhr) {
var timing = performance.getEntriesByName(url)[0];
var result = {
id: resource.id
};
if (resources && resources.expiry > Date.now()) {
return LocalPromise.resolve(resources.data);
}
if (xhr.status >= 200 && xhr.status < 300) {
// Add success response measurements
result = Object.assign({}, result, {
up: 1,
time: Number((timing.responseEnd - timing.requestStart).toFixed(2)),
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)),
headers: xhr.getAllResponseHeaders()
});
}
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');
if (xhr.status >= 300 && xhr.status <= 500) {
// HTTP Redirect/Error
result = Object.assign({}, result, {
up: 0,
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)),
headers: xhr.getAllResponseHeaders()
});
}
window.localStorage.setItem(key, JSON.stringify({
data: response.data,
expiry: Date.now() + RESOURCES_TTL
}));
return response.data;
return result;
}).catch(function () {
// eslint-disable-next-line
return {
"data": [{
"id": 17,
"cdnUrl": "https://edgecast.perfstack.net/8086B5F/bench/500b-bench.jpg",
"p": "1"
}, {
"id": 9,
"cdnUrl": "https://1933886249.rsc.cdn77.org/500b-bench.jpg",
"p": "1"
}, {
"id": 4,
"cdnUrl": "https://fastly.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",
"p": "1"
}, {
"id": 10,
"cdnUrl": "https://akamai.perfstack.net/500b-bench.jpg",
"p": "1"
}, {
"id": 29,
"cdnUrl": "https://25748s.ha.azioncdn.net/500b-bench.jpg",
"p": "0"
}, {
"id": 15,
"cdnUrl": "https://cdnperf-rum.cdnetworks.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": 24,
"cdnUrl": "https://img-cdnperf.mncdn.com/500b-bench.jpg",
"p": "1"
}, {
"id": 11,
"cdnUrl": "https://perfops.b-cdn.net/500b-bench.jpg",
"p": "1"
}, {
"id": 7,
"cdnUrl": "https://googlecdn.perfstack.net/5002b-bench.jpg",
"p": "1"
}, {
"id": 3,
"cdnUrl": "https://perfops.perfstack.cf-china.info/500b-bench.jpg",
"p": "1"
}, {
"id": 13,
"cdnUrl": "https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",
"p": "1"
}, {
"id": 14,
"cdnUrl": "https://perfops.r.worldssl.net/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": 2,
"cdnUrl": "https://ovhcdn.perfstack.net/500b-bench.jpg",
"p": "1"
}, {
"id": 8,
"cdnUrl": "https://perfops.gcdn.co/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"
}, {
"id": 1,
"cdnUrl": "https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",
"p": "1"
}, {
"id": 5,
"cdnUrl": "https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",
"p": "1"
}]
id: resource.id,
up: 0
};

@@ -332,62 +108,202 @@ });

function run() {
// eslint-disable-next-line comma-dangle
new LocalPromise(function (resolve) {
return setTimeout(resolve, 1000);
}).then(function () {
return fetchResourceList().then(function (resources) {
var metadata = {
client: window.rum ? window.rum.key : undefined,
hostname: window.location.hostname,
resources: resources
};
function fetchResourceList() {
return fetch('https://api.perfops.net/rum-cdn.php').then(function (xhr) {
return JSON.parse(xhr.response);
});
} // eslint-disable-next-line no-unused-vars
if (window.Worker) {
var inlineWorkerFn = "(event) => {\n\t\t\t\t\t\t".concat(_fetchHandler.toString(), "\n\t\t\t\t\t\t").concat(workerProcessor.toString(), "\n\t\t\t\t\t\t").concat(workerProcessor.name, "(event);\n\t\t\t\t\t}");
var blob = new Blob(['self.onmessage = ', inlineWorkerFn], {
type: 'text/javascript'
});
var url = URL.createObjectURL(blob);
var worker = new Worker(url);
worker.onmessage = function () {
return setTimeout(function () {
return worker.postMessage(metadata);
}, REPEAT_DELAY);
};
function fetchResourceListTest() {
return Promise.resolve({
data: [{
id: 1,
cdnUrl: 'http://localhost:9999'
}]
});
} // eslint-disable-next-line no-unused-vars
worker.postMessage(metadata);
return;
} // No WebWorkers support
function logSample(data) {
var oneIn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
data.clientVersion = '1';
var handleFallback = function handleFallback() {
workerProcessor({
data: metadata
}).then(function () {
return setTimeout(handleFallback, REPEAT_DELAY);
});
};
if (Math.random() < 1 / oneIn) {
fetch('https://devnull.perfops.net/debug/log', {
data: JSON.stringify(data),
method: 'POST'
});
}
}
handleFallback();
function pMapSeries(array, fn) {
return array.reduce(function (acc, value) {
return acc.then(function (array) {
return fn(value).then(function (result) {
return array.push(result), array;
});
});
});
}, Promise.resolve([]));
}
function fetchJs(url, cb) {
var script = document.createElement('script'),
loaded;
function run() {
setTimeout(function () {
fetchResourceList().then(function (response) {
if (!response || !response.data || !response.data.length) {
throw new Error('Empty response.data');
}
script.onreadystatechange = script.onload = function () {
if (!loaded) {
cb();
}
return response;
}).catch(function () {
// eslint-disable-next-line
return {
"data": [{
"id": 13,
"cdnUrl": "https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",
"p": "1"
}, {
"id": 10,
"cdnUrl": "https://akamai.perfstack.net/500b-bench.jpg",
"p": "1"
}, {
"id": 24,
"cdnUrl": "https://img-cdnperf.mncdn.com/500b-bench.jpg",
"p": "1"
}, {
"id": 14,
"cdnUrl": "https://perfops.r.worldssl.net/500b-bench.jpg",
"p": "1"
}, {
"id": 22,
"cdnUrl": "https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg",
"p": "0"
}, {
"id": 29,
"cdnUrl": "https://25748s.ha.azioncdn.net/500b-bench.jpg",
"p": "0"
}, {
"id": 1,
"cdnUrl": "https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",
"p": "1"
}, {
"id": 17,
"cdnUrl": "https://edgecast.perfstack.net/8086B5F/bench/500b-bench.jpg",
"p": "1"
}, {
"id": 9,
"cdnUrl": "https://1933886249.rsc.cdn77.org/500b-bench.jpg",
"p": "1"
}, {
"id": 15,
"cdnUrl": "https://cdnperf-rum.cdnetworks.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": 5,
"cdnUrl": "https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",
"p": "1"
}, {
"id": 8,
"cdnUrl": "https://perfops.gcdn.co/500b-bench.jpg",
"p": "1"
}, {
"id": 3,
"cdnUrl": "https://perfops.perfstack.cf-china.info/500b-bench.jpg",
"p": "1"
}, {
"id": 7,
"cdnUrl": "https://googlecdn.perfstack.net/5002b-bench.jpg",
"p": "1"
}, {
"id": 2,
"cdnUrl": "https://ovhcdn.perfstack.net/500b-bench.jpg",
"p": "1"
}, {
"id": 18,
"cdnUrl": "https://azure-perfops.azureedge.net/500b-bench.jpg",
"p": "1"
}, {
"id": 4,
"cdnUrl": "https://fastly.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",
"p": "1"
}, {
"id": 6,
"cdnUrl": "https://perfops-ade2.kxcdn.com/500b-bench.jpg",
"p": "1"
}, {
"id": 20,
"cdnUrl": "https://cdnperf.cachefly.net/500b-bench.jpg",
"p": "1"
}, {
"id": 11,
"cdnUrl": "https://perfops.b-cdn.net/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);
loaded = true;
};
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
script.setAttribute('src', url);
document.body.appendChild(script);
if (down > 1 || data.up && (data.time < 3 || data.time > 3000)) {
return;
}
if (results.push(data) >= QUEUE_LIMIT) {
down = 0;
if (tooSlow < QUEUE_LIMIT) {
tooSlow = 0;
} else {
tooSlow = 0;
return results.splice(0, results.length);
}
return storeResults(metadata, results.splice(0, results.length));
}
});
}).then(function () {
if (down <= 1 && results.length) {
return storeResults(metadata, results);
}
});
}).then(logInfo, logError).then(function () {
done = true;
resolvers.forEach(function (resolve) {
return resolve();
});
}); // eslint-disable-next-line comma-dangle
}, 1000);
}
function storeResults(metadata, data) {
return fetch('https://devnull.perfops.net/rum/v1', {
data: JSON.stringify({
metadata: metadata,
data: data
}),
method: 'POST'
}).then(function (request) {
globalStoreMeta = JSON.parse(request.response);
}).catch(logError);
}
function onLoad(fn) {

@@ -411,6 +327,30 @@ if (document.readyState === 'complete') {

fetchJs('https://cdn.jsdelivr.net/npm/es6-promise@4.2.4/dist/es6-promise.min.js', function () {
LocalPromise = window.ES6Promise;
Promise = window.ES6Promise;
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(a){var t,e="https://api.perfops.net/rum-cdn.php",r=3e5;function i(t){var a="function"==typeof Promise?Promise:ES6Promise,n=-1!==function(){}.toString().indexOf("minified")?{logInfo:console.log,logError:console.error}:{logInfo:function(){},logError:function(){}},e=n.logInfo,c=n.logError,r=t.data,i=r.client,s=r.hostname,o=r.resources;function d(t,n){var e=1<arguments.length&&void 0!==n?n:{},r=e.cb,o=void 0===r?function(){}:r,c=e.data,i=e.method,s=void 0===i?"GET":i,d=e.timeout;return new a(p(t,o,c,s,void 0===d?3e3:d))}return a.resolve(o).then(function(t){var e,n={ua:navigator.userAgent,hostname:s,client:i},r=0,o=0;return function(t,r){return t.reduce(function(t,e){return t.then(function(n){return r(e).then(function(t){return n.push(t),n})})},a.resolve([]))}((e=t,Array.from(Array(Math.ceil(e.length/3)),function(t,n){return e.slice(3*n,3*n+3)})),function(t){return a.all(t.map(function(t){return function(r){var o="".concat(r.cdnUrl,"?t=").concat(Date.now());return d(o).then(function(t){var n=performance.getEntriesByName(o)[0];performance.clearResourceTimings();var e={id:r.id};return 200<=t.status&&t.status<300&&(e=Object.assign({},e,{up:1,time:Number((n.responseEnd-n.requestStart).toFixed(2)),dnsLookupTime:Number((n.domainLookupEnd-n.domainLookupStart).toFixed(2)),tcpTime:Number((n.connectEnd-n.connectStart).toFixed(2)),sslTime:Number((n.connectEnd-n.secureConnectionStart).toFixed(2)),headers:t.getAllResponseHeaders()})),300<=t.status&&t.status<=500&&(e=Object.assign({},e,{up:0,dnsLookupTime:Number((n.domainLookupEnd-n.domainLookupStart).toFixed(2)),headers:t.getAllResponseHeaders()})),e}).catch(function(){return{id:r.id,up:0}})}(t).then(function(t){if(t.up?2e3<t.time&&r++:o++,!(1<o||t.up&&(t.time<3||3e3<t.time)))return t})})).then(function(t){if(o=0,r<3)return r=0,function(t,n){return d("https://devnull.perfops.net/rum/v1",{data:JSON.stringify({metadata:t,data:n}),method:"POST"}).catch(c)}(n,t);r=0})})}).then(e,c).then(function(){return postMessage(!0)})}function p(r,o,c,i,s){return function(t,n){var e=new XMLHttpRequest;e.onload=function(){return t(e)},e.onerror=e.ontimeout=function(){n(new Error("Status ".concat(e.status,". Response: ").concat(e.statusText)))},e.open(i,r),e.timeout=s,o(e),e.send(c)}}function n(){var n="perfops-rum-resources",t=JSON.parse(window.localStorage.getItem(n));return t&&t.expiry>Date.now()?a.resolve(t.data):function(t,n){var e=1<arguments.length&&void 0!==n?n:{},r=e.cb,o=void 0===r?function(){}:r,c=e.data,i=e.method,s=void 0===i?"GET":i,d=e.timeout;return new a(p(t,o,c,s,void 0===d?3e3:d))}(e).then(function(t){return JSON.parse(t.response)}).then(function(t){if(!t||!t.data||!t.data.length)throw new Error("Empty response.data");return window.localStorage.setItem(n,JSON.stringify({data:t.data,expiry:Date.now()+r})),t.data}).catch(function(){return{data:[{id:17,cdnUrl:"https://edgecast.perfstack.net/8086B5F/bench/500b-bench.jpg",p:"1"},{id:9,cdnUrl:"https://1933886249.rsc.cdn77.org/500b-bench.jpg",p:"1"},{id:4,cdnUrl:"https://fastly.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",p:"1"},{id:10,cdnUrl:"https://akamai.perfstack.net/500b-bench.jpg",p:"1"},{id:29,cdnUrl:"https://25748s.ha.azioncdn.net/500b-bench.jpg",p:"0"},{id:15,cdnUrl:"https://cdnperf-rum.cdnetworks.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:24,cdnUrl:"https://img-cdnperf.mncdn.com/500b-bench.jpg",p:"1"},{id:11,cdnUrl:"https://perfops.b-cdn.net/500b-bench.jpg",p:"1"},{id:7,cdnUrl:"https://googlecdn.perfstack.net/5002b-bench.jpg",p:"1"},{id:3,cdnUrl:"https://perfops.perfstack.cf-china.info/500b-bench.jpg",p:"1"},{id:13,cdnUrl:"https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",p:"1"},{id:14,cdnUrl:"https://perfops.r.worldssl.net/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:2,cdnUrl:"https://ovhcdn.perfstack.net/500b-bench.jpg",p:"1"},{id:8,cdnUrl:"https://perfops.gcdn.co/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"},{id:1,cdnUrl:"https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",p:"1"},{id:5,cdnUrl:"https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",p:"1"}]}})}function o(){new a(function(t){return setTimeout(t,1e3)}).then(function(){return n().then(function(t){var n={client:window.rum?window.rum.key:void 0,hostname:window.location.hostname,resources:t};if(window.Worker){var e="(event) => {\n\t\t\t\t\t\t".concat(p.toString(),"\n\t\t\t\t\t\t").concat(i.toString(),"\n\t\t\t\t\t\t").concat(i.name,"(event);\n\t\t\t\t\t}"),r=new Blob(["self.onmessage = ",e],{type:"text/javascript"}),o=URL.createObjectURL(r),c=new Worker(o);return c.onmessage=function(){return setTimeout(function(){return c.postMessage(n)},6e4)},void c.postMessage(n)}!function t(){i({data:n}).then(function(){return setTimeout(t,6e4)})}()})})}t=function(){if(void 0!==window.performance)return"function"==typeof Promise?o():void function(t,n){var e,r=document.createElement("script");r.onreadystatechange=r.onload=function(){e||n(),e=!0},r.setAttribute("src",t),document.body.appendChild(r)}("https://cdn.jsdelivr.net/npm/es6-promise@4.2.4/dist/es6-promise.min.js",function(){a=window.ES6Promise,o()})},"complete"===document.readyState?t():window.addEventListener("load",t)}(window.Promise);
"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,i=[],o=[],d=!1;function p(r,n){var t=1<arguments.length&&void 0!==n?n:{},e=t.cb,o=void 0===e?function(){}:e,c=t.data,i=t.method,d=void 0===i?"GET":i,p=t.timeout,s=void 0===p?3e3:p;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(d,r),e.timeout=s,o(e),e.send(c)})}function s(){setTimeout(function(){p("https://api.perfops.net/rum-cdn.php").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:13,cdnUrl:"https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",p:"1"},{id:10,cdnUrl:"https://akamai.perfstack.net/500b-bench.jpg",p:"1"},{id:24,cdnUrl:"https://img-cdnperf.mncdn.com/500b-bench.jpg",p:"1"},{id:14,cdnUrl:"https://perfops.r.worldssl.net/500b-bench.jpg",p:"1"},{id:22,cdnUrl:"https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg",p:"0"},{id:29,cdnUrl:"https://25748s.ha.azioncdn.net/500b-bench.jpg",p:"0"},{id:1,cdnUrl:"https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",p:"1"},{id:17,cdnUrl:"https://edgecast.perfstack.net/8086B5F/bench/500b-bench.jpg",p:"1"},{id:9,cdnUrl:"https://1933886249.rsc.cdn77.org/500b-bench.jpg",p:"1"},{id:15,cdnUrl:"https://cdnperf-rum.cdnetworks.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:5,cdnUrl:"https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",p:"1"},{id:8,cdnUrl:"https://perfops.gcdn.co/500b-bench.jpg",p:"1"},{id:3,cdnUrl:"https://perfops.perfstack.cf-china.info/500b-bench.jpg",p:"1"},{id:7,cdnUrl:"https://googlecdn.perfstack.net/5002b-bench.jpg",p:"1"},{id:2,cdnUrl:"https://ovhcdn.perfstack.net/500b-bench.jpg",p:"1"},{id:18,cdnUrl:"https://azure-perfops.azureedge.net/500b-bench.jpg",p:"1"},{id:4,cdnUrl:"https://fastly.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",p:"1"},{id:6,cdnUrl:"https://perfops-ade2.kxcdn.com/500b-bench.jpg",p:"1"},{id:20,cdnUrl:"https://cdnperf.cachefly.net/500b-bench.jpg",p:"1"},{id:11,cdnUrl:"https://perfops.b-cdn.net/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 p(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(i.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(){d=!0,o.forEach(function(n){return n()})})},1e3)}function h(n,t){return p("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(d)return n(i);o.push(function(){return n(i)})})},getStoreMeta:function(){return new u(function(n){if(d)return n(r);o.push(function(){return n(r)})})}}}(window.Promise);
"use strict";
(function (LocalPromise) {
var RESOURCES_URL = 'https://api.perfops.net/rum-cdn.php';
var RESOURCES_TTL = 5 * 60 * 1000; // Resources list TTL in the LocalStorage
(function (Promise) {
var QUEUE_LIMIT = 2;
var REPEAT_DELAY = 60 * 1000; // How often the script will measure CDN performance while user staying on the same page
var _ref = function () {
/* minified */
}.toString().indexOf('minified') !== -1 ? {
logInfo: console.log,
logError: console.error
} : {
logInfo: function logInfo() {},
logError: function logError() {}
},
logInfo = _ref.logInfo,
logError = _ref.logError;
/**
* 1. Load Promise shim
* 2. Timeout before start
* 3. Fetch providers list
* 3.1. Check in LocalStorage if list already fetched
* 3.2. Fetch from the server and store to LocalStorage
* 4. Run probes
* 4.1. Run as WebWorker if supported
* 4.2. Run as a regular script instead
* 5. Set timeout to run again later
*/
var clientKey = window.rum ? window.rum.key : undefined;
var globalStoreMeta = null;
var globalResults = [];
var resolvers = [];
var done = false;
/**
* @param { MessageEvent } event
*/
function fetch(url) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref2$cb = _ref2.cb,
cb = _ref2$cb === void 0 ? function () {} : _ref2$cb,
data = _ref2.data,
_ref2$method = _ref2.method,
method = _ref2$method === void 0 ? 'GET' : _ref2$method,
_ref2$timeout = _ref2.timeout,
timeout = _ref2$timeout === void 0 ? 3000 : _ref2$timeout;
function workerProcessor(event) {
var API_URL = 'https://devnull.perfops.net/rum/v1';
var QUEUE_LIMIT = 3; // eslint-disable-next-line no-undef
var LocalPromise = typeof Promise === 'function' ? Promise : ES6Promise;
var _ref = function () {
/* minified */
}.toString().indexOf('minified') !== -1 ? {
logInfo: console.log,
logError: console.error
} : {
logInfo: function logInfo() {},
logError: function logError() {}
},
logInfo = _ref.logInfo,
logError = _ref.logError;
var _event$data = event.data,
client = _event$data.client,
hostname = _event$data.hostname,
resources = _event$data.resources;
function pMapSeries(array, fn) {
return array.reduce(function (acc, value) {
return acc.then(function (array) {
return fn(value).then(function (result) {
return array.push(result), array;
});
});
}, LocalPromise.resolve([]));
}
/**
* Worker scoped implementation
*/
function fetch(url) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref2$cb = _ref2.cb,
cb = _ref2$cb === void 0 ? function () {} : _ref2$cb,
data = _ref2.data,
_ref2$method = _ref2.method,
method = _ref2$method === void 0 ? 'GET' : _ref2$method,
_ref2$timeout = _ref2.timeout,
timeout = _ref2$timeout === void 0 ? 3000 : _ref2$timeout;
return new LocalPromise(_fetchHandler(url, cb, data, method, timeout));
}
function fetchResource(resource) {
var url = "".concat(resource.cdnUrl, "?t=").concat(Date.now());
return fetch(url).then(function (xhr) {
var timing = performance.getEntriesByName(url)[0]; // Workaround for performance API limit of 250 entries
performance.clearResourceTimings();
var result = {
id: resource.id
};
if (xhr.status >= 200 && xhr.status < 300) {
// Add success response measurements
result = Object.assign({}, result, {
up: 1,
time: Number((timing.responseEnd - timing.requestStart).toFixed(2)),
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)),
tcpTime: Number((timing.connectEnd - timing.connectStart).toFixed(2)),
sslTime: Number((timing.connectEnd - timing.secureConnectionStart).toFixed(2)),
headers: xhr.getAllResponseHeaders()
});
}
if (xhr.status >= 300 && xhr.status <= 500) {
// HTTP Redirect/Error
result = Object.assign({}, result, {
up: 0,
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)),
headers: xhr.getAllResponseHeaders()
});
}
return result;
}).catch(function () {
return {
id: resource.id,
up: 0
};
});
}
function storeResults(metadata, data) {
return fetch(API_URL, {
data: JSON.stringify({
metadata: metadata,
data: data
}),
method: 'POST'
}).catch(logError);
}
return LocalPromise.resolve(resources).then(function (response) {
var metadata = {
ua: navigator.userAgent,
hostname: hostname,
client: client
};
var tooSlow = 0;
var down = 0;
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) {
return LocalPromise.all(resources.map(function (resource) {
return fetchResource(resource).then(function (data) {
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 (down > 1 || data.up && (data.time < 3 || data.time > 3000)) {
return;
}
return data;
});
})).then(function (res) {
down = 0;
if (tooSlow < QUEUE_LIMIT) {
tooSlow = 0;
} else {
tooSlow = 0;
return;
}
return storeResults(metadata, res);
});
});
}).then(logInfo, logError).then(function () {
return postMessage(true);
});
}
/**
* Common handler for fetch functions in the main thread and in the worker.
* Because worker do not share the code with the parent we can't just use
* regular fetch function there so must define local one in the worker.
*/
function _fetchHandler(url, cb, data, method, timeout) {
return function (resolve, reject) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();

@@ -190,2 +42,3 @@

xhr.onerror = xhr.ontimeout = function () {
logError(xhr);
reject(new Error("Status ".concat(xhr.status, ". Response: ").concat(xhr.statusText)));

@@ -199,130 +52,53 @@ };

xhr.send(data);
};
});
}
/**
* Local implementation
*/
function fetchJs(url, cb) {
var script = document.createElement('script'),
loaded;
function fetch(url) {
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref3$cb = _ref3.cb,
cb = _ref3$cb === void 0 ? function () {} : _ref3$cb,
data = _ref3.data,
_ref3$method = _ref3.method,
method = _ref3$method === void 0 ? 'GET' : _ref3$method,
_ref3$timeout = _ref3.timeout,
timeout = _ref3$timeout === void 0 ? 3000 : _ref3$timeout;
script.onreadystatechange = script.onload = function () {
if (!loaded) {
cb();
}
return new LocalPromise(_fetchHandler(url, cb, data, method, timeout));
loaded = true;
};
script.setAttribute('src', url);
document.body.appendChild(script);
}
function fetchResourceList() {
var key = 'perfops-rum-resources';
var resources = JSON.parse(window.localStorage.getItem(key));
function fetchResource(resource) {
var url = "".concat(resource.cdnUrl, "?t=").concat(Date.now());
return fetch(url).then(function (xhr) {
var timing = performance.getEntriesByName(url)[0];
var result = {
id: resource.id
};
if (resources && resources.expiry > Date.now()) {
return LocalPromise.resolve(resources.data);
}
if (xhr.status >= 200 && xhr.status < 300) {
// Add success response measurements
result = Object.assign({}, result, {
up: 1,
time: Number((timing.responseEnd - timing.requestStart).toFixed(2)),
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)),
headers: xhr.getAllResponseHeaders()
});
}
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');
if (xhr.status >= 300 && xhr.status <= 500) {
// HTTP Redirect/Error
result = Object.assign({}, result, {
up: 0,
dnsLookupTime: Number((timing.domainLookupEnd - timing.domainLookupStart).toFixed(2)),
headers: xhr.getAllResponseHeaders()
});
}
window.localStorage.setItem(key, JSON.stringify({
data: response.data,
expiry: Date.now() + RESOURCES_TTL
}));
return response.data;
return result;
}).catch(function () {
// eslint-disable-next-line
return {
"data": [{
"id": 17,
"cdnUrl": "https://edgecast.perfstack.net/8086B5F/bench/500b-bench.jpg",
"p": "1"
}, {
"id": 9,
"cdnUrl": "https://1933886249.rsc.cdn77.org/500b-bench.jpg",
"p": "1"
}, {
"id": 4,
"cdnUrl": "https://fastly.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",
"p": "1"
}, {
"id": 10,
"cdnUrl": "https://akamai.perfstack.net/500b-bench.jpg",
"p": "1"
}, {
"id": 29,
"cdnUrl": "https://25748s.ha.azioncdn.net/500b-bench.jpg",
"p": "0"
}, {
"id": 15,
"cdnUrl": "https://cdnperf-rum.cdnetworks.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": 24,
"cdnUrl": "https://img-cdnperf.mncdn.com/500b-bench.jpg",
"p": "1"
}, {
"id": 11,
"cdnUrl": "https://perfops.b-cdn.net/500b-bench.jpg",
"p": "1"
}, {
"id": 7,
"cdnUrl": "https://googlecdn.perfstack.net/5002b-bench.jpg",
"p": "1"
}, {
"id": 3,
"cdnUrl": "https://perfops.perfstack.cf-china.info/500b-bench.jpg",
"p": "1"
}, {
"id": 13,
"cdnUrl": "https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",
"p": "1"
}, {
"id": 14,
"cdnUrl": "https://perfops.r.worldssl.net/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": 2,
"cdnUrl": "https://ovhcdn.perfstack.net/500b-bench.jpg",
"p": "1"
}, {
"id": 8,
"cdnUrl": "https://perfops.gcdn.co/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"
}, {
"id": 1,
"cdnUrl": "https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",
"p": "1"
}, {
"id": 5,
"cdnUrl": "https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",
"p": "1"
}]
id: resource.id,
up: 0
};

@@ -332,62 +108,202 @@ });

function run() {
// eslint-disable-next-line comma-dangle
new LocalPromise(function (resolve) {
return setTimeout(resolve, 3000);
}).then(function () {
return fetchResourceList().then(function (resources) {
var metadata = {
client: window.rum ? window.rum.key : undefined,
hostname: window.location.hostname,
resources: resources
};
function fetchResourceList() {
return fetch('https://api.perfops.net/rum-cdn.php').then(function (xhr) {
return JSON.parse(xhr.response);
});
} // eslint-disable-next-line no-unused-vars
if (window.Worker) {
var inlineWorkerFn = "(event) => {\n\t\t\t\t\t\t".concat(_fetchHandler.toString(), "\n\t\t\t\t\t\t").concat(workerProcessor.toString(), "\n\t\t\t\t\t\t").concat(workerProcessor.name, "(event);\n\t\t\t\t\t}");
var blob = new Blob(['self.onmessage = ', inlineWorkerFn], {
type: 'text/javascript'
});
var url = URL.createObjectURL(blob);
var worker = new Worker(url);
worker.onmessage = function () {
return setTimeout(function () {
return worker.postMessage(metadata);
}, REPEAT_DELAY);
};
function fetchResourceListTest() {
return Promise.resolve({
data: [{
id: 1,
cdnUrl: 'http://localhost:9999'
}]
});
} // eslint-disable-next-line no-unused-vars
worker.postMessage(metadata);
return;
} // No WebWorkers support
function logSample(data) {
var oneIn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
data.clientVersion = '1';
var handleFallback = function handleFallback() {
workerProcessor({
data: metadata
}).then(function () {
return setTimeout(handleFallback, REPEAT_DELAY);
});
};
if (Math.random() < 1 / oneIn) {
fetch('https://devnull.perfops.net/debug/log', {
data: JSON.stringify(data),
method: 'POST'
});
}
}
handleFallback();
function pMapSeries(array, fn) {
return array.reduce(function (acc, value) {
return acc.then(function (array) {
return fn(value).then(function (result) {
return array.push(result), array;
});
});
});
}, Promise.resolve([]));
}
function fetchJs(url, cb) {
var script = document.createElement('script'),
loaded;
function run() {
setTimeout(function () {
fetchResourceList().then(function (response) {
if (!response || !response.data || !response.data.length) {
throw new Error('Empty response.data');
}
script.onreadystatechange = script.onload = function () {
if (!loaded) {
cb();
}
return response;
}).catch(function () {
// eslint-disable-next-line
return {
"data": [{
"id": 13,
"cdnUrl": "https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",
"p": "1"
}, {
"id": 10,
"cdnUrl": "https://akamai.perfstack.net/500b-bench.jpg",
"p": "1"
}, {
"id": 24,
"cdnUrl": "https://img-cdnperf.mncdn.com/500b-bench.jpg",
"p": "1"
}, {
"id": 14,
"cdnUrl": "https://perfops.r.worldssl.net/500b-bench.jpg",
"p": "1"
}, {
"id": 22,
"cdnUrl": "https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg",
"p": "0"
}, {
"id": 29,
"cdnUrl": "https://25748s.ha.azioncdn.net/500b-bench.jpg",
"p": "0"
}, {
"id": 1,
"cdnUrl": "https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",
"p": "1"
}, {
"id": 17,
"cdnUrl": "https://edgecast.perfstack.net/8086B5F/bench/500b-bench.jpg",
"p": "1"
}, {
"id": 9,
"cdnUrl": "https://1933886249.rsc.cdn77.org/500b-bench.jpg",
"p": "1"
}, {
"id": 15,
"cdnUrl": "https://cdnperf-rum.cdnetworks.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": 5,
"cdnUrl": "https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",
"p": "1"
}, {
"id": 8,
"cdnUrl": "https://perfops.gcdn.co/500b-bench.jpg",
"p": "1"
}, {
"id": 3,
"cdnUrl": "https://perfops.perfstack.cf-china.info/500b-bench.jpg",
"p": "1"
}, {
"id": 7,
"cdnUrl": "https://googlecdn.perfstack.net/5002b-bench.jpg",
"p": "1"
}, {
"id": 2,
"cdnUrl": "https://ovhcdn.perfstack.net/500b-bench.jpg",
"p": "1"
}, {
"id": 18,
"cdnUrl": "https://azure-perfops.azureedge.net/500b-bench.jpg",
"p": "1"
}, {
"id": 4,
"cdnUrl": "https://fastly.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",
"p": "1"
}, {
"id": 6,
"cdnUrl": "https://perfops-ade2.kxcdn.com/500b-bench.jpg",
"p": "1"
}, {
"id": 20,
"cdnUrl": "https://cdnperf.cachefly.net/500b-bench.jpg",
"p": "1"
}, {
"id": 11,
"cdnUrl": "https://perfops.b-cdn.net/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);
loaded = true;
};
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
script.setAttribute('src', url);
document.body.appendChild(script);
if (down > 1 || data.up && (data.time < 3 || data.time > 3000)) {
return;
}
if (results.push(data) >= QUEUE_LIMIT) {
down = 0;
if (tooSlow < QUEUE_LIMIT) {
tooSlow = 0;
} else {
tooSlow = 0;
return results.splice(0, results.length);
}
return storeResults(metadata, results.splice(0, results.length));
}
});
}).then(function () {
if (down <= 1 && results.length) {
return storeResults(metadata, results);
}
});
}).then(logInfo, logError).then(function () {
done = true;
resolvers.forEach(function (resolve) {
return resolve();
});
}); // eslint-disable-next-line comma-dangle
}, 3000);
}
function storeResults(metadata, data) {
return fetch('https://devnull.perfops.net/rum/v1', {
data: JSON.stringify({
metadata: metadata,
data: data
}),
method: 'POST'
}).then(function (request) {
globalStoreMeta = JSON.parse(request.response);
}).catch(logError);
}
function onLoad(fn) {

@@ -411,6 +327,30 @@ if (document.readyState === 'complete') {

fetchJs('https://cdn.jsdelivr.net/npm/es6-promise@4.2.4/dist/es6-promise.min.js', function () {
LocalPromise = window.ES6Promise;
Promise = window.ES6Promise;
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(a){var t,e="https://api.perfops.net/rum-cdn.php",r=3e5;function i(t){var a="function"==typeof Promise?Promise:ES6Promise,n=-1!==function(){}.toString().indexOf("minified")?{logInfo:console.log,logError:console.error}:{logInfo:function(){},logError:function(){}},e=n.logInfo,c=n.logError,r=t.data,i=r.client,s=r.hostname,o=r.resources;function d(t,n){var e=1<arguments.length&&void 0!==n?n:{},r=e.cb,o=void 0===r?function(){}:r,c=e.data,i=e.method,s=void 0===i?"GET":i,d=e.timeout;return new a(p(t,o,c,s,void 0===d?3e3:d))}return a.resolve(o).then(function(t){var e,n={ua:navigator.userAgent,hostname:s,client:i},r=0,o=0;return function(t,r){return t.reduce(function(t,e){return t.then(function(n){return r(e).then(function(t){return n.push(t),n})})},a.resolve([]))}((e=t,Array.from(Array(Math.ceil(e.length/3)),function(t,n){return e.slice(3*n,3*n+3)})),function(t){return a.all(t.map(function(t){return function(r){var o="".concat(r.cdnUrl,"?t=").concat(Date.now());return d(o).then(function(t){var n=performance.getEntriesByName(o)[0];performance.clearResourceTimings();var e={id:r.id};return 200<=t.status&&t.status<300&&(e=Object.assign({},e,{up:1,time:Number((n.responseEnd-n.requestStart).toFixed(2)),dnsLookupTime:Number((n.domainLookupEnd-n.domainLookupStart).toFixed(2)),tcpTime:Number((n.connectEnd-n.connectStart).toFixed(2)),sslTime:Number((n.connectEnd-n.secureConnectionStart).toFixed(2)),headers:t.getAllResponseHeaders()})),300<=t.status&&t.status<=500&&(e=Object.assign({},e,{up:0,dnsLookupTime:Number((n.domainLookupEnd-n.domainLookupStart).toFixed(2)),headers:t.getAllResponseHeaders()})),e}).catch(function(){return{id:r.id,up:0}})}(t).then(function(t){if(t.up?2e3<t.time&&r++:o++,!(1<o||t.up&&(t.time<3||3e3<t.time)))return t})})).then(function(t){if(o=0,r<3)return r=0,function(t,n){return d("https://devnull.perfops.net/rum/v1",{data:JSON.stringify({metadata:t,data:n}),method:"POST"}).catch(c)}(n,t);r=0})})}).then(e,c).then(function(){return postMessage(!0)})}function p(r,o,c,i,s){return function(t,n){var e=new XMLHttpRequest;e.onload=function(){return t(e)},e.onerror=e.ontimeout=function(){n(new Error("Status ".concat(e.status,". Response: ").concat(e.statusText)))},e.open(i,r),e.timeout=s,o(e),e.send(c)}}function n(){var n="perfops-rum-resources",t=JSON.parse(window.localStorage.getItem(n));return t&&t.expiry>Date.now()?a.resolve(t.data):function(t,n){var e=1<arguments.length&&void 0!==n?n:{},r=e.cb,o=void 0===r?function(){}:r,c=e.data,i=e.method,s=void 0===i?"GET":i,d=e.timeout;return new a(p(t,o,c,s,void 0===d?3e3:d))}(e).then(function(t){return JSON.parse(t.response)}).then(function(t){if(!t||!t.data||!t.data.length)throw new Error("Empty response.data");return window.localStorage.setItem(n,JSON.stringify({data:t.data,expiry:Date.now()+r})),t.data}).catch(function(){return{data:[{id:17,cdnUrl:"https://edgecast.perfstack.net/8086B5F/bench/500b-bench.jpg",p:"1"},{id:9,cdnUrl:"https://1933886249.rsc.cdn77.org/500b-bench.jpg",p:"1"},{id:4,cdnUrl:"https://fastly.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",p:"1"},{id:10,cdnUrl:"https://akamai.perfstack.net/500b-bench.jpg",p:"1"},{id:29,cdnUrl:"https://25748s.ha.azioncdn.net/500b-bench.jpg",p:"0"},{id:15,cdnUrl:"https://cdnperf-rum.cdnetworks.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:24,cdnUrl:"https://img-cdnperf.mncdn.com/500b-bench.jpg",p:"1"},{id:11,cdnUrl:"https://perfops.b-cdn.net/500b-bench.jpg",p:"1"},{id:7,cdnUrl:"https://googlecdn.perfstack.net/5002b-bench.jpg",p:"1"},{id:3,cdnUrl:"https://perfops.perfstack.cf-china.info/500b-bench.jpg",p:"1"},{id:13,cdnUrl:"https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",p:"1"},{id:14,cdnUrl:"https://perfops.r.worldssl.net/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:2,cdnUrl:"https://ovhcdn.perfstack.net/500b-bench.jpg",p:"1"},{id:8,cdnUrl:"https://perfops.gcdn.co/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"},{id:1,cdnUrl:"https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",p:"1"},{id:5,cdnUrl:"https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",p:"1"}]}})}function o(){new a(function(t){return setTimeout(t,3e3)}).then(function(){return n().then(function(t){var n={client:window.rum?window.rum.key:void 0,hostname:window.location.hostname,resources:t};if(window.Worker){var e="(event) => {\n\t\t\t\t\t\t".concat(p.toString(),"\n\t\t\t\t\t\t").concat(i.toString(),"\n\t\t\t\t\t\t").concat(i.name,"(event);\n\t\t\t\t\t}"),r=new Blob(["self.onmessage = ",e],{type:"text/javascript"}),o=URL.createObjectURL(r),c=new Worker(o);return c.onmessage=function(){return setTimeout(function(){return c.postMessage(n)},6e4)},void c.postMessage(n)}!function t(){i({data:n}).then(function(){return setTimeout(t,6e4)})}()})})}t=function(){if(void 0!==window.performance)return"function"==typeof Promise?o():void function(t,n){var e,r=document.createElement("script");r.onreadystatechange=r.onload=function(){e||n(),e=!0},r.setAttribute("src",t),document.body.appendChild(r)}("https://cdn.jsdelivr.net/npm/es6-promise@4.2.4/dist/es6-promise.min.js",function(){a=window.ES6Promise,o()})},"complete"===document.readyState?t():window.addEventListener("load",t)}(window.Promise);
"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,i=[],o=[],d=!1;function p(r,n){var t=1<arguments.length&&void 0!==n?n:{},e=t.cb,o=void 0===e?function(){}:e,c=t.data,i=t.method,d=void 0===i?"GET":i,p=t.timeout,s=void 0===p?3e3:p;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(d,r),e.timeout=s,o(e),e.send(c)})}function s(){setTimeout(function(){p("https://api.perfops.net/rum-cdn.php").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:13,cdnUrl:"https://m9d7v5r2.map2.ssl.hwcdn.net/500b-bench.jpg",p:"1"},{id:10,cdnUrl:"https://akamai.perfstack.net/500b-bench.jpg",p:"1"},{id:24,cdnUrl:"https://img-cdnperf.mncdn.com/500b-bench.jpg",p:"1"},{id:14,cdnUrl:"https://perfops.r.worldssl.net/500b-bench.jpg",p:"1"},{id:22,cdnUrl:"https://09d3da8545e855ce.cdn.gocache.net/500b-bench.jpg",p:"0"},{id:29,cdnUrl:"https://25748s.ha.azioncdn.net/500b-bench.jpg",p:"0"},{id:1,cdnUrl:"https://kgmni17536myjst.belugacdn.link/500b-bench.jpg",p:"1"},{id:17,cdnUrl:"https://edgecast.perfstack.net/8086B5F/bench/500b-bench.jpg",p:"1"},{id:9,cdnUrl:"https://1933886249.rsc.cdn77.org/500b-bench.jpg",p:"1"},{id:15,cdnUrl:"https://cdnperf-rum.cdnetworks.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:5,cdnUrl:"https://d2axgrpnciinw7.cloudfront.net/500b-bench.jpg",p:"1"},{id:8,cdnUrl:"https://perfops.gcdn.co/500b-bench.jpg",p:"1"},{id:3,cdnUrl:"https://perfops.perfstack.cf-china.info/500b-bench.jpg",p:"1"},{id:7,cdnUrl:"https://googlecdn.perfstack.net/5002b-bench.jpg",p:"1"},{id:2,cdnUrl:"https://ovhcdn.perfstack.net/500b-bench.jpg",p:"1"},{id:18,cdnUrl:"https://azure-perfops.azureedge.net/500b-bench.jpg",p:"1"},{id:4,cdnUrl:"https://fastly.jsdelivr.net/gh/jimaek/js-test@1.1/500b-bench.jpg",p:"1"},{id:6,cdnUrl:"https://perfops-ade2.kxcdn.com/500b-bench.jpg",p:"1"},{id:20,cdnUrl:"https://cdnperf.cachefly.net/500b-bench.jpg",p:"1"},{id:11,cdnUrl:"https://perfops.b-cdn.net/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 p(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(i.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(){d=!0,o.forEach(function(n){return n()})})},3e3)}function h(n,t){return p("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(d)return n(i);o.push(function(){return n(i)})})},getStoreMeta:function(){return new u(function(n){if(d)return n(r);o.push(function(){return n(r)})})}}}(window.Promise);
{
"name": "perfops-rom",
"version": "1.1.0",
"version": "1.1.1",
"jsdelivr": "./dist/rom3.min.js",

@@ -5,0 +5,0 @@ "description": "RUM code for https://perfops.net/",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc