mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -04:00
proxy getRegistration
This commit is contained in:
parent
dad499f5c4
commit
3ebbc5e430
3 changed files with 14 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,9 @@ export class ScramjetServiceWorkerRuntime {
|
|||
installing: null,
|
||||
waiting: null,
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
this.client.global.ServiceWorkerGlobalScope = this.client.global;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue