How code that runs inside a webview's own page (not the app's) is bundled and kept apart from the app in Nyxs. Use when adding or changing a `?page-script` import, code that must run in a hidden or preview webview (like the YouTube Music engine), or an eval / new Function that the security tests flag.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Nyxs Page Scripts?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nyxs-code-nyxs-page-scripts)
---
name: nyxs-page-scripts
description: How code that runs inside a webview's own page (not the app's) is bundled and kept apart from the app in Nyxs. Use when adding or changing a `?page-script` import, code that must run in a hidden or preview webview (like the YouTube Music engine), or an eval / new Function that the security tests flag.
---
# Page scripts
Some code must run inside a web page Nyxs opens in a webview (the YouTube Music engine on
YouTube's origin, `src/lib/music/youtubeEngine/page.ts`), not in the app's own page.
## How it is bundled
`import code from "./page.ts?page-script"` (plugin `pageScriptPlugin` in `vite.config.ts`):
rolldown bundles the file and its imports into one IIFE string, `keepNames` on (youtubei.js looks
its parser classes up by name). Nyxs then runs that string in the webview. The type is declared
in `src/vite-env.d.ts`.
## The security boundary
The app's real boundary is that no foreign code runs in its own webview: any script there can
call Rust. So `src/lib/__tests__/securityBoundary.test.ts` forbids `eval(` and `new Function(` in
`src/`, with one list of exceptions, `PAGE_SCRIPTS`:
- A file goes there only if it runs **only** in a webview's page. Write why next to it.
- The test "loads the page scripts only into a webview's page" resolves every import in `src/`
and fails if a listed file is imported anywhere without `?page-script`. Never import a page
script normally, not even its types from the app (move shared types to another file, as
`protocol.ts`).
## Talking to it
The page script puts its API on a global of the page (`ENGINE_GLOBAL`) and the app calls it
through the webview; the shapes both sides use live in `youtubeEngine/protocol.ts`, which has
only types and constants, so the app can import it. The page script imports only libraries and
its own folder (`./parse`, `./protocol`), never `@/lib/...` modules that touch Tauri, React or the
app's stores.