Skip to content

Instantly share code, notes, and snippets.

@rainydio
Last active December 23, 2019 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rainydio/6ebeef45dc4874703bba4e3be883e05f to your computer and use it in GitHub Desktop.
Save rainydio/6ebeef45dc4874703bba4e3be883e05f to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
#lines {
position: fixed;
top: 0;
left: 0;
white-space: pre;
font-family: monospace;
}
</style>
</head>
<body>
<div id="lines"></div>
<script>
let n = 0;
let lines = [];
window.addEventListener("message", evt => {
if (evt.data.startsWith("dt=")) {
n++;
lines.unshift(`n=${n};${evt.data}`);
lines = lines.slice(0, 25);
document.getElementById("lines").innerHTML = lines.join("\n");
}
});
const script = `
let prev = Date.now();
const fn = () => {
const now = Date.now();
const dt = now - prev;
prev = now;
requestAnimationFrame(fn);
window.parent.postMessage("dt=" + dt, "*");
};
requestAnimationFrame(fn);
`;
const iframe = document.createElement("iframe");
iframe.sandbox = "allow-scripts";
iframe.style.marginTop = "1200px";
iframe.srcdoc = "<script" + `>${script}<` + "/script>";
document.body.appendChild(iframe);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment