Socket
Socket
Sign inDemoInstall

@webextension-toolbox/webextension-toolbox

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webextension-toolbox/webextension-toolbox

Framework for WebExtensions (Firefox, Chrome, Opera, Edge)


Version published
Maintainers
3
Created
Source

WebExtension Toolbox

npm version Node.js CI JavaScript Style Guide license

Small cli toolbox for creating cross-browser WebExtensions.

If you want to get started quickly check out the yeoman generator for this project.

Browser Support

  • Chrome (chrome) (auto polyfilled)
  • Opera (opera) (auto polyfilled)
  • Edge (edge) (auto polyfilled)
  • Firefox (firefox)
  • Safari (safari)

Features

React.js

  1. npm install @babel/preset-react --save-dev
  2. Create a .babelrc file next to your package.json file and insert the following contents:
{
  "presets": [
    "@babel/preset-react"
  ]
}

Packing

The build task creates bundles for:

  • Firefox (.xpi)
  • Chrome (.zip)
  • Opera (.crx)
  • Edge (.zip)
  • Safari (.zip)

Manifest validation

Validates your manifest.json while compiling.

You can skip this by adding --validateManifest to your build or dev command.

Manifest defaults

Uses default fields (name, version, description) from your package.json

Manifest vendor keys

Allows you to define vendor specific manifest keys.

Example

manifest.json

"name": "my-extension",
"__chrome__key": "yourchromekey",
"__chrome|opera__key2": "yourblinkkey"

If the vendor is chrome it compiles to:

"name": "my-extension",
"key": "yourchromekey",
"key2": "yourblinkkey"

If the vendor is opera it compiles to:

"name": "my-extension",
"key2": "yourblinkkey"

else it compiles to:

"name": "my-extension"

Polyfill

The WebExtension specification is currently supported on Chrome, Firefox, Edge (Chromium) and Safari (Safari Web Extension’s Browser Compatibility).

This toolbox no longer provides any polyfills for cross-browser support. If you need polyfills e.g. between 'browser' and 'chrome', we recommend detecting the browser during the build time using process.env.VENDOR.

This toolbox comes with babel-preset-env. Feel free add custom configuration if you need any custom polyfills.

Usage

Install

$ npm install -g webextension-toolbox

Development

  • Compiles the extension via webpack to dist/<vendor>.
  • Watches all extension files and recompiles on demand.
  • Reloads extension or extension page as soon something changed.
  • Sets process.env.NODE_ENV to development.
  • Sets process.env.VENDOR to the current vendor.

Syntax

$ webextension-toolbox dev <vendor> [..options]

Examples

$ webextension-toolbox dev --help
$ webextension-toolbox dev chrome
$ webextension-toolbox dev firefox
$ webextension-toolbox dev opera
$ webextension-toolbox dev edge

Build

  • Compile extension via webpack to dist/<vendor>.
  • Minifies extension Code.
  • Sets process.env.NODE_ENV to production.
  • Sets process.env.VENDOR to the current vendor.
  • Packs extension to packages.

Syntax

Usage: build [options] <vendor>

Compiles extension for production

Options:
  -s, --src [src]                       specify source directory (default: "app")
  -t, --target [target]                 specify target directory (default: "dist/[vendor]")
  -d, --devtool [devtool]               controls if and how source maps are generated (default: false)
  -m, --no-minimize                     disables code minification
  -v, --vendorVersion [vendorVersion]   last supported vendor (default: current)
  --validateManifest [validateManifest] validate manifest syntax (default: false)
  -h, --help                            output usage information

Browser API

Always use the WebExtension browser API. Webextension-Toolbox will polyfill it for you in chrome and opera.

Entry points

All javascript files located at the root of your ./app or ./app/scripts directory will create a seperate bundle.

appdist
app/background.jsdist/<vendor>/background.js
app/scripts/background.jsdist/<vendor>/scripts/background.js
app/some-dir/some-file.jsWill be ignored as entry file.
app/scripts/some-dir/some-file.jsWill be ignored as entry file.

Customizing webpack config

In order to extend our usage of webpack, you can define a function that extends its config via webextension-toolbox.config.js in your project root.

module.exports = {
  webpack: (config, { dev, vendor }) => {
    // Perform customizations to webpack config

    // Important: return the modified config
    return config;
  },
};

As WebExtension Toolbox uses webpack’s devtool feature under the hood, you can also customize the desired devtool with the --devtool argument.

For example, if you have problems with source maps on Firefox, you can try the following command:

webextension-toolbox build firefox --devtool=inline-cheap-source-map

Please see Issue #58 for more information on this

FAQ

What is the difference to web-ext?

If want to develop browser extensions for Firefox only web-ext might be a better fit for you, since it supports, extension signing, better manifest validation and auto mounting.

Nevertheless if you want to develop cross browser extensions using

  • the same development experience in every browser
  • a single codebase
  • react
  • and custom webpack configuration

webextension-toolbox might be your tool of choice.

License

Copyright 2021 Henrik Wenz

This project is free software released under the MIT license.

FAQs

Package last updated on 05 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc