diff --git a/src/client/swruntime.ts b/src/client/swruntime.ts index e7ed8db..7341a94 100644 --- a/src/client/swruntime.ts +++ b/src/client/swruntime.ts @@ -60,15 +60,14 @@ function handleMessage( const port = this.recvport; const type = data.scramjet$type; const token = data.scramjet$token; + const handlers = client.eventcallbacks.get(self); if (type === "fetch") { dbg.log("ee", data); - const fetchhandlers = client.eventcallbacks.get(self); + const fetchhandlers = handlers.filter((event) => event.event === "fetch"); if (!fetchhandlers) return; for (const handler of fetchhandlers) { - if (handler.event !== "fetch") continue; - const request = data.scramjet$request; const Request = client.natives["Request"]; diff --git a/src/shared/rewriters/worker.ts b/src/shared/rewriters/worker.ts index 733c653..a0463e2 100644 --- a/src/shared/rewriters/worker.ts +++ b/src/shared/rewriters/worker.ts @@ -2,7 +2,6 @@ import { $scramjet } from "../../scramjet"; import { rewriteJs } from "./js"; import { URLMeta } from "./url"; -// const clientscripts = ["wasm", "shared", "client"]; export function rewriteWorkers( js: string | ArrayBuffer, type: string, diff --git a/src/worker/fetch.ts b/src/worker/fetch.ts index 57fee17..bb8dcd6 100644 --- a/src/worker/fetch.ts +++ b/src/worker/fetch.ts @@ -25,7 +25,7 @@ function newmeta(url: URL): URLMeta { }; } -export async function swfetch( +export async function handleFetch( this: ScramjetServiceWorker, request: Request, client: Client | null @@ -137,14 +137,13 @@ export async function swfetch( } headers.set("Sec-Fetch-Dest", request.destination); + //TODO: Emulate this later (like really) + headers.set("Sec-Fetch-Site", "same-origin"); headers.set( "Sec-Fetch-Mode", request.mode === "cors" ? request.mode : "same-origin" ); - //TODO: Emulate this later - //headers.set("Sec-Fetch-Site", "same-origin"); - const ev = new ScramjetRequestEvent( url, request.body, diff --git a/src/worker/index.ts b/src/worker/index.ts index 11e9505..26fb06f 100644 --- a/src/worker/index.ts +++ b/src/worker/index.ts @@ -1,5 +1,5 @@ import { FakeServiceWorker } from "./fakesw"; -import { swfetch } from "./fetch"; +import { handleFetch } from "./fetch"; import type BareClient from "@mercuryworkshop/bare-mux"; import { ScramjetConfig } from "../types"; import { $scramjet, loadCodecs } from "../scramjet"; @@ -90,7 +90,7 @@ export class ScramjetServiceWorker extends EventTarget { async fetch({ request, clientId }: FetchEvent) { const client = await self.clients.get(clientId); - return swfetch.call(this, request, client); + return handleFetch.call(this, request, client); } }