Skip to content

Commit

Permalink
fixed bug when running on browsers :about pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Mrowetz committed Feb 7, 2015
1 parent 3cce646 commit 03ae374
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Logs
logs
*.log
.DS_Store

# Editor Project Files
*.sublime-project
Expand Down
69 changes: 45 additions & 24 deletions dist/performanceBookmarklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Initiallize Bookmarklet wide variables, holders and helpers - all other files on
*/

//bookmarklet wide vars
var tablesToLog = [],
var tablesToLog = [],
resources,
allResourcesCalc,
marks,
Expand All @@ -23,6 +23,10 @@ var tablesToLog = [],
outputHolder,
outputContent;

//skip browser internal pages
if(location.protocol === "about:"){
return;
}

//feature check gate
if(window.performance && window.performance.getEntriesByType !== undefined) {
Expand Down Expand Up @@ -341,47 +345,61 @@ Tiles to summarize page performance


onIFrameLoaded(function(){
var requestsOnly,
requestsByDomain,
currAndSubdomainRequests,
crossDocDomainRequests,
hostRequests,
hostSubdomains,
slowestCalls,
average,
createTile,
createAppendixDefValue,
tilesHolder,
appendix;

//filter out non-http[s] and sourcemaps
var requestsOnly = allResourcesCalc.filter(function(currR) {
requestsOnly = allResourcesCalc.filter(function(currR) {
return currR.name.indexOf("http") === 0 && !currR.name.match(/js.map$/);
});

var requestsByDomain = getItemCount(requestsOnly.map(function(currR, i, arr){
requestsByDomain = getItemCount(requestsOnly.map(function(currR, i, arr){
return currR.domain;
}), "domain");

var currAndSubdomainRequests = requestsOnly.filter(function(domain){
currAndSubdomainRequests = requestsOnly.filter(function(domain){
return domain.domain.split(".").slice(-2).join(".") === location.host.split(".").slice(-2).join(".");
}).length;

var crossDocDomainRequests = requestsOnly.filter(function(domain){
crossDocDomainRequests = requestsOnly.filter(function(domain){
return !endsWith(domain.domain, document.domain);
}).length;

var hostRequests = requestsOnly.filter(function(domain){
hostRequests = requestsOnly.filter(function(domain){
return domain.domain === location.host;
}).length;

var hostSubdomains = requestsByDomain.filter(function(domain){
hostSubdomains = requestsByDomain.filter(function(domain){
return endsWith(domain.domain, location.host.split(".").slice(-2).join(".")) && domain.domain !== location.host;
}).length;

var slowestCalls = allResourcesCalc.filter(function(a){
return a.name !== location.href;
}).sort(function(a, b) {
return b.duration - a.duration;
});
if(allResourcesCalc.length > 0){
slowestCalls = allResourcesCalc.filter(function(a){
return a.name !== location.href;
}).sort(function(a, b) {
return b.duration - a.duration;
});

var average = Math.floor(slowestCalls.reduceRight(function(a,b){
if(typeof a !== "number"){
return a.duration + b.duration
}
return a + b.duration;
}) / slowestCalls.length);
average = Math.floor(slowestCalls.reduceRight(function(a,b){
if(typeof a !== "number"){
return a.duration + b.duration
}
return a + b.duration;
}) / slowestCalls.length);
}


var createTile = function(title, value, titleFontSize){
createTile = function(title, value, titleFontSize){
titleFontSize = titleFontSize || 60;
var dl = newTag("dl", {
class : "summary-tile"
Expand All @@ -391,12 +409,12 @@ onIFrameLoaded(function(){
return dl;
};

var createAppendixDefValue = function(a, definition, value){
createAppendixDefValue = function(a, definition, value){
a.appendChild(newTag("dt", {html : definition}));
a.appendChild(newTag("dd", {html : value}));
};

var tilesHolder = newTag("div", {
tilesHolder = newTag("div", {
class : "tiles-holder"
});

Expand All @@ -409,10 +427,13 @@ onIFrameLoaded(function(){
tilesHolder.appendChild(createTile("Time to First Byte", perfTiming.responseStart - perfTiming.navigationStart + "ms", 40));
tilesHolder.appendChild(createTile("<span title=\"domLoading to domContentLoadedEventStart\">DOM Content Loading</span>", perfTiming.domContentLoadedEventStart - perfTiming.domLoading + "ms", 40));
tilesHolder.appendChild(createTile("<span title=\"domLoading to loadEventStart\">DOM Processing</span>", perfTiming.domComplete - perfTiming.domLoading + "ms", 40));
tilesHolder.appendChild(createTile("<span title=\"" + slowestCalls[0].name +"\">Slowest Call</span>", "<span title=\"" + slowestCalls[0].name +"\">"+ Math.floor(slowestCalls[0].duration) + "ms</span>", 40));
tilesHolder.appendChild(createTile("Average Call", average + "ms", 40));

if(allResourcesCalc.length > 0){
tilesHolder.appendChild(createTile("<span title=\"" + slowestCalls[0].name +"\">Slowest Call</span>", "<span title=\"" + slowestCalls[0].name +"\">"+ Math.floor(slowestCalls[0].duration) + "ms</span>", 40));
tilesHolder.appendChild(createTile("Average Call", average + "ms", 40));
}

var appendix = newTag("dl", {
appendix = newTag("dl", {
class : "summary-tile-appendix"
});

Expand Down
Loading

0 comments on commit 03ae374

Please sign in to comment.