mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
reintroduce serviceworker proxy
This commit is contained in:
parent
d2249c1fc6
commit
e98b861e1b
1 changed files with 56 additions and 0 deletions
56
src/client/dom/serviceworker.ts
Normal file
56
src/client/dom/serviceworker.ts
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import { encodeUrl } from "../../shared/rewriters/url";
|
||||||
|
import { ScramjetClient } from "../client";
|
||||||
|
|
||||||
|
export default function (client: ScramjetClient, self: Self) {
|
||||||
|
client.Proxy("Worklet.prototype.addModule", {
|
||||||
|
apply(ctx) {
|
||||||
|
ctx.args[0] = encodeUrl(ctx.args[0]);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// client.Proxy("navigator.serviceWorker.register", {
|
||||||
|
// apply(ctx) {
|
||||||
|
// if (ctx.args[0] instanceof URL) ctx.args[0] = ctx.args[0].href;
|
||||||
|
// let url = encodeUrl(ctx.args[0]) + "?dest=serviceworker";
|
||||||
|
// if (ctx.args[1] && ctx.args[1].type === "module") {
|
||||||
|
// url += "&type=module";
|
||||||
|
// }
|
||||||
|
// let worker = new SharedWorker(url);
|
||||||
|
//
|
||||||
|
// let handle = worker.port;
|
||||||
|
//
|
||||||
|
// navigator.serviceWorker.controller.postMessage({
|
||||||
|
// scramjet$type: "registerServiceWorker",
|
||||||
|
// port: handle,
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// const fakeRegistration = new Proxy(
|
||||||
|
// {
|
||||||
|
// __proto__: ServiceWorkerRegistration.prototype,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// get(target, prop) {
|
||||||
|
// if (prop === "installing") {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// if (prop === "waiting") {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// if (prop === "active") {
|
||||||
|
// return handle;
|
||||||
|
// }
|
||||||
|
// if (prop === "scope") {
|
||||||
|
// return ctx.args[0];
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return Reflect.get(target, prop);
|
||||||
|
// },
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// ctx.return(new Promise((resolve) => resolve(fakeRegistration)));
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
delete self.navigator.serviceWorker;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue