Download, verify, and install the browser engine

Each host build pins one engine version in src-tauri/browser-engine.json.
The new engine manager downloads that ZIP over HTTPS, makes sure that its
size and SHA-256 match the pin, extracts it safely to the local app data
folder, and marks the installation last. It can also install a local
ZIP, cancel, report progress, and remove the engine. The host refuses an
engine that sends another protocol with its ready event.
This commit is contained in:
Knotty Wyvern
2026-10-29 00:57:51 -07:00
parent 48b8249ba6
commit 6004e126f7
16 changed files with 815 additions and 33 deletions
+22 -2
View File
@@ -283,16 +283,36 @@ Before you start the app, set `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-de
## Built-in browser runtime
The browser interface is in `src/lib/browser/`. The browser engine, its tests, and its notices are in `browser-runtime/`.
The installer includes the staged engine from `src-tauri/browser-engine/`.
The engine is a separate download. Users install it on first use.
1. Run `npm ci --prefix browser-runtime`.
2. Run `pnpm browser:check` and `pnpm browser:test`.
3. Run `pnpm browser:test:engine` for the native engine tests.
4. Run `npm --prefix browser-runtime run package`.
5. Run `pnpm browser:stage` before you build an installer.
5. Run `pnpm browser:stage` to use this engine in `pnpm tauri dev`.
Each browser window gets a session token at startup. Native requests check that token, and cleanup revokes it.
### Engine download
Each host build pins one engine version in `src-tauri/browser-engine.json`: the version, the protocol, and the URL, size, and SHA-256 hash for each platform.
A platform key is the operating system and the processor, for example `windows-x86_64`. Without an entry for its platform, the host reports that no engine is available.
On request, `src-tauri/src/browser_engine.rs` downloads the ZIP over HTTPS into `browser-engine/.download/` in the local app data folder. A redirect must also use HTTPS.
The host stops when the size or the SHA-256 hash differs from the pin. It extracts the ZIP into a new folder, refuses unsafe paths and links, and needs the engine program at the root of the archive.
Then it writes `installed.json` and renames the folder to `browser-engine/<version>/`. It removes the other versions.
At each start, the host compares `installed.json` with the pin. It does not hash the files again. **Install from file** applies the same size, hash, and archive checks to a local ZIP.
| Engine | When the host starts it |
| --- | --- |
| `src-tauri/browser-engine/`, from `pnpm browser:stage` | Debug builds without a manifest override |
| `browser-engine/<version>/` in the local app data folder | Release builds, and debug builds with `RUNESTONE_BROWSER_ENGINE_MANIFEST` |
`RUNESTONE_BROWSER_ENGINE_MANIFEST` names a manifest file for a native test. Only debug builds read it. With it, the host also accepts HTTP links, for a local test server.
The engine sends `protocol` and `version` with its `ready` event. The host stops an engine with a different protocol.
`PROTOCOL` in `browser_engine.rs` and the `ready` event in `browser-runtime/src/engine-main.mjs` must change together. After a change, package and stage the engine again.
The browser data is in the Tauri `app_local_data_dir()`. Releases up to 0.1.48 kept it in `app_data_dir()`, which roams on Windows.
Before the engine starts, `src-tauri/src/browser.rs` moves an old `browser` folder to the new place. Across volumes, it copies the folder and then deletes the old one.
If the new folder exists, the host uses it and leaves the old folder. If the move fails, the engine does not start, and the error names both folders.