Skip to content

Instantly share code, notes, and snippets.

@chromy
Created July 7, 2023 08:29
Show Gist options
  • Save chromy/e83deb52558724fc332181050af18521 to your computer and use it in GitHub Desktop.
Save chromy/e83deb52558724fc332181050af18521 to your computer and use it in GitHub Desktop.
<html>
<head>
</head>
<body>
<script>
function openTrace(arrayBuffer, title) {
const PERFETTO_ORIGIN = "https://ui.perfetto.dev";
const win = window.open(PERFETTO_ORIGIN);
if (!win || win.closed || typeof win.closed == "undefined") {
console.log("Popup blocked!");
return false;
}
const ping_func = () => {
win.postMessage("PING", PERFETTO_ORIGIN);
};
const timer = setInterval(ping_func, 50);
const onMessageHandler = (evt) => {
if (evt.data !== "PONG") return;
// We got a PONG, the UI is ready.
window.clearInterval(timer);
window.removeEventListener("message", onMessageHandler);
console.log("Posting message with buffer length: " + arrayBuffer.byteLength)
const message = {
perfetto: {
buffer: arrayBuffer,
title: title,
},
};
win.postMessage(message, PERFETTO_ORIGIN);
};
window.addEventListener("message", onMessageHandler);
return true;
}
openTrace(new ArrayBuffer(8), "Hello, world!");
</script>
</body>
</html>
try:
from http import server # Python 3
except ImportError:
import SimpleHTTPServer as server # Python 2
class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
server.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
# Try with and without this line commented out:
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
pass
if __name__ == '__main__':
server.test(HandlerClass=MyHTTPRequestHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment