web-extension-starter
🖥🔋Web Extension starter to build "Write Once Run on Any Browser" extension
Top Related Projects
A Chrome Extensions boilerplate using React 18 and Webpack 5.
A command line tool to help build, run, and test web extensions
🛠️ A Vue CLI 3+ preset (previously a Vue CLI 2 boilerplate) for quickly starting a web extension with Vue, Babel, ESLint and more!
Quick Overview
Web Extension Starter is a modern, cross-browser compatible boilerplate for developing browser extensions. It provides a solid foundation for creating extensions that work across Chrome, Firefox, and other Chromium-based browsers, using TypeScript and React for a robust development experience.
Pros
- Cross-browser compatibility out of the box
- Built with modern technologies (TypeScript, React, Webpack)
- Includes hot-reloading for faster development
- Comprehensive documentation and examples
Cons
- May have a steeper learning curve for beginners
- Might be overkill for simple extensions
- Requires knowledge of React and TypeScript
Code Examples
- Accessing browser APIs:
import Browser from 'webextension-polyfill';
// Get all open tabs
Browser.tabs.query({}).then(tabs => {
console.log('Open tabs:', tabs);
});
- Creating a popup component:
import React from 'react';
const Popup: React.FC = () => {
return (
<div>
<h1>Extension Popup</h1>
<button onClick={() => console.log('Button clicked')}>
Click me
</button>
</div>
);
};
export default Popup;
- Sending a message from content script to background script:
import Browser from 'webextension-polyfill';
// In content script
Browser.runtime.sendMessage({ action: 'getData' })
.then(response => {
console.log('Received data:', response);
});
// In background script
Browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'getData') {
sendResponse({ data: 'Some data' });
}
});
Getting Started
-
Clone the repository:
git clone https://github.com/abhijithvijayan/web-extension-starter.git -
Install dependencies:
cd web-extension-starter npm install -
Start development server:
npm run dev -
Build for production:
npm run build -
Load the extension in your browser:
- Chrome: Go to
chrome://extensions/, enable "Developer mode", and click "Load unpacked". Select theextensiondirectory from the build output. - Firefox: Go to
about:debugging#/runtime/this-firefox, click "Load Temporary Add-on", and select themanifest.jsonfile from theextensiondirectory.
- Chrome: Go to
Competitor Comparisons
A Chrome Extensions boilerplate using React 18 and Webpack 5.
Pros of chrome-extension-boilerplate-react
- Built with React, offering a more modern and component-based approach
- Includes hot-reloading for faster development
- Provides a more comprehensive project structure with separate folders for components, pages, and hooks
Cons of chrome-extension-boilerplate-react
- Larger bundle size due to React dependencies
- Steeper learning curve for developers not familiar with React
- Less focus on cross-browser compatibility compared to web-extension-starter
Code Comparison
web-extension-starter:
import Browser from 'webextension-polyfill';
export async function getCurrentTab() {
const tabs = await Browser.tabs.query({currentWindow: true, active: true});
return tabs[0];
}
chrome-extension-boilerplate-react:
import React from 'react';
import { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('root'));
root.render(<Popup />);
The code snippets highlight the different approaches:
- web-extension-starter uses a more traditional JavaScript approach with browser APIs
- chrome-extension-boilerplate-react leverages React for rendering components
Both repositories provide solid starting points for developing browser extensions, but they cater to different preferences and use cases. web-extension-starter offers a more lightweight and cross-browser compatible solution, while chrome-extension-boilerplate-react provides a modern React-based development experience with additional features like hot-reloading.
A command line tool to help build, run, and test web extensions
Pros of web-ext
- Officially maintained by Mozilla, ensuring compatibility with Firefox
- Robust CLI tool for building, running, and testing web extensions
- Supports auto-reloading and watching for file changes during development
Cons of web-ext
- Primarily focused on Firefox, may require additional setup for cross-browser development
- Less opinionated about project structure and build processes
- Steeper learning curve for beginners compared to web-extension-starter
Code Comparison
web-ext:
web-ext run
web-ext lint
web-ext build
web-extension-starter:
"scripts": {
"dev": "cross-env NODE_ENV=development webpack --config webpack.config.js",
"build": "cross-env NODE_ENV=production webpack --config webpack.config.js",
"lint": "eslint . --ext .ts,.tsx"
}
Summary
web-ext is a powerful tool for Firefox extension development, offering robust CLI features and official Mozilla support. However, it may require additional setup for cross-browser compatibility. web-extension-starter provides a more opinionated and beginner-friendly approach, with a pre-configured project structure and build process. The choice between the two depends on the developer's experience level and specific project requirements.
🛠️ A Vue CLI 3+ preset (previously a Vue CLI 2 boilerplate) for quickly starting a web extension with Vue, Babel, ESLint and more!
Pros of vue-web-extension
- Built specifically for Vue.js, providing a more tailored experience for Vue developers
- Includes Vue Router and Vuex out of the box, offering a complete Vue ecosystem
- Uses Vue CLI 3, which provides a more modern and flexible build setup
Cons of vue-web-extension
- Less frequently updated compared to web-extension-starter
- Focuses solely on Vue.js, limiting flexibility for developers who might want to use other frameworks
- May have a steeper learning curve for developers not familiar with Vue.js ecosystem
Code Comparison
web-extension-starter:
import React from 'react';
import ReactDOM from 'react-dom';
import Popup from './Popup';
ReactDOM.render(<Popup />, document.getElementById('popup-root'));
vue-web-extension:
import Vue from 'vue';
import App from './App.vue';
import store from './store';
/* eslint-disable no-new */
new Vue({
el: '#app',
store,
render: h => h(App),
});
The code comparison highlights the different approaches: web-extension-starter uses React, while vue-web-extension is built around Vue.js. The vue-web-extension example also showcases the integration with Vuex (store), which is included by default.
Both projects aim to simplify web extension development, but they cater to different ecosystems and developer preferences. The choice between them largely depends on the developer's familiarity with React or Vue.js and the specific requirements of the project.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ð web-extension-starter
Web Extension starter to build "Write Once Run on Any Browser" extension
ðââï¸ Made by @abhijithvijayan
â¤ï¸ it? âï¸ it on GitHub or Tweet about it.
Features
- Cross Browser Support (Web-Extensions API)
- Browser Tailored Manifest generation
- Vite for fast builds and HMR
- Automatic build on code changes
- Auto packs browser specific build files
- SASS/SCSS styling with CSS Modules
- TypeScript by default
- ES6 modules support
- React 19 with automatic JSX runtime
- ESLint 9 flat config with Prettier
Tech Stack
- Bundler: Vite 7
- UI: React 19
- Language: TypeScript 5.9
- Styling: SCSS with CSS Modules
- Linting: ESLint 9 (flat config) + Prettier
- Manifest: vite-plugin-wext-manifest
Browser Support
This starter uses Manifest V3 for all browsers.
![]() | ![]() | ![]() | ![]() | ![]() |
|---|---|---|---|---|
| 88+ (Jan 2021) | 109+ (Jan 2023) | 74+ (Chromium-based) | 88+ (Chromium-based) | Latest (Chromium-based) |
Note: Firefox 109+ is required for Manifest V3 support with ES modules in background scripts.
Need to support older Firefox versions? See Firefox MV2 Guide for using Manifest V2 with Firefox.
Used by extensions in production that has over 100,000+ users.
Use this template
Create a new directory and run
curl -fsSL https://github.com/abhijithvijayan/web-extension-starter/archive/react-typescript-vite.tar.gz | tar -xz --strip-components=1
ð Quick Start
Ensure you have Node.js 20 or later installed.
Then run the following:
# Install dependencies
npm install
# Start development server
npm run dev:chrome # For Chrome
npm run dev:firefox # For Firefox
# Build for production
npm run build:chrome # Build Chrome extension
npm run build:firefox # Build Firefox addon
npm run build # Build for all browsers
Project Structure
source/
âââ Background/ # Service worker (Chrome MV3) / Background script (Firefox)
âââ ContentScript/ # Content scripts (injected into web pages)
âââ Popup/ # Extension popup UI
âââ Options/ # Options page UI
âââ components/ # Shared React components
âââ styles/ # Global styles and variables
âââ types/ # TypeScript type definitions
âââ utils/ # Utility functions
âââ public/ # Static assets (icons, etc.)
âââ manifest.json # Extension manifest template
Development
Loading the Extension
Chrome
- Navigate to
chrome://extensions - Enable "Developer mode"
- Click "Load unpacked"
- Select
extension/chromedirectory
Firefox
- Navigate to
about:debugging - Click "This Firefox"
- Click "Load Temporary Add-on"
- Select
extension/firefox/manifest.json
Content Scripts
Content scripts are automatically bundled as IIFE (Immediately Invoked Function Expression) to ensure compatibility with the browser's content script execution environment, which doesn't support ES modules.
Browser-Specific Manifest
The manifest uses vendor prefixes to generate browser-specific configurations:
{
"__chrome__name": "My Chrome Extension",
"__firefox__name": "My Firefox Addon",
"__chrome|firefox__description": "Works on both!"
}
See vite-plugin-wext-manifest for more details.
Scripts
| Script | Description |
|---|---|
npm run dev:chrome | Start dev server for Chrome |
npm run dev:firefox | Start dev server for Firefox |
npm run build:chrome | Build production Chrome extension |
npm run build:firefox | Build production Firefox addon |
npm run build | Build for all browsers |
npm run lint | Run ESLint |
npm run lint:fix | Run ESLint with auto-fix |
Linting & TypeScript Config
- Shared ESLint & Prettier Configuration -
@abhijithvijayan/eslint-config - Shared TypeScript Configuration -
@abhijithvijayan/tsconfig
Bugs
Please file an issue here for bugs, missing documentation, or unexpected behavior.
License
MIT © Abhijith Vijayan
Top Related Projects
A Chrome Extensions boilerplate using React 18 and Webpack 5.
A command line tool to help build, run, and test web extensions
🛠️ A Vue CLI 3+ preset (previously a Vue CLI 2 boilerplate) for quickly starting a web extension with Vue, Babel, ESLint and more!
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot



