Socket
Socket
Sign inDemoInstall

webextension-toolbox

Package Overview
Dependencies
338
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    webextension-toolbox

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


Version published
Maintainers
2
Install size
30.9 MB
Created

Changelog

Source

[4.0.3] - 2021-07-05

Changed

  • Merge pull request #494 from balcsida/bump-plugin 0480141
  • Bump webpack-webextension-plugin aca3298
  • Merge pull request #483 from webextension-toolbox/dependabot/npm_and_yarn/commander-8.0.0 56b8473
  • Bump commander from 8.0.0-2 to 8.0.0 19f8ebb
  • Merge pull request #492 from webextension-toolbox/dependabot/npm_and_yarn/core-js-3.15.2 ce8444b
  • Merge pull request #493 from webextension-toolbox/dependabot/npm_and_yarn/webpack-5.42.0 4c8f497
  • Merge pull request #488 from webextension-toolbox/dependabot/npm_and_yarn/string-replace-loader-3.0.3 51bf23e
  • Bump webpack from 5.40.0 to 5.42.0 d3ea350
  • Bump string-replace-loader from 3.0.2 to 3.0.3 d613295
  • Bump core-js from 3.15.0 to 3.15.2 ba85193
  • Merge pull request #485 from balcsida/ghactions/nodeci 4ad6afe
  • Merge pull request #487 from webextension-toolbox/dependabot/npm_and_yarn/copy-webpack-plugin-9.0.1 297b9fb
  • Bump copy-webpack-plugin from 9.0.0 to 9.0.1 e428f27
  • Use Latest version of setup-node 894261d

Readme

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)

Features

React.js

Works with React out of the box!
Run $ npm i react react-dom and you are ready to go.

Packing

The build task creates bundles for:

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

Manifest validation

Validates your manifest.json while compiling.

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 only supported by Firefox and Edge (Trident version). This toolbox adds the necessary polyfills for Chrome, Edge (Chromium) and Opera.

This way many webextension apis will work in Chrome, Edge (Chromium) and Opera out of the box.

In addition to that, this toolbox comes with babel-preset-env.

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)
  -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.

// This file is not going through babel transformation.
// So, we write it in vanilla JS
// (But you could use ES2015 features supported by your Node.js version)
const webpack = require('webpack')

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

Last updated on 05 Jul 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc