This template is a starting point for generating browser extensions. It can generate different extension builds for different browsers (Chrome and Firefox by default), and comes with the following as a starting point:
- options page (shown when editing an extension's options)
- popup page (shown when clicking on the extension)
- background service worker (runs behind the scenes with no access to a page's content)
- content script that runs on every website (runs with access to a page's content)
Steps:
- Install project dependencies:
npm install
- Run the build. This will build all browser specific versions of the extension:
npm run build:prod
Steps:
- Run the dev build for the browser, watch for changes, and rebuild whenever a file changes (or you can use the prod build from above and can skip this step):
npm run build:chrome
- Go to the extensions page (copy and past this in the browser url):
chrome://extensions
- Turn on "Developer Mode"
- Click on "Load unpacked" under Extensions
- Select the Chrome build folder:
build/chrome
Note: you will need to reload the extension whenever you make a change to the source.
The files will rebuild as long as npm run build:chrome
is still running, but the extension won't reload until you manually reload it from the extensions page.
Steps:
- Run the dev build for the browser, watch for changes, and rebuild whenever a file changes (or you can use the prod build from above and can skip this step):
npm run build:firefox
- Go to the about debugging page (copy and past this in the browser url):
about:debugging
- Click on the "This Firefox" option
- Click on the "Load Temporary Add-on" button
- Select the manifest file in the Firefox build folder:
build/firefox/manifest.json
Note: you will need to reload the extension whenever you make a change to the source.
The files will rebuild as long as npm run build:firefox
is still running, but the extension won't reload until you manually reload it from the extensions page.
Note: the extension will need to be re-added whenever Firefox restarts.
Note: the "manifest.firefox.json" file is set to use "manifest_version" 2. It isn't (currently?) possible to ask for some permissions during install or set that some permissions are required in version 3.
All of the extension development code exists in the src folder with html, images, scripts, and styles each living in their own directories.
There is a manifest.json file in the source folder that can be customized for each of the browsers.
The webpack.config.js file is used to build the extension output. It bundles each of the javascript entry targets and copies all the other files (html, images, styles) into the build output folder. It does this for each browser target and copies those files plus the correct manifest file to the build output folder. This can all be triggered by running the "build" scripts from the package.json file.