/** * `wmill app dev --recording`: a shell page that frames the app under * development and records the session with the same recorder the Windmill UI * uses, so a locally-built app can be demoed without deploying it first. * * The shell holds the toolbar rather than the app page: the recorder snapshots * the framed document on every mutation, and a toolbar living in that document * would record itself. It also lives at its own path, so the app keeps the root * URL its router and its own links expect. */ import { DEV_RECORDER_BUNDLE } from "./devRecorderBundle.gen.ts"; /** Path the bundled recorder is served from. */ export const RECORDER_BUNDLE_PATH = "/__wm_recorder.js"; /** Path the toolbar shell is served from. Not the root: the app stays there, so * a link or a router push to `/` inside it reloads the app rather than nesting * another shell in the frame. */ export const RECORDER_SHELL_PATH = "/__record"; /** Recordings are POSTed here and served back from `/`. */ export const RECORDER_SAVE_PATH = "/__recordings"; export { DEV_RECORDER_BUNDLE }; export { RECORDINGS_FOLDER } from "./app_metadata.ts"; /** Whether a request to the save route came from the shell this server serves. * A cross-site POST carrying JSON under a simple content type (`text/plain`) * needs no preflight, so without this any page open in the developer's browser * could write files into the app folder. Compared against the `Host` the browser * actually reached us on, since the shell is equally `localhost`, `127.0.0.1` or * whatever `--host` binds. */ export function isOwnOrigin( origin: string | undefined, host: string | undefined, ): boolean { // Absent on a same-origin request in some browsers, and on non-browser // clients (curl, a script); a forged one is no worse than no header at all. if (origin === undefined) return true; if (host === undefined) return false; try { return new URL(origin).host === host; } catch { return false; } } /** Name a recording after the moment it was saved. Millisecond resolution plus * the caller's collision retry: two tabs stopping together must not have one * silently overwrite the other. */ export function recordingFileName(now: Date, attempt = 0): string { const stamp = now.toISOString().slice(0, 23).replace(/[:T.]/g, "-"); return `recording-${stamp}${attempt > 0 ? `-${attempt}` : ""}.json`; } /** Names the read route accepts. Rejects every separator and escape, so the * name can only ever resolve inside the recordings folder. */ export function isRecordingFileName(file: string): boolean { return /^[A-Za-z0-9._-]+\.json$/.test(file) && !file.includes(".."); } export function createRecorderShellHTML(opts: { appPath: string; workspace: string; /** Base URL of the Windmill instance, for the "Open in player" link. */ playerBaseUrl?: string; }): string { // `<` escaped: this lands inside an inline ` in // any value (the app path comes from raw_app.yaml) would end the block. const config = JSON.stringify({ appPath: opts.appPath, workspace: opts.workspace, playerBaseUrl: opts.playerBaseUrl ?? null, savePath: RECORDER_SAVE_PATH, }).replace(/ Windmill App Dev Recording
Not recording Passwords are masked. Mark sensitive elements with data-wm-no-record
`; }