Last active
July 23, 2018 15:27
-
-
Save nicjansma/10dc57bae1f6cf139630c6b055d23f98 to your computer and use it in GitHub Desktop.
Naive ResourceTiming crawl of all IFRAMEs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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