From 337134bcdc8b7db6a1414f57b2ef6aa7fc1a4cbe Mon Sep 17 00:00:00 2001 From: velzie Date: Sun, 13 Oct 2024 10:20:19 -0400 Subject: [PATCH] refactor: delete codecs/ & self.$scramjet --- rewriter/src/lib.rs | 13 +++--- rewriter/src/rewrite.rs | 2 +- rspack.config.js | 2 - src/client/index.ts | 3 ++ src/client/shared/eval.ts | 2 +- src/client/shared/import.ts | 4 +- src/client/shared/wrap.ts | 4 +- src/codecs/index.ts | 79 ---------------------------------- src/controller/index.ts | 57 +++++++++++++----------- src/global.d.ts | 3 ++ src/scramjet.ts | 26 +++++++++++ src/shared.ts | 6 ++- src/shared/index.ts | 3 +- src/shared/rewriters/html.ts | 11 +++-- src/shared/rewriters/js.ts | 11 +++-- src/shared/rewriters/url.ts | 15 ++++--- src/shared/rewriters/worker.ts | 22 +++------- src/types.d.ts | 46 ++++++++++---------- src/worker/fetch.ts | 3 +- src/worker/index.ts | 25 +++-------- static/sw.js | 1 - static/ui.js | 16 +++---- 22 files changed, 148 insertions(+), 206 deletions(-) delete mode 100644 src/codecs/index.ts create mode 100644 src/scramjet.ts diff --git a/rewriter/src/lib.rs b/rewriter/src/lib.rs index 8259e3a..42049c6 100644 --- a/rewriter/src/lib.rs +++ b/rewriter/src/lib.rs @@ -49,17 +49,18 @@ fn get_config(scramjet: &Object) -> Config { let codec = &get_obj(scramjet, "codec"); let config = &get_obj(scramjet, "config"); let flags = &get_obj(config, "flags"); + let globals = &get_obj(config, "globals"); Config { prefix: get_str(config, "prefix"), encode: create_encode_function(get_obj(codec, "encode")), - wrapfn: get_str(config, "wrapfn"), - importfn: get_str(config, "importfn"), - rewritefn: get_str(config, "rewritefn"), - metafn: get_str(config, "metafn"), - setrealmfn: get_str(config, "setrealmfn"), - pushsourcemapfn: get_str(config, "pushsourcemapfn"), + wrapfn: get_str(globals, "wrapfn"), + importfn: get_str(globals, "importfn"), + rewritefn: get_str(globals, "rewritefn"), + metafn: get_str(globals, "metafn"), + setrealmfn: get_str(globals, "setrealmfn"), + pushsourcemapfn: get_str(globals, "pushsourcemapfn"), do_sourcemaps: get_bool(flags, "sourcemaps"), capture_errors: get_bool(flags, "captureErrors"), diff --git a/rewriter/src/rewrite.rs b/rewriter/src/rewrite.rs index 672beec..c030c5b 100644 --- a/rewriter/src/rewrite.rs +++ b/rewriter/src/rewrite.rs @@ -419,7 +419,7 @@ fn expression_span(e: &Expression) -> Span { } // js MUST not be able to get a reference to any of these because sbx -const UNSAFE_GLOBALS: [&str; 9] = [ +const UNSAFE_GLOBALS: [&str; 10] = [ "window", "self", "globalThis", diff --git a/rspack.config.js b/rspack.config.js index 8eca8af..67c5113 100644 --- a/rspack.config.js +++ b/rspack.config.js @@ -15,9 +15,7 @@ export default defineConfig({ entry: { shared: join(__dirname, "src/shared/index.ts"), worker: join(__dirname, "src/worker/index.ts"), - thread: join(__dirname, "src/thread/thread.ts"), client: join(__dirname, "src/client/index.ts"), - codecs: join(__dirname, "src/codecs/index.ts"), controller: join(__dirname, "src/controller/index.ts"), sync: join(__dirname, "src/sync.ts"), }, diff --git a/src/client/index.ts b/src/client/index.ts index 7594105..878803a 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -1,5 +1,6 @@ // entrypoint for scramjet.client.js +import { loadCodecs } from "../scramjet"; import { SCRAMJETCLIENT } from "../symbols"; import { ScramjetClient } from "./client"; import { ScramjetServiceWorkerRuntime } from "./swruntime"; @@ -19,6 +20,8 @@ export class ScramjetContextInit extends Event { dbg.log("scrammin"); // if it already exists, that means the handlers have probably already been setup by the parent document if (!(SCRAMJETCLIENT in >self)) { + loadCodecs(); + const client = new ScramjetClient(self); if (self.COOKIE) client.loadcookies(self.COOKIE); diff --git a/src/client/shared/eval.ts b/src/client/shared/eval.ts index c269400..011ab21 100644 --- a/src/client/shared/eval.ts +++ b/src/client/shared/eval.ts @@ -4,7 +4,7 @@ import { config, rewriteJs } from "../../shared"; export default function (client: ScramjetClient, self: Self) { // used for proxying *direct eval* // eval("...") -> eval($scramjet$rewrite("...")) - Object.defineProperty(self, config.rewritefn, { + Object.defineProperty(self, config.globals.rewritefn, { value: function (js: any) { if (typeof js !== "string") return js; diff --git a/src/client/shared/import.ts b/src/client/shared/import.ts index 02921e2..6f1811e 100644 --- a/src/client/shared/import.ts +++ b/src/client/shared/import.ts @@ -5,7 +5,7 @@ import { rewriteUrl } from "../../shared/rewriters/url"; export default function (client: ScramjetClient, self: Self) { const Function = client.natives.Function; - self[config.importfn] = function (base: string) { + self[config.globals.importfn] = function (base: string) { return function (url: string) { const resolved = new URL(url, base).href; @@ -15,7 +15,7 @@ export default function (client: ScramjetClient, self: Self) { }; }; - self[config.metafn] = function (base: string) { + self[config.globals.metafn] = function (base: string) { return { url: base, resolve: function (url: string) { diff --git a/src/client/shared/wrap.ts b/src/client/shared/wrap.ts index 596ffd0..cdc0895 100644 --- a/src/client/shared/wrap.ts +++ b/src/client/shared/wrap.ts @@ -60,7 +60,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) { // the main magic of the proxy. all attempts to access any "banned objects" will be redirected here, and instead served a proxy object // this contrasts from how other proxies will leave the root object alone and instead attempt to catch every member access // this presents some issues (see element.ts), but makes us a good bit faster at runtime! - Object.defineProperty(self, config.wrapfn, { + Object.defineProperty(self, config.globals.wrapfn, { value: client.wrapfn, writable: false, configurable: false, @@ -81,7 +81,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) { // ((t)=>$scramjet$tryset(location,"+=",t)||location+=t)(...); // it has to be a discrete function because there's always the possibility that "location" is a local variable // we have to use an IIFE to avoid duplicating side-effects in the getter - Object.defineProperty(self, config.trysetfn, { + Object.defineProperty(self, config.globals.trysetfn, { value: function (lhs: any, op: string, rhs: any) { if (lhs instanceof Location) { // @ts-ignore diff --git a/src/codecs/index.ts b/src/codecs/index.ts deleted file mode 100644 index cbc2aa4..0000000 --- a/src/codecs/index.ts +++ /dev/null @@ -1,79 +0,0 @@ -// for some reason eslint was parsing the type inside of the function params as a variable -export interface Codec { - // eslint-disable-next-line - encode: (str: string | undefined) => string; - // eslint-disable-next-line - decode: (str: string | undefined) => string; -} - -const none = { - encode: (str: string | undefined) => str, - decode: (str: string | undefined) => str, -}; - -const plain = { - encode: (str: string | undefined) => { - if (!str) return str; - - return encodeURIComponent(str); - }, - decode: (str: string | undefined) => { - if (!str) return str; - - return decodeURIComponent(str); - }, -}; - -const xor = { - encode: (str: string | undefined, key: number = 2) => { - if (!str) return str; - - let result = ""; - for (let i = 0; i < str.length; i++) { - result += i % key ? String.fromCharCode(str.charCodeAt(i) ^ key) : str[i]; - } - - return encodeURIComponent(result); - }, - decode: (str: string | undefined, key: number = 2) => { - if (!str) return str; - - const [input, ...search] = str.split("?"); - let result = ""; - const decoded = decodeURIComponent(input); - for (let i = 0; i < decoded.length; i++) { - result += - i % key ? String.fromCharCode(decoded.charCodeAt(i) ^ key) : decoded[i]; - } - - return result + (search.length ? "?" + search.join("?") : ""); - }, -}; - -const base64 = { - encode: (str: string | undefined) => { - if (!str) return str; - - return decodeURIComponent(btoa(str)); - }, - decode: (str: string | undefined) => { - if (!str) return str; - - return atob(str); - }, -}; - -if (typeof self.$scramjet === "undefined") { - //@ts-expect-error really dumb workaround - self.$scramjet = {}; -} -self.$scramjet.codecs = { - none, - plain, - xor, - base64, -}; - -if ("document" in self && document.currentScript) { - document.currentScript.remove(); -} diff --git a/src/controller/index.ts b/src/controller/index.ts index ca8827c..f35d20e 100644 --- a/src/controller/index.ts +++ b/src/controller/index.ts @@ -1,30 +1,32 @@ import { ScramjetConfig } from "../types"; import { Codec } from "../codecs"; import { ScramjetFrame } from "./frame"; +import { $scramjet, loadCodecs } from "../scramjet"; export class ScramjetController { - config: ScramjetConfig; private store: IDBDatabase; - codec: Codec; - constructor(config: ScramjetConfig) { + constructor(config: Partial) { + // sane ish defaults const defaultConfig: Partial = { prefix: "/scramjet/", - codec: "plain", - wrapfn: "$scramjet$wrap", - trysetfn: "$scramjet$tryset", - importfn: "$scramjet$import", - rewritefn: "$scramjet$rewrite", - metafn: "$scramjet$meta", - setrealmfn: "$scramjet$setrealm", - pushsourcemapfn: "$scramjet$pushsourcemap", - wasm: "/scramjet.wasm.js", - shared: "/scramjet.shared.js", - worker: "/scramjet.worker.js", - thread: "/scramjet.thread.js", - client: "/scramjet.client.js", - codecs: "/scramjet.codecs.js", - sync: "/scramjet.sync.js", + + globals: { + wrapfn: "$scramjet$wrap", + trysetfn: "$scramjet$tryset", + importfn: "$scramjet$import", + rewritefn: "$scramjet$rewrite", + metafn: "$scramjet$meta", + setrealmfn: "$scramjet$setrealm", + pushsourcemapfn: "$scramjet$pushsourcemap", + }, + files: { + wasm: "/scramjet.wasm.js", + shared: "/scramjet.shared.js", + worker: "/scramjet.worker.js", + client: "/scramjet.client.js", + sync: "/scramjet.sync.js", + }, flags: { serviceworkers: false, naiiveRewriter: false, @@ -34,6 +36,12 @@ export class ScramjetController { scramitize: false, sourcemaps: false, }, + codec: { + encode: `if (!url) return url; + return encodeURIComponent(url);`, + decode: `if (!url) return url; + return decodeURIComponent(url);`, + }, }; const deepMerge = (target: any, source: any): any => { @@ -46,12 +54,11 @@ export class ScramjetController { return Object.assign(target || {}, source); }; - this.config = deepMerge(defaultConfig, config); + $scramjet.config = deepMerge(defaultConfig, config); } async init(serviceWorkerPath: string): Promise { - await import(/* webpackIgnore: true */ this.config.codecs); - this.codec = self.$scramjet.codecs[this.config.codec]; + loadCodecs(); await this.openIDB(); @@ -72,7 +79,7 @@ export class ScramjetController { encodeUrl(url: string | URL): string { if (url instanceof URL) url = url.toString(); - return this.config.prefix + this.codec.encode(url); + return $scramjet.config.prefix + $scramjet.codec.encode(url); } async openIDB(): Promise { @@ -102,7 +109,7 @@ export class ScramjetController { } const tx = this.store.transaction("config", "readwrite"); const store = tx.objectStore("config"); - const req = store.put(this.config, "config"); + const req = store.put($scramjet.config, "config"); return new Promise((resolve, reject) => { req.onsuccess = resolve; @@ -111,8 +118,8 @@ export class ScramjetController { } async modifyConfig(config: ScramjetConfig) { - this.config = Object.assign({}, this.config, config); - this.codec = self.$scramjet.codecs[this.config.codec]; + $scramjet.config = Object.assign({}, $scramjet.config, config); + loadCodecs(); await this.#saveConfig(); } diff --git a/src/global.d.ts b/src/global.d.ts index a856636..c8ee6f1 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -5,4 +5,7 @@ declare const dbg: { debug: (message: string, ...args: any[]) => void; }; +declare const COMMITHASH: string; +declare const VERSION: string; + declare type Self = Window & typeof globalThis; diff --git a/src/scramjet.ts b/src/scramjet.ts new file mode 100644 index 0000000..c05449f --- /dev/null +++ b/src/scramjet.ts @@ -0,0 +1,26 @@ +import { ScramjetConfig } from "./types"; + +if (!("$scramjet" in self)) { + // @ts-expect-error ts stuff + self.$scramjet = { + version: { + build: COMMITHASH, + version: VERSION, + }, + codec: {}, + }; +} + +export const $scramjet = self.$scramjet; + +const nativeFunction = Function; +export function loadCodecs() { + $scramjet.codec.encode = nativeFunction( + "url", + $scramjet.config.codec.encode + ) as any; + $scramjet.codec.decode = nativeFunction( + "url", + $scramjet.config.codec.decode + ) as any; +} diff --git a/src/shared.ts b/src/shared.ts index e3ff37b..fd25f69 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -1,3 +1,5 @@ +import { $scramjet } from "./scramjet"; + export const { util: { BareClient, ScramjetHeaders, BareMuxConnection }, url: { rewriteUrl, unrewriteUrl, rewriteBlob, unrewriteBlob }, @@ -13,6 +15,6 @@ export const { htmlRules, }, CookieStore, -} = self.$scramjet.shared; +} = $scramjet.shared; -export const config = self.$scramjet.config; +export const config = $scramjet.config; diff --git a/src/shared/index.ts b/src/shared/index.ts index 954e12e..bac2c1c 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -14,8 +14,9 @@ import { parseDomain } from "parse-domain"; import { ScramjetHeaders } from "./headers"; import { CookieStore } from "./cookie"; import { htmlRules, unrewriteHtml } from "./rewriters/html"; +import { $scramjet } from "../scramjet"; -self.$scramjet.shared = { +$scramjet.shared = { util: { parseDomain, BareClient, diff --git a/src/shared/rewriters/html.ts b/src/shared/rewriters/html.ts index 5de72fa..bea47ee 100644 --- a/src/shared/rewriters/html.ts +++ b/src/shared/rewriters/html.ts @@ -6,6 +6,7 @@ import { rewriteCss } from "./css"; import { rewriteJs } from "./js"; import { CookieStore } from "../cookie"; import { unrewriteBlob } from "../../shared/rewriters/url"; +import { $scramjet } from "../../scramjet"; export function rewriteHtml( html: string, @@ -43,8 +44,7 @@ export function rewriteHtml( const dump = JSON.stringify(cookieStore.dump()); const injected = ` self.COOKIE = ${dump}; - self.$scramjet.config = ${JSON.stringify(self.$scramjet.config)}; - self.$scramjet.codec = self.$scramjet.codecs[self.$scramjet.config.codec]; + self.$scramjet.config = ${JSON.stringify($scramjet.config)}; if ("document" in self && document.currentScript) { document.currentScript.remove(); } @@ -53,11 +53,10 @@ export function rewriteHtml( const script = (src) => new Element("script", { src }); head.children.unshift( - script(self.$scramjet.config["wasm"]), - script(self.$scramjet.config["codecs"]), + script($scramjet.config.files.wasm), + script($scramjet.config.files.shared), script("data:application/javascript;base64," + btoa(injected)), - script(self.$scramjet.config["shared"]), - script(self.$scramjet.config["client"]) + script($scramjet.config.files.client) ); } diff --git a/src/shared/rewriters/js.ts b/src/shared/rewriters/js.ts index aad5ce5..2059356 100644 --- a/src/shared/rewriters/js.ts +++ b/src/shared/rewriters/js.ts @@ -7,6 +7,7 @@ import { rewrite_js, rewrite_js_from_arraybuffer, } from "../../../rewriter/out/rewriter.js"; +import { $scramjet } from "../../scramjet"; initSync({ module: new WebAssembly.Module( @@ -19,7 +20,7 @@ init(); Error.stackTraceLimit = 50; export function rewriteJs(js: string | ArrayBuffer, meta: URLMeta) { - if (self.$scramjet.config.flags.naiiveRewriter) { + if ($scramjet.config.flags.naiiveRewriter) { const text = typeof js === "string" ? js : new TextDecoder().decode(js); return rewriteJsNaiive(text); @@ -27,14 +28,12 @@ export function rewriteJs(js: string | ArrayBuffer, meta: URLMeta) { const before = performance.now(); if (typeof js === "string") { - js = new TextDecoder().decode( - rewrite_js(js, meta.base.href, self.$scramjet) - ); + js = new TextDecoder().decode(rewrite_js(js, meta.base.href, $scramjet)); } else { js = rewrite_js_from_arraybuffer( new Uint8Array(js), meta.base.href, - self.$scramjet + $scramjet ); } const after = performance.now(); @@ -56,7 +55,7 @@ export function rewriteJsNaiive(js: string | ArrayBuffer) { } return ` - with (${self.$scramjet.config.wrapfn}(globalThis)) { + with (${$scramjet.config.globals.wrapfn}(globalThis)) { ${js} diff --git a/src/shared/rewriters/url.ts b/src/shared/rewriters/url.ts index 183ffc4..3549059 100644 --- a/src/shared/rewriters/url.ts +++ b/src/shared/rewriters/url.ts @@ -1,3 +1,4 @@ +import { $scramjet } from "../../scramjet"; import { rewriteJs } from "./js"; export type URLMeta = { @@ -31,9 +32,9 @@ export function rewriteUrl(url: string | URL, meta: URLMeta) { if (url.startsWith("javascript:")) { return "javascript:" + rewriteJs(url.slice("javascript:".length), meta); } else if (url.startsWith("blob:")) { - return location.origin + self.$scramjet.config.prefix + url; + return location.origin + $scramjet.config.prefix + url; } else if (url.startsWith("data:")) { - return location.origin + self.$scramjet.config.prefix + url; + return location.origin + $scramjet.config.prefix + url; } else if (url.startsWith("mailto:") || url.startsWith("about:")) { return url; } else { @@ -43,8 +44,8 @@ export function rewriteUrl(url: string | URL, meta: URLMeta) { return ( location.origin + - self.$scramjet.config.prefix + - self.$scramjet.codec.encode(new URL(url, base).href) + $scramjet.config.prefix + + $scramjet.codec.encode(new URL(url, base).href) ); } } @@ -54,7 +55,7 @@ export function unrewriteUrl(url: string | URL) { url = url.href; } - const prefixed = location.origin + self.$scramjet.config.prefix; + const prefixed = location.origin + $scramjet.config.prefix; if (url.startsWith("javascript:")) { //TODO @@ -69,8 +70,8 @@ export function unrewriteUrl(url: string | URL) { } else if (url.startsWith("mailto:") || url.startsWith("about:")) { return url; } else if (tryCanParseURL(url)) { - return self.$scramjet.codec.decode( - url.slice((location.origin + self.$scramjet.config.prefix).length) + return $scramjet.codec.decode( + url.slice((location.origin + $scramjet.config.prefix).length) ); } else { return url; diff --git a/src/shared/rewriters/worker.ts b/src/shared/rewriters/worker.ts index 009b73c..ec20fad 100644 --- a/src/shared/rewriters/worker.ts +++ b/src/shared/rewriters/worker.ts @@ -1,3 +1,4 @@ +import { $scramjet } from "../../scramjet"; import { rewriteJs } from "./js"; import { URLMeta } from "./url"; @@ -9,22 +10,11 @@ export function rewriteWorkers( ) { let str = ""; - str += `self.$scramjet = {}; self.$scramjet.config = ${JSON.stringify(self.$scramjet.config)}; - `; - str += ""; - if (type === "module") { - str += `import "${self.$scramjet.config["codecs"]}" -self.$scramjet.codec = self.$scramjet.codecs[self.$scramjet.config.codec]; -`; - for (const script of clientscripts) { - str += `import "${self.$scramjet.config[script]}"\n`; - } - } else { - str += `importScripts("${self.$scramjet.config["codecs"]}"); -self.$scramjet.codec = self.$scramjet.codecs[self.$scramjet.config.codec]; -`; - for (const script of clientscripts) { - str += `importScripts("${self.$scramjet.config[script]}");\n`; + for (const script of clientscripts) { + if (type === "module") { + str += `import "${$scramjet.config.files[script]}"\n`; + } else { + str += `importScripts("${$scramjet.config.files[script]}");\n`; } } diff --git a/src/types.d.ts b/src/types.d.ts index c6d48fe..611f387 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -36,23 +36,28 @@ type ScramjetFlags = { interface ScramjetConfig { prefix: string; - codec: string; - wrapfn: string; - trysetfn: string; - importfn: string; - rewritefn: string; - metafn: string; - setrealmfn: string; - pushsourcemapfn: string; - wasm: string; - shared: string; - worker: string; - thread: string; - client: string; - codecs: string; - sync: string; + globals: { + wrapfn: string; + trysetfn: string; + importfn: string; + rewritefn: string; + metafn: string; + setrealmfn: string; + pushsourcemapfn: string; + }; + files: { + wasm: string; + shared: string; + worker: string; + client: string; + sync: string; + }; flags: ScramjetFlags; - siteflags?: Record; + siteflags: Record; + codec: { + encode: string; + decode: string; + }; } declare global { @@ -85,13 +90,10 @@ declare global { CookieStore: typeof CookieStore; }; config: ScramjetConfig; - codecs: { - none: Codec; - plain: Codec; - base64: Codec; - xor: Codec; + codec: { + encode: (url: string) => string; + decode: (url: string) => string; }; - codec: Codec; }; COOKIE: string; WASM: string; diff --git a/src/worker/fetch.ts b/src/worker/fetch.ts index ff22db2..0757b67 100644 --- a/src/worker/fetch.ts +++ b/src/worker/fetch.ts @@ -16,6 +16,7 @@ import { } from "../shared"; import type { URLMeta } from "../shared/rewriters/url"; +import { $scramjet } from "../scramjet"; function newmeta(url: URL): URLMeta { return { @@ -115,7 +116,7 @@ export async function swfetch( if ( client && - new URL(client.url).pathname.startsWith(self.$scramjet.config.prefix) + new URL(client.url).pathname.startsWith($scramjet.config.prefix) ) { // TODO: i was against cors emulation but we might actually break stuff if we send full origin/referrer always const clientURL = new URL(unrewriteUrl(client.url)); diff --git a/src/worker/index.ts b/src/worker/index.ts index 2e47692..587c214 100644 --- a/src/worker/index.ts +++ b/src/worker/index.ts @@ -3,22 +3,23 @@ import { swfetch } from "./fetch"; import { ScramjetThreadpool } from "./threadpool"; import type BareClient from "@mercuryworkshop/bare-mux"; import { ScramjetConfig } from "../types"; +import { $scramjet, loadCodecs } from "../scramjet"; export class ScramjetServiceWorker extends EventTarget { client: BareClient; - config: typeof self.$scramjet.config; + config: ScramjetConfig; threadpool: ScramjetThreadpool; syncPool: Record void> = {}; synctoken = 0; - cookieStore = new self.$scramjet.shared.CookieStore(); + cookieStore = new $scramjet.shared.CookieStore(); serviceWorkers: FakeServiceWorker[] = []; constructor() { super(); - this.client = new self.$scramjet.shared.util.BareClient(); + this.client = new $scramjet.shared.util.BareClient(); this.threadpool = new ScramjetThreadpool(); @@ -40,19 +41,6 @@ export class ScramjetServiceWorker extends EventTarget { async loadConfig() { if (this.config) return; - // const store = new IDBMap("config", { - // prefix: "scramjet", - // }); - - // if (store.has("config")) { - // const config = await store.get("config"); - // this.config = config; - // self.$scramjet.config = config; - // self.$scramjet.codec = self.$scramjet.codecs[config.codec]; - // } - - // Recreate the above code using the stock IDB API - const request = indexedDB.open("$scramjet", 1); return new Promise((resolve, reject) => { @@ -64,8 +52,9 @@ export class ScramjetServiceWorker extends EventTarget { config.onsuccess = () => { this.config = config.result; - self.$scramjet.config = config.result; - self.$scramjet.codec = self.$scramjet.codecs[config.result.codec]; + $scramjet.config = config.result; + + loadCodecs(); resolve(); }; diff --git a/static/sw.js b/static/sw.js index f104cf1..613e50c 100644 --- a/static/sw.js +++ b/static/sw.js @@ -1,6 +1,5 @@ importScripts( "/scram/scramjet.wasm.js", - "/scram/scramjet.codecs.js", "/scram/scramjet.shared.js", "/scram/scramjet.worker.js" ); diff --git a/static/ui.js b/static/ui.js index 8514e12..a0ce2a0 100644 --- a/static/ui.js +++ b/static/ui.js @@ -1,11 +1,11 @@ const scramjet = new ScramjetController({ - wasm: "/scram/scramjet.wasm.js", - codecs: "/scram/scramjet.codecs.js", - worker: "/scram/scramjet.worker.js", - thread: "/scram/scramjet.thread.js", - client: "/scram/scramjet.client.js", - shared: "/scram/scramjet.shared.js", - sync: "/scram/scramjet.sync.js", + files: { + wasm: "/scram/scramjet.wasm.js", + worker: "/scram/scramjet.worker.js", + client: "/scram/scramjet.client.js", + shared: "/scram/scramjet.shared.js", + sync: "/scram/scramjet.sync.js", + }, }); scramjet.init("./sw.js"); @@ -148,7 +148,7 @@ function App() { return html`
-

Percury Unblocker

+

scramjet

surf the unblocked and mostly buggy web