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

foxdriver

v1.0.6

Published

Foxdriver is a Node library which provides a high-level API to control Firefox over the Remote Debugging Protocol

Downloads

419

Readme

Foxdriver Foxdriver test pipeline

Foxdriver is a Node library which provides a high-level API to control Firefox over the Remote Debugging Protocol.

Getting Started

Installation

To use Foxdriver in your project, run:

$ npm i foxdriver

Usage

The Firefox Remote Debugging Protocol consists of multiple actors that provide different methods. The Foxdriver API allows you to launch a Firefox instance and connects to the protocol interface automatically. From there you can access the methods of all actors.

Example - opening page and get console.logs

import Foxdriver from 'foxdriver'

(async () => {
    const { browser, tab } = await Foxdriver.launch({
        url: 'https://www.mozilla.org/en-US'
    });

    // attach to created tab
    await tab.attach();
    // enable actor
    await tab.console.startListeners();
    // wait until page is loaded
    await new Promise((resolve) => setTimeout(resolve, 3000));
    // receive logs and page errors
    const logs = await tab.console.getCachedMessages();
    console.log(logs);

    // close browser
    browser.close();
})()

You can also attach yourself to an already running Firefox browser. This requires to start the browser with the -start-debugger-server=<port> cli argument and have the following settings set:

  • devtools.chrome.enabled: true
  • devtools.debugger.prompt-connection: false
  • devtools.debugger.remote-enabled: true

To attach yourself to the browser you then need to create a Foxdriver instance with the correct port and host and call the connect() method:

import Foxdriver from 'foxdriver'

(async () => {
    const { browser, tab } = await Foxdriver.attach('localhost', 9222);
    const preferences = await browser.preference.getAllPrefs();

    // ...
})()

API

Foxdriver

Foxdriver.attach(host, port)

Attaches client to an already running instance.

  • host <String> host where Firefox instance was launched
  • port <Number> port on which the Firefox instance was launched
  • returns: <Promise<Object>>
    • tab <[Tab]> list of opened tabs
    • browser <Browser> browser instance

Foxdriver.launch(options)

Attaches client to an already running instance.

  • options <Object>
    • port <Number> port on which the Firefox instance should get launched
    • bin <String> path to Firefox binary (default: OS default path)
    • args <[String]> list of arguments pass to fs.spawn (default: [])
    • customPrefs <Object> you may set your own preferences before the browser is being launched by setting key value pairs of prefs. Note that it is not possible to override the required prefs, i.e.
      • devtools.chrome.enabled: true
      • devtools.debugger.prompt-connection: false
      • devtools.debugger.remote-enabled: true
    • customProfileFiles <[String]> A array of absolute file paths to be copied into the randomaly generated profile folder. This is very helpful when working with self-signed certificates in firefox. See more here How to use self-signed certificate in Firefox
  • returns: <Promise<Object>>
    • tab <Tab> opened tab
    • browser <Browser> browser instance

class: Browser

close()

Disconnects from the browser instance and closes browser if launched via launch() method

class: Tab

tab.attach()

Attaches to this tab

  • returns: <Promise> fulfills once request was sent
tab.detach()

Detaches from this tab

  • returns: <Promise> fulfills once request was sent
tab.reload()

Reloads current page url.

  • returns: <Promise> fulfills once request was sent
tab.cacheDisabled(disable)

Disable cache.

  • disable <Boolean> if true, caching is disbled
  • returns: <Promise> fulfills once request was sent
tab.navigateTo(url)

Navigates to a certain url

  • url <String> url to navigate to
  • returns: <Promise> fulfills once request was sent
tab.onTabNavigated(callback)

Event fired on tab navigation end

  • callback <Function> to be called on event

For more information please see API docs.