Skip to content

Instantly share code, notes, and snippets.

@surfmuggle
Created October 29, 2018 10:05
Show Gist options
  • Save surfmuggle/7df3b3e9d92412f3d457a800e46ea1a9 to your computer and use it in GitHub Desktop.
Save surfmuggle/7df3b3e9d92412f3d457a800e46ea1a9 to your computer and use it in GitHub Desktop.
This is an incomplete snippet - idea is to use greasemonky to measure the pageloadtime
// With GreaseMonkey create a new script that would look like the following:
// ==UserScript==
// @name test
// @description test desc
// @include *://www.mysite.com/*
// @grant none
// @version 0.1
// ==/UserScript==
// (function() {
// document.addEventListener("DOMContentLoaded", function(event) {
// console.log("DOM fully loaded and parsed");
// // Your code should be here.
// });
// })();
/*
* This is a JavaScript Scratchpad.
*
* Enter some JavaScript, then Right Click or choose from the Execute Menu:
* 1. Run to evaluate the selected text (Ctrl+R),
* 2. Inspect to bring up an Object Inspector on the result (Ctrl+I), or,
* 3. Display to insert the result in a comment after the selection. (Ctrl+L)
*/
function KPI(key, value) {
this.key = key;
this.value = value;
}
function right(foo)
{
var s = foo.toString();
var lastFive = s.substring(s.length - 4);
return lastFive;
}
function getPerformanceTimings()
{
var t = window.performance.timing;
var timings = [];
timings.push(["navigationStart", t.navigationStart, right(t.navigationStart) ] );
timings.push(["connectStart", t.connectStart, right(t.connectStart) ] );
timings.push(["requestStart", t.requestStart, right(t.requestStart)] );
timings.push(["responseEnd", t.responseEnd, right(t.responseEnd) ] );
timings.push(["PageLoadTime", ( t.loadEventEnd - t.navigationStart), 0 ] );
// timings.push("navigationStart: " + t.navigationStart );
// timings.push("responseEnd: " + t.responseEnd );
// timings.push("PageLoadTime: " + ( t.loadEventEnd - t.navigationStart));
// timings.push("DOMContentLoadedTime: " + (t.domContentLoadedEventEnd - t.navigationStart ));
// timings.push("ResponseTime: " + (t.responseEnd - t.requestStart) );
// timings.push({ label: "Connection", time: t.connectEnd - t.connectStart });
// timings.push({ label: "Response", time: t.responseEnd - t.responseStart });
// timings.push({ label: "DomainLookup", time: t.domainLookupEnd - t.domainLookupStart });
// timings.push({ label: "LoadEvent", time: t.loadEventEnd - t.loadEventStart });
// timings.push({ label: "UnloadEvent", time: t.unloadEventEnd - t.unloadEventStart });
// timings.push({ label: "DOMContentLoadedEvent", time: t.domContentLoadedEventEnd - t.domContentLoadedEventStart });
// chrome.loadTimes will be removed see https://bugs.chromium.org/p/chromium/issues/detail?id=621512
// var lt = window.chrome && window.chrome.loadTimes && window.chrome.loadTimes();
// if(lt) {
// if(lt.wasNpnNegotiated) {
// timings.push({ label: "NPN negotiation protocol", time: lt.npnNegotiatedProtocol }); }
// timings.push({ label: "ConnectionInfo", time: lt.connectionInfo });
// timings.push({ label: "FirstPaintAfterDocumentLoad", time: Math.ceil(lt.firstPaintTime - lt.finishDocumentLoadTime) });
// }
return timings;
// return perf;
}
console.table(getPerformanceTimings())
/*
undefined
*/
@surfmuggle
Copy link
Author

snippets copied not working together yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment