diff --git a/src/client/dom/serviceworker.ts b/src/client/dom/serviceworker.ts index 6c334f5..f58c182 100644 --- a/src/client/dom/serviceworker.ts +++ b/src/client/dom/serviceworker.ts @@ -6,7 +6,7 @@ import { type MessageC2W } from "../../worker"; export const order = 2; export default function (client: ScramjetClient, self: Self) { - let fakeregistrations = new WeakSet(); + let registration; client.Proxy("Worklet.prototype.addModule", { apply(ctx) { @@ -16,7 +16,7 @@ export default function (client: ScramjetClient, self: Self) { client.Proxy("EventTarget.prototype.addEventListener", { apply(ctx) { - if (fakeregistrations.has(ctx.this)) { + if (registration === ctx.this) { // do nothing ctx.return(undefined); } @@ -25,13 +25,19 @@ export default function (client: ScramjetClient, self: Self) { client.Proxy("EventTarget.prototype.removeEventListener", { apply(ctx) { - if (fakeregistrations.has(ctx.this)) { + if (registration === ctx.this) { // do nothing ctx.return(undefined); } }, }); + client.Proxy("navigator.serviceWorker.getRegistration", { + apply(ctx) { + ctx.return(new Promise((resolve) => resolve(registration))); + }, + }); + client.Proxy("navigator.serviceWorker.register", { apply(ctx) { if (ctx.args[0] instanceof URL) ctx.args[0] = ctx.args[0].href; @@ -80,11 +86,9 @@ export default function (client: ScramjetClient, self: Self) { }, } ); - fakeregistrations.add(fakeRegistration); + registration = fakeRegistration; ctx.return(new Promise((resolve) => resolve(fakeRegistration))); }, }); - - // delete self.navigator.serviceWorker; } diff --git a/src/client/swruntime.ts b/src/client/swruntime.ts index 06d5764..56b997c 100644 --- a/src/client/swruntime.ts +++ b/src/client/swruntime.ts @@ -47,6 +47,9 @@ export class ScramjetServiceWorkerRuntime { installing: null, waiting: null, }; + + // @ts-ignore + this.client.global.ServiceWorkerGlobalScope = this.client.global; } } diff --git a/static/ui.js b/static/ui.js index 0245fe0..56a1519 100644 --- a/static/ui.js +++ b/static/ui.js @@ -92,7 +92,7 @@ function App() { } iframe { border: 2px solid #313131; - background-color: #121212; + background-color: #fff; border-radius: 0.5rem; margin: 1em; margin-top: 0.5em;