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 theextension
directory from the build output. - Firefox: Go to
about:debugging#/runtime/this-firefox
, click "Load Temporary Add-on", and select themanifest.json
file from theextension
directory.
- 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.
ð§ââï¸ React + TypeScript = This branch
ð¨ React + JavaScript = Checkout react-javascript branch
ð¶ð¼ HTML + JavaScript = Checkout master branch
Features
- Cross Browser Support (Web-Extensions API)
- Browser Tailored Manifest generation
- Automatic build on code changes
- Auto packs browser specific build files
- SASS styling
- TypeScript by default
- ES6 modules support
- React UI Library by default
- Smart reload
Browser Support
49 & later â | 52 & later â | 36 & later â | 79 & later â | Latest â | Latest â | Latest â |
Used by extensions in production that has over 100,000+ users.
- daily.dev in daily.dev extension
- Jiffy Reader in ansh/jiffyreader.com
- kutt-extension in abhijithvijayan/kutt-extension
- doubanIMDb in lisongx/doubanIMDb
- Mooc Assistant in unbyte/mooc-assistant
- ArtiPub in crawlab-team/artipub
and many more...
Use this template
Create a new directory and run
curl -fsSL https://github.com/abhijithvijayan/web-extension-starter/archive/react-typescript.tar.gz | tar -xz --strip-components=1
ð Quick Start
Ensure you have
- Node.js 10 or later installed
Then run the following:
npm install
to install dependencies.npm run dev:chrome
to start the development server for chrome extensionnpm run dev:firefox
to start the development server for firefox addonnpm run dev:opera
to start the development server for opera extensionnpm run build:chrome
to build chrome extensionnpm run build:firefox
to build firefox addonnpm run build:opera
to build opera extensionnpm run build
builds and packs extensions all at once to extension/ directory
Development
-
npm install
to install dependencies. -
To watch file changes in development
- Chrome
npm run dev:chrome
- Firefox
npm run dev:firefox
- Opera
npm run dev:opera
- Chrome
-
Load extension in browser
-
Chrome
- Go to the browser address bar and type
chrome://extensions
- Check the
Developer Mode
button to enable it. - Click on the
Load Unpacked Extensionâ¦
button. - Select your browsers folder in
extension/
.
- Go to the browser address bar and type
-
Firefox
- Load the Add-on via
about:debugging
as temporary Add-on. - Choose the
manifest.json
file in the extracted directory
- Load the Add-on via
-
Opera
- Load the extension via
opera:extensions
- Check the
Developer Mode
and load as unpacked from extensionâs extracted directory.
- Load the extension via
Production
npm run build
builds the extension for all the browsers toextension/BROWSER
directory respectively.
Note: By default the manifest.json
is set with version 0.0.0
. The webpack loader will update the version in the build with that of the package.json
version. In order to release a new version, update version in package.json
and run script.
If you don't want to use package.json
version, you can disable the option here.
Generating browser specific manifest.json
Update source/manifest.json
file with browser vendor prefixed manifest keys
{
"__chrome__name": "SuperChrome",
"__firefox__name": "SuperFox",
"__edge__name": "SuperEdge",
"__opera__name": "SuperOpera"
}
if the vendor is chrome
this compiles to:
{
"name": "SuperChrome",
}
Add keys to multiple vendors by separating them with | in the prefix
{
__chrome|opera__name: "SuperBlink"
}
if the vendor is chrome
or opera
, this compiles to:
{
"name": "SuperBlink"
}
See the original README of wext-manifest-loader
package for more details
Bugs
Please file an issue here for bugs, missing documentation, or unexpected behavior.
Linting & TypeScript Config
- Shared Eslint & Prettier Configuration -
@abhijithvijayan/eslint-config
- Shared TypeScript Configuration -
@abhijithvijayan/tsconfig
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