Created
July 7, 2023 08:29
-
-
Save chromy/e83deb52558724fc332181050af18521 to your computer and use it in GitHub Desktop.
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
<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> | |
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
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