WXT Web Extension Framework
WXT is a next-generation web extension framework designed for building browser extensions across all major browsers (Chrome, Firefox, Edge, etc.) supporting both Manifest V2 and Manifest V3. It leverages Vite for fast development with Hot Module Replacement (HMR) and rapid reloads. The current stable version is `0.20.25`. WXT follows a frequent release cadence, often releasing multiple patch versions within weeks, indicating active development and responsiveness to bug fixes and minor enhancements. Key differentiators include its file-based entrypoints, comprehensive TypeScript support, auto-imports, a flexible module system for code reuse, and framework agnosticism, allowing integration with popular UI libraries like Vue, React, and Svelte via dedicated modules. It also provides automated publishing capabilities and bundle analysis.
Common errors
-
Error: Node.js v18.x is not supported. Please use Node.js v20.12.0 or higher.
cause Using an outdated Node.js version that does not meet WXT's engine requirements.fixUpgrade Node.js to version `20.12.0` or newer (e.g., using `nvm install 20` and `nvm use 20`). Alternatively, use Bun version `1.2.0` or higher. -
Peer dependency 'eslint' is not installed or incompatible.
cause The required `eslint` package is either missing from `devDependencies` or its version does not satisfy WXT's peer dependency range.fixInstall `eslint` with `npm install -D eslint@'^8.57.0 || ^9.0.0 || ^10.0.0'` to match the expected peer dependency range. -
Error: Cannot find module 'vite'
cause Vite is a fundamental dependency, and issues can arise if it's not correctly installed or if WXT's internal Vite resolution fails.fixEnsure `vite` is installed as a `devDependency` (`npm install -D vite`) and that WXT is updated to a version compatible with your Vite installation (e.g., `wxt@0.20.19` for Vite 8 support).
Warnings
- breaking WXT now requires Node.js version >=20.12.0 or Bun >=1.2.0. Older Node.js versions are not supported and will prevent the framework from running.
- breaking Major Vite version updates, specifically Vite 8, require corresponding WXT updates or module updates. Older WXT versions may not be compatible with newer Vite versions, leading to build failures or unexpected behavior.
- gotcha The `eslint` peer dependency is critical for linting. WXT's internal tooling expects a compatible `eslint` version. Incompatible versions (e.g., older `eslint 8` with newer WXT versions expecting `eslint 9` or `10`) can lead to warnings or linting failures.
- gotcha Handling Manifest V2 (MV2) vs. Manifest V3 (MV3) requires careful attention to browser extension API differences, especially regarding background scripts, content script injection, and permissions. WXT aims to abstract some of this, but developers must still understand the underlying manifest requirements.
- deprecated Changes in dev server port assignment on reload (e.g., [#2283]) might affect automated testing or development setups that rely on fixed ports. While a fix was implemented, custom `dev.server.port` configurations should be reviewed.
Install
-
npm install wxt -
yarn add wxt -
pnpm add wxt
Imports
- defineConfig
import { defineConfig } from 'wxt'; - createViteConfig
import { createViteConfig } from 'wxt'; - Wxt
import { Wxt } from 'wxt';import Wxt from 'wxt';
Quickstart
import { defineConfig } from 'wxt';
export default defineConfig({
srcDir: 'src',
publicDir: 'public',
entrypoints: {
background: 'src/background.ts',
'content-scripts/inject': 'src/content-scripts/inject.ts',
popup: 'src/popup/index.html',
options: 'src/options/index.html',
},
manifest: {
host_permissions: ['*://*.google.com/*', '*://*.bing.com/*'],
permissions: ['storage', 'unlimitedStorage'],
name: 'My Awesome Extension',
version: '1.0.0',
description: 'A quickstart web extension built with WXT.',
},
modules: {
// Example: add the React module if using React
// react: true,
},
});