Commands for Chrome and Firefox – WebExtensions
WebExtension API to perform browser actions, such as opening a new tab.
make chrome
Open the Extensions page by navigating to chrome://extensions
, enable Developer mode then Load unpacked to select the extension directory: target/chrome
.
make firefox
- Open
about:config
, changexpinstall.signatures.required
tofalse
. - Open
about:addons
❯ Extensions, click Install add-on from file and select the package file:target/firefox/package.zip
.
// Environment variables
switch (true) {
case (typeof browser !== 'undefined'):
var PLATFORM = 'firefox'
var COMMANDS_EXTENSION_ID = 'commands@alexherbo2.github.com'
break
case (typeof chrome !== 'undefined'):
var PLATFORM = 'chrome'
var COMMANDS_EXTENSION_ID = 'cabmgmngameccclicfmcpffnbinnmopc'
break
}
// Initialization
const commands = {}
commands.port = chrome.runtime.connect(COMMANDS_EXTENSION_ID)
commands.send = (command, ...arguments) => {
commands.port.postMessage({ command, arguments })
}
// Usage
commands.send('new-tab', 'https://github.com')
You can find some examples in Krabby.
See the source for a complete reference.