Skip to content

Latest commit

 

History

History
66 lines (46 loc) · 1.67 KB

README.md

File metadata and controls

66 lines (46 loc) · 1.67 KB

Commands for Chrome and FirefoxWebExtensions

WebExtension API to perform browser actions, such as opening a new tab.

Dependencies

Installation

Chrome
make chrome

Open the Extensions page by navigating to chrome://extensions, enable Developer mode then Load unpacked to select the extension directory: target/chrome.

Firefox
make firefox
  • Open about:config, change xpinstall.signatures.required to false.
  • Open about:addonsExtensions, click Install add-on from file and select the package file: target/firefox/package.zip.

Usage

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