Skip to content

Commit b416be9

Browse files
committed
[scramjet/core] kill loadAndHook entry point
1 parent d690572 commit b416be9

File tree

2 files changed

+10
-39
lines changed

2 files changed

+10
-39
lines changed

packages/scramjet/packages/core/src/client/client.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type ScramjetFrame = any;
2-
import { BareClient } from "@mercuryworkshop/bare-mux-custom";
2+
import { BareClient, BareTransport } from "@mercuryworkshop/bare-mux-custom";
33
import { SCRAMJETCLIENT, SCRAMJETFRAME } from "@/symbols";
44
import { getOwnPropertyDescriptorHandler } from "@client/helpers";
55
import { createLocationProxy } from "@client/location";
@@ -8,10 +8,18 @@ import { NavigateEvent } from "@client/events";
88
import { rewriteUrl, unrewriteUrl, type URLMeta } from "@rewriters/url";
99
import { flagEnabled, ScramjetContext, ScramjetInterface } from "@/shared";
1010
import { CookieJar } from "@/shared/cookie";
11-
import { iswindow, ScramjetClientInit } from "./entry";
11+
import { iswindow } from "./entry";
1212
import { SingletonBox } from "./singletonbox";
1313
import { ScramjetConfig } from "@/types";
1414

15+
export type ScramjetClientInit = {
16+
context: ScramjetContext;
17+
transport: BareTransport;
18+
sendSetCookie: (url: URL, cookie: string) => Promise<void>;
19+
shouldPassthroughWebsocket?: (url: string | URL) => boolean;
20+
shouldBlockMessageEvent?: (ev: MessageEvent) => boolean;
21+
};
22+
1523
type NativeStore = {
1624
store: Record<string, any>;
1725
call: (target: string, that: any, ...args) => any;

packages/scramjet/packages/core/src/client/entry.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,3 @@ export const isworker = "WorkerGlobalScope" in globalThis;
1212
export const issw = "ServiceWorkerGlobalScope" in globalThis;
1313
export const isdedicated = "DedicatedWorkerGlobalScope" in globalThis;
1414
export const isshared = "SharedWorkerGlobalScope" in globalThis;
15-
16-
function createFrameId() {
17-
return `${Array(8)
18-
.fill(0)
19-
.map(() => Math.floor(Math.random() * 36).toString(36))
20-
.join("")}`;
21-
}
22-
23-
export type ScramjetClientInit = {
24-
context: ScramjetContext;
25-
transport: BareTransport;
26-
sendSetCookie: (url: URL, cookie: string) => Promise<void>;
27-
shouldPassthroughWebsocket?: (url: string | URL) => boolean;
28-
shouldBlockMessageEvent?: (ev: MessageEvent) => boolean;
29-
};
30-
31-
export function loadAndHook(init: ScramjetClientInit) {
32-
dbg.log("initializing scramjet client");
33-
// if it already exists, that means the handlers have probably already been setup by the parent document
34-
if (!(SCRAMJETCLIENT in <Partial<typeof self>>globalThis)) {
35-
const client = new ScramjetClient(globalThis, init);
36-
37-
const frame: HTMLIFrameElement =
38-
globalThis.frameElement as HTMLIFrameElement;
39-
if (frame && !frame.name) {
40-
// all frames need to be named for our logic to work
41-
frame.name = createFrameId();
42-
}
43-
44-
client.hook();
45-
46-
const contextev = new ScramjetContextEvent(client.global.window, client);
47-
client.frame?.dispatchEvent(contextev);
48-
const urlchangeev = new UrlChangeEvent(client.url.href);
49-
if (!client.isSubframe) client.frame?.dispatchEvent(urlchangeev);
50-
}
51-
}

0 commit comments

Comments
 (0)