fix postmessage proxy

This commit is contained in:
velzie 2024-08-02 13:47:15 -04:00
parent a29e8c42a3
commit b8334993ae
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
5 changed files with 34 additions and 8 deletions

View file

@ -8,10 +8,17 @@ export default function (client: ScramjetClient, self: Self) {
const handlers = {
message: {
origin() {
return this.data.$scramjet$origin;
if (typeof this.data === "object" && "$scramjet$origin" in this.data)
return this.data.$scramjet$origin;
// then it must be from a worker, which we aren't currently rewriting
return client.url.origin;
},
data() {
return this.data.$scramjet$data;
if (typeof this.data === "object" && "$scramjet$data" in this.data)
return this.data.$scramjet$data;
return this.data;
},
},
};
@ -46,8 +53,8 @@ export default function (client: ScramjetClient, self: Self) {
client.Proxy("EventTarget.prototype.addEventListener", {
apply(ctx) {
unproxy(ctx, client);
if (typeof ctx.args[1] === "object")
// if (ctx.args[0] === "message" && iswindow) debugger;
if (typeof ctx.args[1] === "function")
ctx.args[1] = wraplistener(ctx.args[1]);
},
});