diff --git a/src/client/dom/serviceworker.ts b/src/client/dom/serviceworker.ts index ccf516d..d85bdc1 100644 --- a/src/client/dom/serviceworker.ts +++ b/src/client/dom/serviceworker.ts @@ -25,7 +25,7 @@ export default function (client: ScramjetClient, _self: Self) { > = new WeakMap(); client.Proxy("EventTarget.prototype.addEventListener", { apply(ctx) { - if (registration === ctx.this) { + if (registrationmap.get(ctx.this)) { // do nothing ctx.return(undefined); } @@ -34,7 +34,7 @@ export default function (client: ScramjetClient, _self: Self) { client.Proxy("EventTarget.prototype.removeEventListener", { apply(ctx) { - if (registration === ctx.this) { + if (registrationmap.get(ctx.this)) { // do nothing ctx.return(undefined); } diff --git a/src/client/shared/requests/websocket.ts b/src/client/shared/requests/websocket.ts index 0f75c66..1a5362f 100644 --- a/src/client/shared/requests/websocket.ts +++ b/src/client/shared/requests/websocket.ts @@ -7,10 +7,7 @@ type FakeWebSocketState = { url: string; binaryType: string; barews: BareWebSocket; - /* - captureListeners: Record; - listeners: Record; - */ + onclose?: (ev: CloseEvent) => any; onerror?: (ev: Event) => any; onmessage?: (ev: MessageEvent) => any; @@ -49,10 +46,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) { url: ctx.args[0], binaryType: "blob", barews, - /* - captureListeners: {}, - listeners: {}, - */ + onclose: null, onerror: null, onmessage: null, @@ -107,58 +101,6 @@ export default function (client: ScramjetClient, self: typeof globalThis) { ctx.return(fakeWebSocket); }, }); - // i have no clue why this is here but it prevents the real event listener from ever happening so im commenting it out for now - /* - client.Proxy("EventTarget.prototype.addEventListener", { - apply(ctx) { - const ws = socketmap.get(ctx.this); - if (!ws) return; // it's not a websocket ignore it - - const [type, listener, opts] = ctx.args; - - if ( - (typeof opts === "object" && opts.capture) || - (typeof opts === "boolean" && opts) - ) { - const listeners = (ws.captureListeners[type] ??= []); - listeners.push(listener); - ws.captureListeners[type] = listeners; - } else { - const listeners = (ws.listeners[type] ??= []); - listeners.push(listener); - ws.listeners[type] = listeners; - } - - ctx.return(undefined); - }, - }); - - client.Proxy("EventTarget.prototype.removeEventListener", { - apply(ctx) { - const ws = socketmap.get(ctx.this); - if (!ws) return; - - const [type, listener, opts] = ctx.args; - - if ( - (typeof opts === "object" && opts.capture) || - (typeof opts === "boolean" && opts) - ) { - const listeners = (ws.captureListeners[type] ??= []); - const idx = listeners.indexOf(listener); - if (idx !== -1) listeners.splice(idx, 1); - ws.captureListeners[type] = listeners; - } else { - const listeners = (ws.listeners[type] ??= []); - const idx = listeners.indexOf(listener); - if (idx !== -1) listeners.splice(idx, 1); - ws.listeners[type] = listeners; - } - - ctx.return(undefined); - }, - }); - */ client.Trap("WebSocket.prototype.binaryType", { get(ctx) { const ws = socketmap.get(ctx.this); diff --git a/src/client/shared/wrap.ts b/src/client/shared/wrap.ts index c9d1506..1e4d3e8 100644 --- a/src/client/shared/wrap.ts +++ b/src/client/shared/wrap.ts @@ -74,6 +74,10 @@ export default function (client: ScramjetClient, self: typeof globalThis) { debugger; } + if (v === self && v.$scramjet) { + debugger; + } + if (iswindow && v instanceof Document && v.defaultView.$scramjet) { debugger; } diff --git a/static/playground.js b/static/playground.js index 9ebb5d3..3f169fc 100644 --- a/static/playground.js +++ b/static/playground.js @@ -9,6 +9,7 @@ const scramjet = new ScramjetController({ flags: { serviceworkers: true, syncxhr: true, + scramitize: true, }, });