Thursday, May 19, 2011

Injecting Firebug into a remote FIrefox instance on Selenium 2

There are ample instructions about how to instantiate Firefox with Firebug on a localhost, but what if you're trying to do so with a reverse SSH tunnel (see and don't intend to be running things on your localhost? Well, the Selenium 2 developers provide a way, albeit not very well documented. Apparently there is an API command to base-64 encode a .zip file that can be transferred over the network to the remote browser.

1. First, create the profile on your local machine:

firefox -ProfileManager --no-remote

2. Install the Firebug add-on, enabling the Net/Console panels after the plug-in is installed (so these settings get saved inside your prefs.js file))

3. Tar up the profile directory (stored inside ~/.mozilla/firefox with some special hash prefix i.e. ~/.mozilla/firefox/60f709x.selenium) and transfer to the machine that will invoke

(At the time of this writing, you also must add a user.js file to the profile directory, since the Selenium Python bindings expect to find this file even though this file does not normally get created by default -- see patch submitted at and

4. Unzip the file into a directory.

Then the profile can be added as follows:

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
profile = FirefoxProfile(profile_directory="/home/myuserid/.mozilla")
profile.update_preferences() # increases the num of simultaneous connections among other things

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
profile = FirefoxProfile(profile_directory="/home/myuserid/.mozilla")

selenium_browser = webdriver.Remote(desired_capabilities=DesiredCapabilities.FIREFOX,

The Python bindings for Selenium 2 will take the directory, zip it up, base-64 encode, and transfer it over the network to the Selenium RC server. Note that the old Selenium 1.0 way of using the java -jar selenium-server.jar -firefoxProfileTemplate “<selenium Profile Directory>" (as described in seems to be ignored for WebDriver-based Selenium 2 tests, so if you're planning on using only Selenium 2, the approach described approach seems to be the way things work.


  1. Thanks. Using the above, I was also able to get profile management working for standalone Firefox webdriver, as in webdriver.Firefox(browser_profile=profile)
    Before, I never figured out the correct way to instantiate FirefoxProfile.

  2. BlueHost is ultimately the best website hosting company for any hosting plans you require.