mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-03 07:32:00 +00:00
The MessagePort one in particular is required by Cloudflare Turnstile, as the method it takes to run JS in a worker is to `eval` the contents of `MessageEvent.data`. However, it will only do this if `MessageEvent.isTrusted` is true, `MessageEvent.origin` is the empty string and `MessageEvent.source` is `null`. The Window version is a quick fix whilst in the vicinity, as its MessageEvent should also be trusted.
27 lines
928 B
HTML
27 lines
928 B
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
asyncTest((done) => {
|
|
const iframe = document.createElement("iframe");
|
|
document.body.appendChild(iframe);
|
|
|
|
const script = iframe.contentDocument.createElement("script");
|
|
script.textContent = `
|
|
self.onmessage = (messageEvent) => {
|
|
if (messageEvent.isTrusted && messageEvent.source === window.parent) {
|
|
window.parent.postMessage(messageEvent.data + "pong");
|
|
}
|
|
};
|
|
`;
|
|
iframe.contentDocument.body.appendChild(script);
|
|
|
|
window.onmessage = (messageEvent) => {
|
|
if (messageEvent.isTrusted && messageEvent.source === iframe.contentWindow) {
|
|
println(messageEvent.data);
|
|
done();
|
|
}
|
|
}
|
|
|
|
iframe.contentWindow.postMessage("ping\n", { targetOrigin: "*" });
|
|
});
|
|
</script>
|