From ee7287d268039dfcf35f05ed8acc5fc2e2f01991 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Fri, 14 Nov 2025 11:33:41 -0600 Subject: [PATCH 01/13] [chrome] fix: make isolated origin urls actually be formatted properly --- package.json | 2 +- packages/chrome/src/proxy/Controller.ts | 2 +- pnpm-lock.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f35cafb6..50a8fd8b 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "build": "rspack build", "build:dreamland": "cd external/dreamlandjs && pnpm build", "build:chrome": "cd packages/chrome && pnpm build", - "dev": "node --no-warnings=ExperimentalWarning devserver.ts", + "dev": "node --localstorage-file='./uwu' --no-warnings=ExperimentalWarning devserver.ts", "watch": "rspack build --watch", "format": "prettier --write .", "preinstall": "npx only-allow pnpm" diff --git a/packages/chrome/src/proxy/Controller.ts b/packages/chrome/src/proxy/Controller.ts index 98dd65c8..94c2595f 100644 --- a/packages/chrome/src/proxy/Controller.ts +++ b/packages/chrome/src/proxy/Controller.ts @@ -217,7 +217,7 @@ export async function controllerForURL(url: URL): Promise { let channel = new MessageChannel(); const controllerId = makeId(); - let prefix = new URL(baseurl + basePrefix + controllerId); + let prefix = new URL(baseurl.origin + basePrefix + controllerId + "/"); controller = new Controller(prefix, controllerId, channel, rootdomain); controllers.push(controller); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 81ec87a7..755931f2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12928,7 +12928,7 @@ snapshots: dependencies: eastasianwidth: 0.2.0 emoji-regex: 10.5.0 - strip-ansi: 7.1.0 + strip-ansi: 7.1.2 string-width@7.2.0: dependencies: From 7713ae77583f87108f18abac336fff21f3343db4 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Fri, 14 Nov 2025 11:38:09 -0600 Subject: [PATCH 02/13] [chrome] make injectload assign to globalthis instead of window --- amplify.yml | 1 - packages/inject/src/index.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/amplify.yml b/amplify.yml index 4b0f1c52..ce705503 100644 --- a/amplify.yml +++ b/amplify.yml @@ -52,7 +52,6 @@ frontend: - pnpm build - VITE_PUTER_BRANDING=1 VITE_ISOLATION_ORIGIN="https://puter.zone" pnpm build:chrome - artifacts: baseDirectory: packages/scramjet/packages/core/dist files: diff --git a/packages/inject/src/index.ts b/packages/inject/src/index.ts index 09bc1f59..07a17feb 100644 --- a/packages/inject/src/index.ts +++ b/packages/inject/src/index.ts @@ -178,6 +178,6 @@ function $injectLoadError( } // @ts-expect-error -window.$injectLoadError = $injectLoadError; +globalThis.$injectLoadError = $injectLoadError; // @ts-expect-error -window.$injectLoad = $injectLoad; +globalThis.$injectLoad = $injectLoad; From 5853c81a47a933fe052ee892b26a5c05836073dd Mon Sep 17 00:00:00 2001 From: percs Date: Fri, 14 Nov 2025 23:06:31 -0600 Subject: [PATCH 03/13] [scramjet/controller] update things, add extra stuff to demo --- .../scramjet/packages/controller/src/index.ts | 14 ++++---- .../scramjet/packages/controller/src/sw.ts | 2 +- .../packages/controller/tsconfig.json | 26 +++++++++++--- packages/scramjet/packages/demo/src/App.tsx | 34 ++++++++++++------- 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/packages/scramjet/packages/controller/src/index.ts b/packages/scramjet/packages/controller/src/index.ts index ed10f0c5..77499443 100644 --- a/packages/scramjet/packages/controller/src/index.ts +++ b/packages/scramjet/packages/controller/src/index.ts @@ -1,4 +1,4 @@ -import { MethodsDefinition, RpcHelper } from "@mercuryworkshop/rpc"; +import { type MethodsDefinition, RpcHelper } from "@mercuryworkshop/rpc"; import type * as ScramjetGlobal from "@mercuryworkshop/scramjet"; declare const $scramjet: typeof ScramjetGlobal; @@ -11,11 +11,11 @@ declare const $scramjet: typeof ScramjetGlobal; // CookieJar, // } = $scramjet; -import { Controllerbound, SWbound } from "./types"; +import type { Controllerbound, SWbound } from "./types"; import LibcurlClient from "@mercuryworkshop/libcurl-transport"; import { BareClient, - BareResponseFetch, + type BareResponseFetch, } from "@mercuryworkshop/bare-mux-custom"; let lc = new LibcurlClient({ @@ -44,6 +44,10 @@ export const config: Config = { }; const cfg = { + flags: { + ...$scramjet.defaultConfig.flags, + allowFailedIntercepts: true, + }, maskedfiles: ["inject.js", "scramjet.wasm.js"], }; @@ -293,8 +297,6 @@ class Frame { id: string; prefix: string; - getInjectScripts(meta, handler, script) {} - get context() { let sjcfg = { ...$scramjet.defaultConfig, @@ -311,7 +313,7 @@ class Frame { { ...$scramjet.defaultConfig, ...cfg }, new URL(this.prefix, location.href) ), - getWorkerInjectScripts: (type: string) => { + getWorkerInjectScripts: (meta, js, type, url) => { const module = type === "module"; let str = ""; const script = (script: string) => { diff --git a/packages/scramjet/packages/controller/src/sw.ts b/packages/scramjet/packages/controller/src/sw.ts index 08102d5c..07642b56 100644 --- a/packages/scramjet/packages/controller/src/sw.ts +++ b/packages/scramjet/packages/controller/src/sw.ts @@ -1,6 +1,6 @@ declare var clients: Clients; import { RpcHelper } from "@mercuryworkshop/rpc"; -import { Controllerbound, SWbound } from "./types"; +import type { Controllerbound, SWbound } from "./types"; import type { BareHeaders } from "@mercuryworkshop/bare-mux-custom"; function makeId(): string { diff --git a/packages/scramjet/packages/controller/tsconfig.json b/packages/scramjet/packages/controller/tsconfig.json index a6d1f353..ee70ad81 100644 --- a/packages/scramjet/packages/controller/tsconfig.json +++ b/packages/scramjet/packages/controller/tsconfig.json @@ -1,7 +1,25 @@ +{ { "compilerOptions": { - "target": "es2022", - "lib": ["es2022", "webworker"], - "moduleResolution": "node" - } + "target": "ES2022", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2022", "webworker", "DOM", "DOM.Iterable"], + "types": [], + "skipLibCheck": true, + /* Bundler mode */ + "moduleResolution": "node", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "moduleDetection": "force", + "noEmit": true, + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": false, + "erasableSyntaxOnly": false, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true, + }, + "include": ["src"] } diff --git a/packages/scramjet/packages/demo/src/App.tsx b/packages/scramjet/packages/demo/src/App.tsx index 8feff282..8593a4d8 100644 --- a/packages/scramjet/packages/demo/src/App.tsx +++ b/packages/scramjet/packages/demo/src/App.tsx @@ -1,23 +1,33 @@ import { controller } from "."; import { css, type Component } from "dreamland/core"; -export const App: Component<{ frameel: HTMLIFrameElement }> = function (cx) { - let frame; +export const App: Component< + {}, + {}, + { + url: string; + frame: controller.Frame; + frameel: HTMLIFrameElement; + } +> = function (cx) { + this.url = "https://google.com"; cx.mount = () => { - frame = controller.createFrame(this.frameel); - - frame.go("https://google.com"); + this.frame = controller.createFrame(this.frameel); + let body = btoa( + `Welcome to Scramjet! Type in a URL in the omnibox above and press enter to get started.` + ); + this.frame.go(`data:text/html;base64,${body}`); }; - return (
- { - let url = (e.target as HTMLInputElement).value; - frame.go(url); +
{ + e.preventDefault(); + this.frame.go(this.url); }} - placeholder="Enter URL" - /> + > + +
); From 181d4f66eacaf0764da412f253ca59146dd9be2f Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Fri, 14 Nov 2025 23:14:11 -0600 Subject: [PATCH 04/13] [scramjet/controller] fix prefix issues --- .../scramjet/packages/controller/src/index.ts | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/packages/scramjet/packages/controller/src/index.ts b/packages/scramjet/packages/controller/src/index.ts index 77499443..51c150dc 100644 --- a/packages/scramjet/packages/controller/src/index.ts +++ b/packages/scramjet/packages/controller/src/index.ts @@ -37,8 +37,8 @@ fetch("/scramjet/scramjet.wasm.wasm").then(async (resp) => { }); export const config: Config = { - prefix: "/~/sj", - virtualWasmPath: "/scramjet.wasm.js", + prefix: "/~/sj/", + virtualWasmPath: "scramjet.wasm.js", scramjetPath: "/scramjet/scramjet.js", wasmPath: "/scramjet/scramjet.wasm.wasm", }; @@ -91,12 +91,7 @@ export class Controller { const frame = this.frames.find((f) => path.startsWith(f.prefix)); if (!frame) throw new Error("No frame found for request"); - if ( - path.startsWith( - frame.prefix.substring(0, frame.prefix.length - 1) + - config.virtualWasmPath - ) - ) { + if (path === frame.prefix + config.virtualWasmPath) { console.log("???"); if (!wasmPayload) { const resp = await fetch(config.wasmPath); @@ -172,7 +167,7 @@ export class Controller { constructor(serviceworker: ServiceWorker) { this.id = makeId(); - this.prefix = config.prefix + "/" + this.id; + this.prefix = config.prefix + this.id; this.ready = new Promise((resolve) => { this.readyResolve = resolve; @@ -195,7 +190,7 @@ export class Controller { serviceworker.postMessage( { $controller$init: { - prefix: config.prefix + "/" + this.id, + prefix: config.prefix + this.id, id: this.id, }, }, @@ -224,10 +219,7 @@ function yieldGetInjectScripts( return function getInjectScripts(meta, handler, script) { return [ script(config.scramjetPath), - script( - prefix.href.substring(0, prefix.href.length - 1) + - config.virtualWasmPath - ), + script(prefix.href + config.virtualWasmPath), script( "data:text/javascript;base64," + btoa(` @@ -325,10 +317,7 @@ class Frame { }; script(config.scramjetPath); - script( - this.prefix.substring(0, this.prefix.length - 1) + - config.virtualWasmPath - ); + script(this.prefix + config.virtualWasmPath); str += ` (()=>{ const { ScramjetClient, CookieJar, setWasm } = $scramjet; From db75996d0ae66b86715291cd96762216d1ff2a05 Mon Sep 17 00:00:00 2001 From: percs Date: Fri, 14 Nov 2025 23:21:18 -0600 Subject: [PATCH 05/13] [scramjet/controller] more url tweaks --- packages/scramjet/packages/controller/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/scramjet/packages/controller/src/index.ts b/packages/scramjet/packages/controller/src/index.ts index 51c150dc..74c220f5 100644 --- a/packages/scramjet/packages/controller/src/index.ts +++ b/packages/scramjet/packages/controller/src/index.ts @@ -167,7 +167,7 @@ export class Controller { constructor(serviceworker: ServiceWorker) { this.id = makeId(); - this.prefix = config.prefix + this.id; + this.prefix = config.prefix + this.id + "/"; this.ready = new Promise((resolve) => { this.readyResolve = resolve; @@ -362,7 +362,7 @@ class Frame { public element: HTMLIFrameElement ) { this.id = makeId(); - this.prefix = this.controller.prefix + "/" + this.id + "/"; + this.prefix = this.controller.prefix + this.id + "/"; this.fetchHandler = new $scramjet.ScramjetFetchHandler({ crossOriginIsolated: self.crossOriginIsolated, From 0449fe4f814544e10c6015384c303c7cccc1ea4c Mon Sep 17 00:00:00 2001 From: percs Date: Fri, 14 Nov 2025 23:42:04 -0600 Subject: [PATCH 06/13] [chrome] make chrome actually function again --- package.json | 2 +- packages/inject/src/scramjet.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 50a8fd8b..f35cafb6 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "build": "rspack build", "build:dreamland": "cd external/dreamlandjs && pnpm build", "build:chrome": "cd packages/chrome && pnpm build", - "dev": "node --localstorage-file='./uwu' --no-warnings=ExperimentalWarning devserver.ts", + "dev": "node --no-warnings=ExperimentalWarning devserver.ts", "watch": "rspack build --watch", "format": "prettier --write .", "preinstall": "npx only-allow pnpm" diff --git a/packages/inject/src/scramjet.ts b/packages/inject/src/scramjet.ts index 172737c3..b951c4b5 100644 --- a/packages/inject/src/scramjet.ts +++ b/packages/inject/src/scramjet.ts @@ -29,9 +29,15 @@ export function loadScramjet({ setWasm(Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0))); delete (self as any).WASM; + if (SCRAMJETCLIENT in globalThis) { + //@ts-expect-error god bless america + client = globalThis[SCRAMJETCLIENT]; + return; + } + const transport = new LibcurlClient({ wisp }); - loadAndHook({ + client = new ScramjetClient(globalThis, { context: { interface: { getInjectScripts, @@ -43,8 +49,10 @@ export function loadScramjet({ prefix: new URL(prefix), }, transport, + shouldPassthroughWebsocket: (url) => { + return url === "wss://anura.pro/"; + }, sendSetCookie: async (url: URL, cookie: string) => {}, }); - - client = self[SCRAMJETCLIENT]; + client.hook(); } From 6c62837387f38c1d8e6ea9cc62ac9720abf04bf6 Mon Sep 17 00:00:00 2001 From: percs Date: Sat, 15 Nov 2025 23:17:49 -0600 Subject: [PATCH 07/13] [chrome] fix websocket and worker stuff --- packages/chrome/src/proxy/scramjet.ts | 3 +++ packages/inject/src/scramjet.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/chrome/src/proxy/scramjet.ts b/packages/chrome/src/proxy/scramjet.ts index 56792e89..987041c7 100644 --- a/packages/chrome/src/proxy/scramjet.ts +++ b/packages/chrome/src/proxy/scramjet.ts @@ -262,6 +262,9 @@ export function createFetchHandler(controller: Controller) { config: ${JSON.stringify(makeConfig())}, cookies: null, wisp: ${JSON.stringify(wispUrl)}, + codecEncode: ${codecEncode.toString()}, + codecDecode: ${codecDecode.toString()}, + prefix: "${controller.prefix.href}", }); `; script(controller.prefix.href + virtualWasmPath); diff --git a/packages/inject/src/scramjet.ts b/packages/inject/src/scramjet.ts index b951c4b5..e633e4a2 100644 --- a/packages/inject/src/scramjet.ts +++ b/packages/inject/src/scramjet.ts @@ -50,7 +50,7 @@ export function loadScramjet({ }, transport, shouldPassthroughWebsocket: (url) => { - return url === "wss://anura.pro/"; + return url === wisp; }, sendSetCookie: async (url: URL, cookie: string) => {}, }); From b617908e72e106110ebe81a6adc698c95954e600 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Tue, 18 Nov 2025 10:41:05 -0600 Subject: [PATCH 08/13] [scramjet/core] clean up worker inject scripts --- packages/chrome/src/proxy/scramjet.ts | 20 +++++++------------ .../scramjet/packages/controller/src/index.ts | 14 +++---------- .../packages/core/src/shared/index.ts | 5 ++--- .../core/src/shared/rewriters/worker.ts | 10 ++++++++-- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/packages/chrome/src/proxy/scramjet.ts b/packages/chrome/src/proxy/scramjet.ts index 987041c7..67a9bf03 100644 --- a/packages/chrome/src/proxy/scramjet.ts +++ b/packages/chrome/src/proxy/scramjet.ts @@ -244,18 +244,10 @@ export function createFetchHandler(controller: Controller) { const getWorkerInjectScripts: ScramjetInterface["getWorkerInjectScripts"] = ( meta, - js, - type + type, + script ) => { - const module = type === "module"; let str = ""; - const script = (script: string) => { - if (module) { - str += `import "${script}"\n`; - } else { - str += `importScripts("${script}");\n`; - } - }; const injectLoad = ` $injectLoad({ @@ -267,9 +259,11 @@ export function createFetchHandler(controller: Controller) { prefix: "${controller.prefix.href}", }); `; - script(controller.prefix.href + virtualWasmPath); - script(controller.prefix.href + virtualInjectPath); - script(`data:application/javascript;base64,${base64Encode(injectLoad)}`); + str += script(controller.prefix.href + virtualWasmPath); + str += script(controller.prefix.href + virtualInjectPath); + str += script( + `data:application/javascript;base64,${base64Encode(injectLoad)}` + ); return str; }; diff --git a/packages/scramjet/packages/controller/src/index.ts b/packages/scramjet/packages/controller/src/index.ts index 74c220f5..abcc640c 100644 --- a/packages/scramjet/packages/controller/src/index.ts +++ b/packages/scramjet/packages/controller/src/index.ts @@ -305,19 +305,11 @@ class Frame { { ...$scramjet.defaultConfig, ...cfg }, new URL(this.prefix, location.href) ), - getWorkerInjectScripts: (meta, js, type, url) => { - const module = type === "module"; + getWorkerInjectScripts: (meta, type, script) => { let str = ""; - const script = (script: string) => { - if (module) { - str += `import "${script}"\n`; - } else { - str += `importScripts("${script}");\n`; - } - }; - script(config.scramjetPath); - script(this.prefix + config.virtualWasmPath); + str += script(config.scramjetPath); + str += script(this.prefix + config.virtualWasmPath); str += ` (()=>{ const { ScramjetClient, CookieJar, setWasm } = $scramjet; diff --git a/packages/scramjet/packages/core/src/shared/index.ts b/packages/scramjet/packages/core/src/shared/index.ts index 8e9c80df..837b0612 100644 --- a/packages/scramjet/packages/core/src/shared/index.ts +++ b/packages/scramjet/packages/core/src/shared/index.ts @@ -36,9 +36,8 @@ export type ScramjetInterface = { ): Element[]; getWorkerInjectScripts?( meta: URLMeta, - js: string | Uint8Array, - type: string, - url: string + type: "module" | undefined, + script: (src: string) => string ): string; }; diff --git a/packages/scramjet/packages/core/src/shared/rewriters/worker.ts b/packages/scramjet/packages/core/src/shared/rewriters/worker.ts index 0d975cdf..57e9e8b0 100644 --- a/packages/scramjet/packages/core/src/shared/rewriters/worker.ts +++ b/packages/scramjet/packages/core/src/shared/rewriters/worker.ts @@ -5,12 +5,18 @@ import { URLMeta } from "@rewriters/url"; export function rewriteWorkers( context: ScramjetContext, js: string | Uint8Array, - type: string, + type: "module" | undefined, url: string, meta: URLMeta ) { const module = type === "module"; - let str = context.interface.getWorkerInjectScripts(meta, js, type, url); + const script = (script: string) => { + if (module) { + return `import "${script}"\n`; + } + return `importScripts("${script}");\n`; + }; + let str = context.interface.getWorkerInjectScripts(meta, type, script); let rewritten = rewriteJs(js, url, context, meta, module); if (rewritten instanceof Uint8Array) { rewritten = new TextDecoder().decode(rewritten); From 97be3187a3bb2e2c9224562dcb60c1b0350e5641 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Wed, 19 Nov 2025 11:51:18 -0600 Subject: [PATCH 09/13] [scramjet/core] fix playwright tests --- packages/scramjet/devserver.ts | 2 +- packages/scramjet/jsconfig.json | 2 +- packages/scramjet/package.json | 1 + .../packages/core/playwright.config.ts | 52 +++++++++++++++++++ .../core}/tests/ci/packageValidation.js | 7 +-- .../tests/integration/site/google.spec.ts | 0 .../tests/integration/site/youtube.spec.ts | 0 .../core}/tests/util/inspectConsole.ts | 0 .../core}/tests/util/setupPage.ts | 6 +-- packages/scramjet/packages/demo/src/App.tsx | 7 ++- packages/scramjet/playwright.config.ts | 8 +-- packages/scramjet/typedoc | 1 - 12 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 packages/scramjet/packages/core/playwright.config.ts rename packages/scramjet/{ => packages/core}/tests/ci/packageValidation.js (97%) rename packages/scramjet/{ => packages/core}/tests/integration/site/google.spec.ts (100%) rename packages/scramjet/{ => packages/core}/tests/integration/site/youtube.spec.ts (100%) rename packages/scramjet/{ => packages/core}/tests/util/inspectConsole.ts (100%) rename packages/scramjet/{ => packages/core}/tests/util/setupPage.ts (77%) delete mode 120000 packages/scramjet/typedoc diff --git a/packages/scramjet/devserver.ts b/packages/scramjet/devserver.ts index e9eac4f6..4024873b 100644 --- a/packages/scramjet/devserver.ts +++ b/packages/scramjet/devserver.ts @@ -27,7 +27,7 @@ const branch = execSync("git rev-parse --abbrev-ref HEAD", { const packagejson = JSON.parse(await fs.readFile("./package.json", "utf-8")); const version = packagejson.version; -const DEMO_PORT = process.env.CHROME_PORT || 4141; +const DEMO_PORT = process.env.DEMO_PORT || 4141; const WISP_PORT = process.env.WISP_PORT || 4142; process.env.VITE_WISP_URL = diff --git a/packages/scramjet/jsconfig.json b/packages/scramjet/jsconfig.json index 94e5df32..78d31526 100644 --- a/packages/scramjet/jsconfig.json +++ b/packages/scramjet/jsconfig.json @@ -15,5 +15,5 @@ "types": [] }, "include": ["static/**/*", "dist/types/index.d.ts"], - "exclude": ["node_modules", "dist", "src/**/*", "tests/**/*"] + "exclude": ["node_modules", "dist", "src/**/*", "packages/core/tests/**/*"] } diff --git a/packages/scramjet/package.json b/packages/scramjet/package.json index 560f342a..362c30f1 100644 --- a/packages/scramjet/package.json +++ b/packages/scramjet/package.json @@ -8,6 +8,7 @@ "license": "AGPL-3.0-only", "packageManager": "pnpm@10.12.1", "scripts": { + "dev": "node --no-warnings=ExperimentalWarning devserver.ts", "preinstall": "npx only-allow pnpm" }, "devDependencies": { diff --git a/packages/scramjet/packages/core/playwright.config.ts b/packages/scramjet/packages/core/playwright.config.ts new file mode 100644 index 00000000..e2ee67c3 --- /dev/null +++ b/packages/scramjet/packages/core/playwright.config.ts @@ -0,0 +1,52 @@ +import { defineConfig, devices } from "@playwright/test"; +import type { GitHubActionOptions } from "@estruyf/github-actions-reporter"; + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: "./tests/integration/site", + fullyParallel: true, + forbidOnly: !!process.env.CI, + retries: 2, + reporter: process.env.CI + ? [ + [ + "@estruyf/github-actions-reporter", + { + title: "Test summary", + useDetails: true, + showError: true, + } as GitHubActionOptions, + ], + ["github"], + ] + : "html", + timeout: 20000, + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: "on-first-retry", + actionTimeout: 10000, + baseURL: "http://localhost:4141", + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: "chromium", + use: { ...devices["Desktop Chrome"] }, + }, + // { + // name: "firefox", + // use: { ...devices["Desktop Firefox"] }, + // }, + ], + + /* Run your local dev server before starting the tests */ + webServer: { + command: "cd .. && pnpm run dev", + url: "http://localhost:4141", + reuseExistingServer: false, + }, +}); diff --git a/packages/scramjet/tests/ci/packageValidation.js b/packages/scramjet/packages/core/tests/ci/packageValidation.js similarity index 97% rename from packages/scramjet/tests/ci/packageValidation.js rename to packages/scramjet/packages/core/tests/ci/packageValidation.js index 66b8df8c..29713ac8 100644 --- a/packages/scramjet/tests/ci/packageValidation.js +++ b/packages/scramjet/packages/core/tests/ci/packageValidation.js @@ -14,9 +14,10 @@ import { existsSync } from "node:fs"; * These aren't globs. */ const EXPECTED_DIST_FILES = [ - "dist/scramjet.all.js", - "dist/scramjet.bundle.js", - "dist/scramjet.sync.js", + "dist/scramjet.js", + "dist/scramjet.mjs", + "dist/scramjet_bundled.js", + "dist/scramjet_bundled.mjs", "dist/scramjet.wasm.wasm", ]; diff --git a/packages/scramjet/tests/integration/site/google.spec.ts b/packages/scramjet/packages/core/tests/integration/site/google.spec.ts similarity index 100% rename from packages/scramjet/tests/integration/site/google.spec.ts rename to packages/scramjet/packages/core/tests/integration/site/google.spec.ts diff --git a/packages/scramjet/tests/integration/site/youtube.spec.ts b/packages/scramjet/packages/core/tests/integration/site/youtube.spec.ts similarity index 100% rename from packages/scramjet/tests/integration/site/youtube.spec.ts rename to packages/scramjet/packages/core/tests/integration/site/youtube.spec.ts diff --git a/packages/scramjet/tests/util/inspectConsole.ts b/packages/scramjet/packages/core/tests/util/inspectConsole.ts similarity index 100% rename from packages/scramjet/tests/util/inspectConsole.ts rename to packages/scramjet/packages/core/tests/util/inspectConsole.ts diff --git a/packages/scramjet/tests/util/setupPage.ts b/packages/scramjet/packages/core/tests/util/setupPage.ts similarity index 77% rename from packages/scramjet/tests/util/setupPage.ts rename to packages/scramjet/packages/core/tests/util/setupPage.ts index 00bf9c4f..9cff5c9c 100644 --- a/packages/scramjet/tests/util/setupPage.ts +++ b/packages/scramjet/packages/core/tests/util/setupPage.ts @@ -10,11 +10,9 @@ export async function setupPage( await page.route("**", (route) => route.continue()); // Goto base url defined in config. await page.goto("/"); - await page.waitForSelector(".version > b"); - const bar = page.locator(".bar"); - const title = await page.locator(".version > b").textContent(); + await page.waitForSelector("#search"); + const bar = page.locator("#search"); const frame = page.frameLocator("iframe"); - expect(title).toBe("scramjet"); expect(bar).not.toBeNull(); diff --git a/packages/scramjet/packages/demo/src/App.tsx b/packages/scramjet/packages/demo/src/App.tsx index 8593a4d8..d18a41f1 100644 --- a/packages/scramjet/packages/demo/src/App.tsx +++ b/packages/scramjet/packages/demo/src/App.tsx @@ -26,7 +26,12 @@ export const App: Component< this.frame.go(this.url); }} > - + diff --git a/packages/scramjet/playwright.config.ts b/packages/scramjet/playwright.config.ts index 20e21e15..0f52a41f 100644 --- a/packages/scramjet/playwright.config.ts +++ b/packages/scramjet/playwright.config.ts @@ -28,7 +28,7 @@ export default defineConfig({ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: "on-first-retry", actionTimeout: 10000, - baseURL: "http://localhost:1337", + baseURL: "http://localhost:4141", }, /* Configure projects for major browsers */ @@ -45,8 +45,8 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { - command: "pnpm run dev", - url: "http://127.0.0.1:1337", - reuseExistingServer: false, + command: "cd .. && pnpm run dev", + url: "http://127.0.0.1:4141", + reuseExistingServer: !process.env.CI, }, }); diff --git a/packages/scramjet/typedoc b/packages/scramjet/typedoc deleted file mode 120000 index 368f4144..00000000 --- a/packages/scramjet/typedoc +++ /dev/null @@ -1 +0,0 @@ -../../../../../packages/scramjet/packages/typedoc \ No newline at end of file From 1acf389b338da0d0f29f0301a4a1b3de98f45084 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Wed, 19 Nov 2025 12:08:03 -0600 Subject: [PATCH 10/13] [ci] add back package validation --- .github/workflows/main.yml | 187 +++++++++++++++++++++++++------------ 1 file changed, 128 insertions(+), 59 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b3ce7077..08f51452 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -129,20 +129,20 @@ jobs: name: scramjet path: | packages/scramjet/packages/core/dist/* - frontend: - name: Build Frontend + + package-validation: + name: Validate Package Structure runs-on: ubuntu-latest - permissions: write-all needs: [build] steps: - name: Checkout code uses: actions/checkout@v4 - with: - submodules: recursive - name: Setup pnpm uses: pnpm/action-setup@v4 + with: + version: latest - name: Setup Node.js uses: actions/setup-node@v4 @@ -156,65 +156,19 @@ jobs: - name: Get artifacts uses: actions/download-artifact@v4 with: - name: scramjet - path: packages/scramjet/packages/core/dist - - - name: Build Dreamland - run: pnpm build:dreamland - - # - name: Get Chii submodule commit hash - # id: chii-hash - # run: echo "hash=$(git submodule status chii | awk '{print $1}')" >> $GITHUB_OUTPUT - - # - name: Cache Chii build output - # id: chii-cache - # uses: actions/cache@v4 - # with: - # path: | - # chii/public - # chii/front_end/dist - # key: chii-${{ runner.os }}-${{ steps.chii-hash.outputs.hash }} - - # - name: Install Depot Tools - # if: steps.chii-cache.outputs.cache-hit != 'true' - # uses: newkdev/setup-depot-tools@v1.0.1 - - # - name: Initialize Chii front_end - # if: steps.chii-cache.outputs.cache-hit != 'true' - # run: | - # cd chii - # pnpm init:front_end - - # - name: Build Chii - # if: steps.chii-cache.outputs.cache-hit != 'true' - # run: | - # cd chii - # pnpm build - - - name: Build Frontend - run: | - SKIP_CORE=1 pnpm build - VITE_PUTER_BRANDING=1 VITE_ISOLATION_ORIGIN="https://puter.zone" pnpm build:chrome + name: packaged-scramjet + path: . - - name: Upload Artifact (dist) - uses: actions/upload-artifact@v4 - with: - name: frontend - path: | - ./packages/chrome/dist + - name: Extract package + run: tar xvf mercuryworkshop-scramjet-*.tgz package --strip-components=1 - - name: Upload pages artifact - uses: actions/upload-pages-artifact@v3 - with: - path: "./packages/chrome/dist" + - name: Run package validation tests + run: pnpm test:package - - name: Deploy to github - id: deployment - uses: actions/deploy-pages@v4 tests: name: Run Scramjet Tests runs-on: ubuntu-latest - needs: build + needs: [build, package-validation] env: PLAYWRIGHT_BROWSERS_PATH: .playwright-browsers steps: @@ -262,7 +216,7 @@ jobs: rewritertests: name: "Run Rewriter Tests" runs-on: ubuntu-latest - needs: [build] + needs: [build, package-validation] steps: - name: Checkout code @@ -290,3 +244,118 @@ jobs: - name: Run Tests run: cargo test working-directory: packages/scramjet/packages/core/rewriter/native + + frontend: + name: Build Frontend + runs-on: ubuntu-latest + permissions: write-all + needs: [build, package-validation] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "22" + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Get artifacts + uses: actions/download-artifact@v4 + with: + name: scramjet + path: packages/scramjet/packages/core/dist + + - name: Build Dreamland + run: pnpm build:dreamland + + # - name: Get Chii submodule commit hash + # id: chii-hash + # run: echo "hash=$(git submodule status chii | awk '{print $1}')" >> $GITHUB_OUTPUT + + # - name: Cache Chii build output + # id: chii-cache + # uses: actions/cache@v4 + # with: + # path: | + # chii/public + # chii/front_end/dist + # key: chii-${{ runner.os }}-${{ steps.chii-hash.outputs.hash }} + + # - name: Install Depot Tools + # if: steps.chii-cache.outputs.cache-hit != 'true' + # uses: newkdev/setup-depot-tools@v1.0.1 + + # - name: Initialize Chii front_end + # if: steps.chii-cache.outputs.cache-hit != 'true' + # run: | + # cd chii + # pnpm init:front_end + + # - name: Build Chii + # if: steps.chii-cache.outputs.cache-hit != 'true' + # run: | + # cd chii + # pnpm build + + - name: Build Frontend + run: | + SKIP_CORE=1 pnpm build + VITE_PUTER_BRANDING=1 VITE_ISOLATION_ORIGIN="https://puter.zone" pnpm build:chrome + + - name: Upload Artifact (dist) + uses: actions/upload-artifact@v4 + with: + name: frontend + path: | + ./packages/chrome/dist + + pages: + name: Upload to Github Pages + runs-on: ubuntu-latest + # make sure to add rewritertests and tests, omitting them due to bugs currently + needs: [frontend] + permissions: write-all + if: github.ref == 'refs/heads/main' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: latest + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "22" + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Get artifacts + uses: actions/download-artifact@v4 + with: + name: frontend + path: "./packages/chrome/dist" + + - name: Upload pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: "./packages/chrome/dist" + + - name: Deploy to github + id: deployment + uses: actions/deploy-pages@v4 From cf4b33ec63a5d5bde48e0b38ea2d08c39b365c5c Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Wed, 19 Nov 2025 12:11:00 -0600 Subject: [PATCH 11/13] ci golf --- .github/workflows/main.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 08f51452..fd665956 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -141,8 +141,6 @@ jobs: - name: Setup pnpm uses: pnpm/action-setup@v4 - with: - version: latest - name: Setup Node.js uses: actions/setup-node@v4 @@ -333,8 +331,6 @@ jobs: - name: Setup pnpm uses: pnpm/action-setup@v4 - with: - version: latest - name: Setup Node.js uses: actions/setup-node@v4 From ae8b2b18e395922c3f8a1aa9bcc513fdeda52b91 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Wed, 19 Nov 2025 12:14:58 -0600 Subject: [PATCH 12/13] [ci] golf, change working directory for package-validation --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fd665956..fc8e1866 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -155,13 +155,15 @@ jobs: uses: actions/download-artifact@v4 with: name: packaged-scramjet - path: . + path: packages/scramjet/packages/core - name: Extract package run: tar xvf mercuryworkshop-scramjet-*.tgz package --strip-components=1 + working-directory: packages/scramjet/packages/core - name: Run package validation tests run: pnpm test:package + working-directory: packages/scramjet/packages/core tests: name: Run Scramjet Tests From 62302f69e535497c3f54324e0a50b9c1eee275f9 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Wed, 19 Nov 2025 12:22:59 -0600 Subject: [PATCH 13/13] [ci] fix package validation again --- packages/scramjet/{ => packages/core}/lib/index.cjs | 0 packages/scramjet/{ => packages/core}/lib/index.d.ts | 0 packages/scramjet/{ => packages/core}/lib/types.d.ts | 0 packages/scramjet/packages/core/src/fetch/index.ts | 6 +++--- packages/scramjet/packages/core/src/shared/index.ts | 2 +- .../scramjet/packages/core/src/shared/rewriters/worker.ts | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename packages/scramjet/{ => packages/core}/lib/index.cjs (100%) rename packages/scramjet/{ => packages/core}/lib/index.d.ts (100%) rename packages/scramjet/{ => packages/core}/lib/types.d.ts (100%) diff --git a/packages/scramjet/lib/index.cjs b/packages/scramjet/packages/core/lib/index.cjs similarity index 100% rename from packages/scramjet/lib/index.cjs rename to packages/scramjet/packages/core/lib/index.cjs diff --git a/packages/scramjet/lib/index.d.ts b/packages/scramjet/packages/core/lib/index.d.ts similarity index 100% rename from packages/scramjet/lib/index.d.ts rename to packages/scramjet/packages/core/lib/index.d.ts diff --git a/packages/scramjet/lib/types.d.ts b/packages/scramjet/packages/core/lib/types.d.ts similarity index 100% rename from packages/scramjet/lib/types.d.ts rename to packages/scramjet/packages/core/lib/types.d.ts diff --git a/packages/scramjet/packages/core/src/fetch/index.ts b/packages/scramjet/packages/core/src/fetch/index.ts index 3eee835d..f5fb4b3c 100644 --- a/packages/scramjet/packages/core/src/fetch/index.ts +++ b/packages/scramjet/packages/core/src/fetch/index.ts @@ -40,7 +40,7 @@ export interface ScramjetFetchParsed { clientUrl?: URL; meta: URLMeta; - scriptType: string; + scriptType: "module" | "regular"; } export interface ScramjetFetchResponse { @@ -209,13 +209,13 @@ export function parseRequest( const strippedUrl = new URL(request.rawUrl.href); const extraParams: Record = {}; - let scriptType = ""; + let scriptType: "module" | "regular" = "regular"; let topFrameName: string | undefined; let parentFrameName: string | undefined; for (const [param, value] of [...request.rawUrl.searchParams.entries()]) { switch (param) { case "type": - scriptType = value; + if (value === "module") scriptType = value; break; case "dest": break; diff --git a/packages/scramjet/packages/core/src/shared/index.ts b/packages/scramjet/packages/core/src/shared/index.ts index 837b0612..31990fb3 100644 --- a/packages/scramjet/packages/core/src/shared/index.ts +++ b/packages/scramjet/packages/core/src/shared/index.ts @@ -36,7 +36,7 @@ export type ScramjetInterface = { ): Element[]; getWorkerInjectScripts?( meta: URLMeta, - type: "module" | undefined, + type: "module" | "regular", script: (src: string) => string ): string; }; diff --git a/packages/scramjet/packages/core/src/shared/rewriters/worker.ts b/packages/scramjet/packages/core/src/shared/rewriters/worker.ts index 57e9e8b0..b06d9ee7 100644 --- a/packages/scramjet/packages/core/src/shared/rewriters/worker.ts +++ b/packages/scramjet/packages/core/src/shared/rewriters/worker.ts @@ -5,7 +5,7 @@ import { URLMeta } from "@rewriters/url"; export function rewriteWorkers( context: ScramjetContext, js: string | Uint8Array, - type: "module" | undefined, + type: "module" | "regular", url: string, meta: URLMeta ) {