Skip to content

Instantly share code, notes, and snippets.

@surfmuggle
Last active December 7, 2017 08:44
Show Gist options
  • Save surfmuggle/01577e5987e236ea46e250ed57d60029 to your computer and use it in GitHub Desktop.
Save surfmuggle/01577e5987e236ea46e250ed57d60029 to your computer and use it in GitHub Desktop.
"use strict"
// MIT Licence a snippet to be run inside the chrome dev tools
// not fully working yet
// see https://stackoverflow.com/questions/47686564/chrome-devtools-run-snippet-to-load-pages
function getPerformanceTimings()
{
var t = window.performance.timing;
var timings = [];
timings.push({ label: "navigationStart", time: t.navigationStart });
timings.push({ label: "PageLoadTime", time: t.loadEventEnd - t.navigationStart });
timings.push({ label: "DOMContentLoadedTime", time: t.domContentLoadedEventEnd - t.navigationStart });
timings.push({ label: "ResponseTime", time: 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;
}
function getData(method, url){
return new Promise(function(resolve, reject){
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function(){
if(this.status >= 200 && this.status < 300){
resolve(xhr.response);
}else {
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function(){
reject({
status: this.status,
statusText: xhr.statusText
});
};
xhr.send();
});
}
function getQuerystring(timings)
{
let querystring = "";
timings.forEach((t) => { querystring+=`${t.label}=${t.time}&`;})
return querystring;
}
function getMainNavigationLinks()
{
var links = []
var list = document.querySelectorAll("div.vw-nav-main li.with-flyout a.main")
for (var item of list) {
links.push(item.href);
}
return links;
}
function loadPage(querystring){
console.log("querystring: ", querystring);
var newURL = window.location.href + "?page=" + window.location.pathname + "&" + querystring
console.log("newURL:",newURL);
window.location.href = newURL;
}
function testPage(linkList)
{
console.log("link", linkList[0]);
if(document.readyState === 'complete')
{
let timings = getPerformanceTimings();
let querystring = getQuerystring(timings);
// let newUrl = linkList[0]+ "?page=measure&" + querystring;
let newUrl = window.location.href + "?page=" + window.location.pathname +"&" + querystring;
console.log("newUrl", newUrl);
window.location.href=newUrl;
}
return linkList.splice(0, 1);
}
/*
function loadPage(url) {
return new Promise((resolve, reject) => {
resolve(console.log("foo resolve"));
reject(console.log("foo reject"));
});
}
*/
// window.addEventListener("load", function(event) {
// console.log("All resources finished loading!");
// });
var linkList = getMainNavigationLinks();
console.log("linkList", linkList);
// console.log("link", linkList[0]); linkList.splice(0, 1);
testPage(linkList);
// testPage(linkList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment