This commit is contained in:
velzie 2024-08-25 00:17:39 -04:00
parent 4ac0fce534
commit 8666196db3
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
2 changed files with 5 additions and 4 deletions

View file

@ -45,6 +45,7 @@ export class ScramjetClient {
documentProxy: any; documentProxy: any;
windowProxy: any; windowProxy: any;
locationProxy: any; locationProxy: any;
serviceWorker: ServiceWorkerContainer;
cookieStore = new CookieStore(); cookieStore = new CookieStore();
@ -75,6 +76,7 @@ export class ScramjetClient {
} }
hook() { hook() {
this.serviceWorker = navigator.serviceWorker;
// @ts-ignore // @ts-ignore
const context = import.meta.webpackContext(".", { const context = import.meta.webpackContext(".", {
recursive: true, recursive: true,

View file

@ -1,11 +1,11 @@
import { ScramjetClient } from "../client"; import { ScramjetClient } from "../client";
export default function (client: ScramjetClient, self: typeof window) { export default function (client: ScramjetClient, self: typeof window) {
client.serviceworker.addEventListener("message", ({ data }) => { client.serviceWorker.addEventListener("message", ({ data }) => {
if (!("scramjet$type" in data)) return; if (!("scramjet$type" in data)) return;
if (data.scramjet$type === "cookie") { if (data.scramjet$type === "cookie") {
this.cookieStore.setCookies([data.cookie], new URL(data.url)); client.cookieStore.setCookies([data.cookie], new URL(data.url));
return; return;
} }
}); });
@ -17,8 +17,7 @@ export default function (client: ScramjetClient, self: typeof window) {
set(ctx, value: string) { set(ctx, value: string) {
client.cookieStore.setCookies([value], client.url); client.cookieStore.setCookies([value], client.url);
// TODO hardcode because scoping whatever client.serviceWorker.controller!.postMessage({
client.serviceworker.controller!.postMessage({
scramjet$type: "cookie", scramjet$type: "cookie",
cookie: value, cookie: value,
url: client.url.href, url: client.url.href,