Matthew Casperson Matthew Casperson October 1, 2018

Selenium series: Firefox debugging tricks

This post is part of a series about creating a Selenium WebDriver test framework.

A common issue that I’ve run into on multiple occasions when using proxies is a subtle misconfiguration in Firefox that results in errors being thrown.

To simulate this error lets attempt to configure the SOCKS proxy in the BrowserMobDecorator class.

SOCKS proxies are used to proxy TCP packets, meaning they can be used with HTTP, HTTPS, FTP, and a whole range of other higher level protocols. We won’t use BrowserMob as a SOCKS proxy, but configuring it here is a useful way to demonstrate the misconfiguration error.

We configure the SOCKS proxy by calling seleniumProxy.setSocksProxy(proxyStr):

public DesiredCapabilities getDesiredCapabilities() {

  proxy = new BrowserMobProxyServer();


  final Proxy seleniumProxy = new Proxy();
  final String proxyStr = "localhost:" + proxy.getPort();

  final DesiredCapabilities desiredCapabilities =

  desiredCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy);

  return desiredCapabilities;

Running a test in Firefox with this configuration will result in the exception below being thrown:

org.openqa.selenium.SessionNotCreatedException: InvalidArgumentError: Expected [object Undefined] undefined to be an integer
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'Christinas-MBP', ip: '',
'Mac OS X', os.arch: 'x86_64', os.version: '10.13.5', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver
remote stacktrace: WebDriverError@chrome://marionette/content/error.js:178:5

From the message in the exception it appears that some remote JavaScript code resulted in an error. But where is this JavaScript code, and how can we debug the error?

Looking at the JavaScript stack trace, it appears that the source of the error is in these two lines of code. A method called fromJSON() is making an assertion that an integer is positive, and this assertion is failing:


The key to debugging this error is to understand that the file chrome://marionette/content/session.js is bundled with Firefox. If you enter that URL into Firefox, you can see the source of the file.

In this case, the offending line of code is:

p.socksVersion = assert.positiveInteger(json.socksVersion);

From this code we can deduce that we need to define the version of the SOCKS proxy.

In theory, you can define the SOCKS proxy version with the following code in the BrowserMobDecorator class:

public DesiredCapabilities getDesiredCapabilities() {
  // ...
  // ...

In practice, there are bugs in the WebDriver library that will still cause this code to fail. However, the important thing to take away from this post is that when you see Firefox stack traces with URLs that start with chrome://marionette/, you can access the source of those files by entering the URL into Firefox directly in order to debug the root cause.

This post is part of a series about creating a Selenium WebDriver test framework.