Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Foxdriver: A Node.js Remote Debugging Client

DZone's Guide to

Foxdriver: A Node.js Remote Debugging Client

Check out Foxdriver, an open source Node.js remote debugging client for Firefox. See how it can help with WebDriver testing.

· DevOps Zone ·
Free Resource

Download the blueprint that can take a company of any maturity level all the way up to enterprise-scale continuous delivery using a combination of Automic Release Automation, Automic’s 20+ years of business automation experience, and the proven tools and practices the company is already leveraging.

Sauce Labs is pleased to announce that it is open-sourcing one of its internal projects called Foxdriver. It is a Node.js remote debugging client for Firefox that allows developer to boot a fresh Firefox instance or attach themselves to an already-running instance, e.g. while running a WebDriver test. It provides access to the Firefox Remote Debugging Protocol, which is a comprehensive interface to remote-control the browser.

As part of our internal effort to surface as much information as possible about the state of a customer's application, we built this tool to capture, for example, network data, and other useful metrics during WebDriver tests in our cloud. It also allows certain browser emulations that would not be possible using just the WebDriver protocol.

The following script demonstrates how to listen to network events during your WebDriver test. It uses WebdriverIO as the WebDriver client. In addition to that, the script creates a specific Firefox profile that is required in order to allow 3rd party clients, like Foxdriver, to connect to the browser:

import Foxdriver from 'foxdriver'
import FirefoxProfile from 'firefox-profile'
import { remote } from 'webdriverio'

(async () = > {
    const fp = new FirefoxProfile()
    fp.setPreference('devtools.debugger.remote-enabled', true)
    fp.setPreference('devtools.chrome.enabled', true)
    fp.setPreference('devtools.debugger.prompt-connection', false)

    const zippedProfile = await new Promise((resolve, reject) = > {
        fp.encoded((err, zippedProfile) = > {
            if (err) return reject(err)
            return resolve(zippedProfile)
        })
    })

    const browser = remote({
        desiredCapabilities: {
            browserName: 'firefox',
            'moz:firefoxOptions': {
                args: ['--start-debugger-server', '9222'],
                profile: zippedProfile
            }
        }
    })

    / / start browser
    await browser.init()

    / / attach to browser
    const { tabs } = await Foxdriver.attach('localhost', 9222)

    / / listen to network events
    await tabs[0].network.startListeners()
    await tabs[0].network.on('request',
        ({url, method}) = > console.log("new request:", method, url)
    )

    / / open page
    await browser.url('https:/ /www.mozilla.org/en-US')

    / / close session
    await browser.end()
})()

Once you've attached yourself to a tab, you can access various so-called "Actors". Each Actor addresses a certain domain within the browser and allows you to listen to its events or manipulate its behavior. Some of the currently supported actors are Network, Profiler, Performance, and Emulation, just to name a few. These can be very useful if you want to access functionality beyond the WebDriver protocol.

Have a look at more of such examples at https://github.com/saucelabs/foxdriver.

The first release of Foxdriver already implements most of the common actors provided by the Firefox Remote Debugging Protocol. Our team is working on covering more in order to make the whole protocol accessible over a simplified API. We are looking for your feedback and appreciate any kind of contribution. We love Open Source!

The project was highly inspired by Heather Arthur's initial project called firefox-client.

We <3 Open Source at Sauce Labs and encourage Saucers to contribute to projects like Appium, Selenium and their own initiatives.

Download the ‘Practical Blueprint to Continuous Delivery’ to learn how Automic Release Automation can help you begin or continue your company’s digital transformation.

Topics:
node.js ,foxdriver ,debugging ,firefox ,testing ,devops

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}