This file contains 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
(function(w) { | |
if (w != top) return | |
w.addEventListener('load', function() { | |
var iframe = document.createElement('iframe') | |
iframe.style.display = 'none' | |
iframe.src = location.href | |
document.body.appendChild(iframe) | |
iframe.addEventListener('load', function() { | |
var outer = w.performance |
This file contains 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
function isNativeFunction(fn) { | |
return typeof fn === 'function' && fn.toString && !fn.hasOwnProperty('toString') && | |
/\[native code\]/.test(String(fn)) | |
} | |
function checkNatives(fns) { | |
var results = [] | |
for (var i = 0; i < fns.length; i++) { | |
results[i] = { | |
fn: fns[i], | |
native: isNativeFunction(fns[i]) |
This file contains 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
/****************************************************************************** | |
Copyright (c) 2014, Google Inc. | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions are met: | |
* Redistributions of source code must retain the above copyright notice, | |
this list of conditions and the following disclaimer. | |
* Redistributions in binary form must reproduce the above copyright notice, |
This file contains 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
(function() { | |
if (window !== top) return; | |
const bucketSize = 500, threshold = 30, stamps = [] | |
function measureFps() { | |
const now = performance.now() | |
if (stamps.length) { | |
while (now - stamps[0] > bucketSize) { | |
stamps.shift() | |
} |
This file contains 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
const query = ` | |
CREATE TEMPORARY FUNCTION getHeaders(payload STRING) | |
RETURNS STRING | |
LANGUAGE js AS """ | |
try { | |
var $ = JSON.parse(payload); | |
var headers = $.response.headers; | |
var st = headers.find(function(e) { | |
return e['name'].toLowerCase() === 'server-timing' | |
}); |
This file contains 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
!(function() { | |
const nativePO = window.PerformanceObserver | |
const polyfills = { | |
longtask: LongTaskPolyFill | |
// etc. | |
} | |
window.PerformanceObserver = (callback) => { | |
let po, registeredPolyFills = [] | |
const observe = function(options) { |
This file contains 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
!(function() { | |
const nativePO = window.PerformanceObserver | |
const interfaces = { | |
resource: 'PerformanceResourceTiming', | |
longtask: 'PerformanceLongTaskTiming', | |
// etc. | |
} | |
const polyfills = { | |
longtask: LongTaskPolyFill | |
// etc. |
This file contains 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
function cachedInBrowser(resourceTimingEntry) { | |
if (resourceTimingEntry.requestStart) { | |
// has permissive Timing-Allow-Origin response header | |
return resourceTimingEntry.transferSize === 0 | |
} | |
// because.... physics? | |
return resourceTimingEntry.duration < 30 | |
} |
This file contains 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
(function() { | |
let userThinkTime = 0 | |
;['alert', 'confirm', 'prompt'].forEach(function(methodName) { | |
window[methodName] = (function(method) { | |
return function () { | |
userThinkTime -= performance.now() | |
var returnValue = method.apply(window, arguments) | |
userThinkTime += performance.now() | |
return returnValue |
This file contains 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
;(function() { | |
function getNatives(objects) { | |
if (typeof objects === 'string') { | |
objects = [objects] | |
} | |
var natives = {} | |
if (objects.length) { | |
var iframe = document.createElement('iframe') | |
iframe.style.display = 'none' |