mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 15:40:02 -04:00
cookie communication
This commit is contained in:
parent
bac00de12b
commit
c1aecdf3a8
3 changed files with 32 additions and 7 deletions
|
@ -1,12 +1,28 @@
|
|||
import { ScramjetClient } from "../client";
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof window) {
|
||||
client.serviceworker.addEventListener("message", ({ data }) => {
|
||||
if (!("scramjet$type" in data)) return;
|
||||
|
||||
if (data.scramjet$type === "cookie") {
|
||||
this.cookieStore.setCookies([data.cookie], new URL(data.url));
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
client.Trap("Document.prototype.cookie", {
|
||||
get() {
|
||||
return client.cookieStore.getCookies(client.url, true);
|
||||
},
|
||||
set(ctx, value: string) {
|
||||
client.cookieStore.setCookies([value], client.url);
|
||||
|
||||
// TODO hardcode because scoping whatever
|
||||
client.serviceworker.controller!.postMessage({
|
||||
scramjet$type: "cookie",
|
||||
cookie: value,
|
||||
url: client.url.href,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue