Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Naive ResourceTiming crawl of all IFRAMEs
//
// Naive ResourceTiming crawl of all IFRAMEs.
//
// Based on https://github.com/SOASTA/boomerang/blob/master/plugins/restiming.js
// which you should use to deal with all of the caveats (e.g. startTime adjusting)
//
function isFrameAccessible(frame) {
var dummy;
try {
// try to trigger cross-origin warnings
dummy = frame.location && frame.location.href;
dummy = frame.document;
if (("performance" in frame) && frame.performance) {
return true;
}
}
catch (e) {
// NOP
}
return false;
}
function crawlFrame(frame) {
var entries = [];
try {
if (!isFrameAccessible(frame)) {
return [];
}
if (frame.frames) {
for (var i = 0; i < frame.frames.length; i++) {
entries = entries.concat(crawlFrame(frame.frames[i]));
}
}
if (typeof frame.performance.getEntriesByType !== "function") {
return [];
}
// NOTE: startTime will be off unless fixed, see
// https://github.com/SOASTA/soasta-boomerang/blob/soasta/plugins/restiming.js
// for how.
return entries.concat(frame.performance.getEntriesByType("resource"));
} catch (e) {
// NOP
}
return entries;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment