Hot Reload (HMR)
The addfox dev command provides a hot reload experience during development: after saving code, the project is automatically rebuilt and the browser extension is reloaded via WebSocket.
How It Works
Hot Reload Mechanisms by Entry
Background / Service Worker
Background scripts use extension reload mechanism:
- Code changes → Rsbuild rebuilds
- Build complete → WebSocket sends reload command
- Calls
chrome.runtime.reload()to reload entire extension - Service Worker restarts with new code
Service Worker loses in-memory state after reload. Use chrome.storage API for persistent data.
Content Script
Content Scripts use re-injection mechanism:
- Code changes → Rsbuild rebuilds
- Build complete → Extension reloads
- Content Script auto-injects into matched pages
- Open tabs can auto-refresh (see configuration)
Content Scripts run in the web page environment. After reload, they re-inject into matched pages without needing to manually refresh the extensions management page.
Popup / Options / Sidepanel
Page entries use Rsbuild HMR mechanism:
- Code changes → Rsbuild attempts HMR hot replacement
- If HMR succeeds → Page updates locally, state preserved
- If HMR fails → Automatically falls back to page refresh
- Faster update speed
- Preserves component state (e.g., form inputs)
- Smoother development experience :::
:::warning HTML template limitation
Due to Rsbuild's mechanism, HTML template files (such as popup/index.html) do not support true HMR hot replacement.
After changing HTML templates, Addfox will fall back to page refresh / extension reload behavior.
Firefox Special Handling
Firefox dev mode uses the web-ext tool to manage extensions:
- Extension reload is handled by
web-ext, not Addfox's WebSocket - Firefox automatically opens and loads the extension on first start
- Supports auto-reload (livereload)
When developing with Firefox, ensure Firefox browser is installed. Addfox automatically calls web-ext to handle Firefox extension loading and reloading.
Usage
First Start Flow
After running addfox dev:
- First build completes
- Browser auto-starts based on configuration
- Development extension is loaded
- Extension popup/options pages auto-open (if
openis configured)
Configuration
Hot Reload Port
Next Steps
- browserPath config — Configure auto browser launch during dev
- monitor debugging — Use error monitoring panel
- config/hot-reload — Complete hot reload configuration

