Beesbot

Selenium Chrome Browser with Extensions

Feb 22, 2018

I had the fortune to work at a place where a browser extensions called foxy proxy was needed to reach our stage servers. Selenium launches the chrome browser without extensions and therefore couldn't reach the stage site. But regardless of what extension you need, I can show you how to launch a selenium browser with extensions using ruby.

Create a Chrome Profile

There are many resources explaining how to do this, but essentially you need to create a chrome profile using instructions like these. While using that profile add whatever extensions you want selenium to use.

Copy your profile into your project

First you'll need to find your chrome profile and you can do that by reading through this howtogeek.com article on how to find your chrome profile folder that essentially tells you to browse to

chrome://version/

And get the Profile Path. You'll need to copy the contents of that folder into your project folder, placing them into .profiles/Default

Set switch for selenium web driver

When you launch your web driver you'll need to set a switch to use that profile

driver = Selenium::WebDriver.for :chrome, :switches => %W[--user-data-dir=.profiles --enable-logging  --incognito --ignore-certificate-errors]

Note the --.profiles switch that lets chrome know to use the profile you created. I included other useful switches like launching --incognito so your sessions don't affect selenium and --ignore-certificate-errors in case you're dealing with self signed certificates. Now when you launch your browser it should have the extensions and everything should be great.