Skip to content

Instantly share code, notes, and snippets.

@nicjansma
Last active July 23, 2018 15:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicjansma/10dc57bae1f6cf139630c6b055d23f98 to your computer and use it in GitHub Desktop.
Save nicjansma/10dc57bae1f6cf139630c6b055d23f98 to your computer and use it in GitHub Desktop.
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