Skip to main content

Debugging and hot reload

The plugin debugging harness lets you debug plugin logic in a plain browser (Chromium) without starting Tauri or the Rust backend.

Quick start

Recommended: just use qomicex dev (plugins inside the repo automatically use harness mode):
Or call the harness script directly:
In pnpm run harness -- hello-plugin, the -- forwards arguments to pnpm; you can also run node scripts/harness/run.mjs hello-plugin directly.
If Playwright is not installed, you are prompted to install it:

Architecture

Components

Stub endpoints

Custom mock data

Overridable keys: settings, systemInfo, proxyResponse, modpackInstall, downloadStart, downloadProgress, fileRead, execCommand, wasmList, pluginStates ({ "插件id": "active" }).

Breakpoint debugging

  • pnpm run harness -- hello-plugin --headed (headed mode)
  • Press F12 in the browser to open DevTools
  • The plugin renders inside an iframe (sandbox sandbox="allow-scripts", opaque origin) — select the iframe in the DevTools Elements panel, then switch the Console context dropdown to that iframe’s document and call __PLUGIN_API__.call('getSettings') directly to verify the bridge and the stub return value
  • In the Sources panel, set a breakpoint on handleApiCall in src/plugins/sandbox.ts to step through the whole __PLUGIN_API__ postMessage → executePluginMethod → createPluginBridge chain
Playwright Inspector (recording and stepping, optional):
codegen does not inject the Tauri mock, so it only suits inspecting page rendering or exercising UI interactions; to verify bridge APIs, use the harness.

Hot reload

  • Watches src/, index.html, theme.css, overlay.html, and vite.config.ts under plugins-dev/{pluginId}/
  • A change → 400ms debounce → run the build command in the plugin directory (defaults to pnpm run build, override with --build-cmd) → on a successful build → page.reload() reloads the whole page and remounts the plugin iframe
  • A failed build does not reload the page; stderr goes to the terminal, so you can keep editing and watching

CLI integration

Inside the repo, qomicex dev detects the harness and invokes it (see qomicex CLI reference):

Limitations and caveats

  • Chromium ≠ WebView2: rendering and compositing can differ (backdrop-filter, for example), so web debugging conclusions need re-checking in real Tauri/WebView2
  • The harness is a read-only sandbox: every stub returns fake data or 400 for real data writes, instance launches, and real downloads; do not trigger real business actions from a plugin
  • Exit cleanup: after Ctrl+C, run.mjs kills the stub and Vite it spawned; if you started Vite(:1420) yourself first (pnpm run dev), the harness reuses it and does not kill that process on exit
  • iframe sandbox: sandbox="allow-scripts" without allow-same-origin, so a synchronous while(true) inside the iframe can still block the shared renderer process (matching real WebView2 behavior)
  • Plugins depend on @qomicex/plugin-ui, so its dist/ must already be built (pnpm --filter @qomicex/plugin-ui build)