npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webextensions-geckodriver

v0.7.0

Published

Run your WebExtension with GeckoDriver

Downloads

22

Readme

WebExtensions GeckoDriver

When testing WebExtensions you might want to automatically load them into Firefox and do functional testing with geckodriver.

Installation

npm install --save-dev webextensions-geckodriver

Usage

const webExtensionsGeckoDriver = require('webextensions-geckodriver');
const webExtension = await webExtensionsGeckoDriver('/absolute/path/to/manifest.json');

Loads the WebExtension as Temporary Add-on into a new Firefox instance. See API docs for more details.

Example

manifest.json includes

  "browser_action": {
    "default_title": "Visit Example.com"
  },
  "applications": {
    "gecko": {
      "id": "@examplewebextension",
      "strict_min_version": "57.0"
    }
  }

Test could look like this (using mocha):

const path = require('path');
const assert = require('assert');

const webExtensionsGeckoDriver = require('webextensions-geckodriver');
const {webdriver} = webExtensionsGeckoDriver;

const manifestPath = path.resolve(path.join(__dirname, './path/to/manifest.json'));

describe('Example', () => {
  let geckodriver;

  before(async () => {
    const webExtension = await webExtensionsGeckoDriver(manifestPath);
    geckodriver = webExtension.geckodriver;
  });

  it('should have a Toolbar Button', async () => {
    const button = await geckodriver.wait(webdriver.until.elementLocated(
      // browser_actions automatically have applications.gecko.id as prefix
      // special chars in the id are replaced with _
      webdriver.By.id('_examplewebextension-browser-action')
    ), 1000);
    assert.equal(await button.getAttribute('tooltiptext'), 'Visit Example.com');
  });

  after(() => {
    geckodriver.quit();
  });
});

Full executable example is in the example directory.

API

Exported default function(path[, options])

  • path <string>, required, absolute path to the manifest.json file
  • options <object>, optional
    • binary <string>, optional, lets you set the binary that is passed to fx-runner. Possible values: firefox, beta, aurora, nightly, firefoxdeveloperedition. Defaults to: firefox.
    • autoInstall, <boolean>, optional, if set to false the extension will not be installed, you can manually do so later by calling install. Defaults to true.
    • webExt <object>, optional, lets you overwrite the parameters that get passed into web-ext.cmd.build
    • fxOptions firefox.Options, optional, a firefox.Options that will be passed to the webdriver

Returns a Promise that resolves with an initialized WebExtensionsGeckodriver instance in case of success, notably with the following properties:

  • geckodriver, <object>, a new selenium-webdriver/firefox instance with previously loaded geckodriver
  • install, <function>, returns a Promise that resolves when installing is finished, accepts an options <object>:
    • extensionPath, <string>, optional, path to something that installAddon can handle. Defaults to the web-ext build extensionPath.
    • temporary, <boolean>, optional, whether the WebExt should be installed temporary. Defaults to true.
  • internalUUID, <function>, returns a Promise that resolves to the Internal UUID of the installed extension
  • uninstall, <function>, returns a Promise that resolves when uninstalling is finished, accepts an optional extensions id as <string>

Exported property: webdriver

Return value of require('selenium-webdriver')

Exported property: firefox

Return value of require('selenium-webdriver/firefox')

Travis Configuration

dist: xenial
services:
  - xvfb

language: node_js
addons:
  firefox: latest

node_js:
  - 'lts/*'

Headless Example

const webExtensionsGeckoDriver = require('webextensions-geckodriver');

const {firefox} = webExtensionsGeckoDriver;
// or equivalently:
//   const firefox = require('selenium-webdriver/firefox')

const fxOptions = new firefox.Options()
  .headless()
  .windowSize({height: 1080, width: 1920}) // If you rely on viewport size

webExtensionsGeckoDriver(manifestPath, {fxOptions})

JSDOM

If you're looking for a way to test WebExtensions with JSDOM then webextensions-jsdom might be for you.

Credits

Thanks to Standard8 for the original work in example-webextension.