Get your setup working faster. Join our Discord for optimisation tips from elite testers.Join our Discord
Add plugins/extensions to remote browsers
Learn how to add extensions to remote Chrome browsers in BrowserStack Automate.
You can add extensions to remote Chrome browsers in BrowserStack Automate.
End-users extend browser functionalities with plugins / extensions. For some scenarios, you may need to verify the following:
How your web pages look or behave on browsers with 3rd party plugins / extensions.
How your plugin / extension modifies the appearance or behavior of different webpages.
You can add plugins / extensions to remote browsers in BrowserStack Automate.
This page shows you how to add extensions to remote Chrome browsers. Weβll update it to include Firefox soon.
Starting with Chrome 137, and continuing in Chrome 149, Googleβs branded Chrome blocks the --load-extension flag and applies stricter extension-trust checks, which can prevent your extension from loading in a remote session. Chrome for Testing is exempt from this restriction, so itβs the recommended browser for extension testing on the latest Chrome versions. Set browserName to chromefortesting to use it. See Select browsers and devices for supported versions and platforms.
Verify your specific extension-loading flow works as expected when using Chrome for Testing, as extension behavior may vary across different extension types and configurations.
Prerequisites
First, youβll need the Chrome extensionβs .crx file. To obtain it, follow the steps below:
Find the Extension ID
Open Google Chrome browser on your workstation.
Open URL: chrome://extensions/. This will show you a list of installed extensions.
Tick the Developer Mode checkbox. This will show you the ID of each extension installed on your Chrome browser.
Find the extension you want to add on the remote Chrome browser. Copy its extension ID to Notepad.
Locating Extension-version subdirectory
Find the extensions directory on your workstation.
In the extensions directory, find the subdirectory with the extensionβs version number.
Copy the path to this extension-version subdirectory and paste it in the Notepad.
Pack extension
Go back to Google Chrome extensions page and click βPack extensionβ.
In the dialogue box that pops up, paste the path to the extension-version subdirectory in the βExtension root directoryβ input field.
Click the βPack extensionβ button. This will create a .crx file in the extension-version folder.
Copy the path to the extension-version folder (now containing the .crx file). Weβll need this path to configure our Selenium test.
Adding extensions to remote Chrome browser
This section shows you how to use Seleniumβs chromeOptions class to add extensions in our remote Chrome browsers.
Add the code snippet below in your test script. This will instruct the remote ChromeDriver to add the specified extension before executing the test:
MutableCapabilitiescapabilities=newMutableCapabilities();ChromeOptionsoptions=newChromeOptions();HashMap<String,Object>browserstackOptions=newHashMap<String,Object();capabilities.setCapability("browserName","Chrome");browserstackOptions.put("os","Windows");browserstackOptions.put("osVersion","10");capabilities.setCapability("bstack:options",browserstackOptions);options.addExtensions(newFile("<path to extension directory>.crx"));capabilities.setCapability(ChromeOptions.CAPABILITY,options)
/* You need to use the below modules into your NodeJS test before implementing this code.
var chrome = require("selenium-webdriver/chrome");
var fs = require('fs');
*/letfile_path='<path to extension directory>.crx';letbuff=newBuffer.from(fs.readFileSync(file_path));letbase64data=buff.toString('base64');varcapabilities={'bstack:options':{"os":"Windows","osVersion":"10",},"chromeOptions":{"extensions":[base64data]}"browserName":"Chrome","browserVersion":"latest",}vardriver=newwebdriver.Builder().usingServer('https://hub-cloud.browserstack.com/wd/hub').withCapabilities(capabilities).build();
/* You need to use the below packages into your C# test before implementing
this code.
using System.IO;
using System.Collections.Generic;
*/IWebDriverdriver;Byte[]bytes=File.ReadAllBytes("<path to extension directory>.crx");Stringcrx_file_base64=Convert.ToBase64String(bytes);String[]files_string_array={crx_file_base64};Dictionary<string,object>chromeOptionsD=newDictionary<string,object>();chromeOptionsD.Add("extensions",files_string_array);ChromeOptionscapabilities=newChromeOptions();capabilities.BrowserVersion="latest";Dictionary<string,object>browserstackOptions=newDictionary<string,object>();browserstackOptions.Add("os","Windows");browserstackOptions.Add("osVersion","10");browserstackOptions.Add("browserName","Chrome");capabilities.AddAdditionalOption("bstack:options",browserstackOptions);driver=newRemoteWebDriver(newUri("https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub/"),capabilities);
/* Requires PHP Class
You need to use the class "Facebook\WebDriver\Chrome\ChromeOptions" into your PHP test before implementing following code. */$options=newChromeOptions();$options->addExtensions(array('<path to extension directory>.crx',));$caps=array('bstack:options'=>array("os"=>"Windows","osVersion"=>"10","chromeOptions"=>$options),"browserName"=>"Chrome","browserVersion"=>"latest",)$web_driver=RemoteWebDriver::create("https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",$caps);
chrome_options=Options()chrome_options.add_extension('<path to extension directory>.crx')desired_cap=chrome_options.to_capabilities()desired_cap={'bstack:options':{"os":"Windows","osVersion":"10",},"browserName":"Chrome","browserVersion":"latest",}
caps=Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions"=>{"extensions"=>[Base64.strict_encode64(File.open("<path to extension directory>.crx",'rb').read)]})capabilities={'bstack:options'=>{"os"=>"Windows","osVersion"=>"10",},"browserName"=>"Chrome","browserVersion"=>"latest",}driver=Selenium::WebDriver.for:remote,url: 'https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub',desired_capabilities: caps
DesiredCapabilitiescaps=newDesiredCapabilities();ChromeOptionsoptions=newChromeOptions();caps.setCapability("os","Windows");caps.setCapability("os_version","10");options.addExtensions(newFile("<path to extension directory>.crx"));caps.setCapability(ChromeOptions.CAPABILITY,options)
/* You need to use the below modules into your NodeJS test before implementing this code.
var chrome = require("selenium-webdriver/chrome");
var fs = require('fs');
*/letfile_path='<path to extension directory>.crx';letbuff=newBuffer.from(fs.readFileSync(file_path));letbase64data=buff.toString('base64');varcapabilities={'browserName':'Chrome','os':'Windows','os_version':'10','chromeOptions':{'extensions':[base64data]}}vardriver=newwebdriver.Builder().usingServer('https://hub-cloud.browserstack.com/wd/hub').withCapabilities(capabilities).build();
/* You need to use the below packages into your C# test before implementing
this code.
using System.IO;
using System.Collections.Generic;
*/IWebDriverdriver;Byte[]bytes=File.ReadAllBytes("<path to extension directory>.crx");Stringcrx_file_base64=Convert.ToBase64String(bytes);String[]files_string_array={crx_file_base64};Dictionary<string,object>chromeOptionsD=newDictionary<string,object>();chromeOptionsD.Add("extensions",files_string_array);DesiredCapabilitiescapabilities=newDesiredCapabilities();capabilities.SetCapability("browserName","Chrome");capabilities.SetCapability("browserVersion","75.0");capabilities.SetCapability("chromeOptions",chromeOptionsD);driver=newRemoteWebDriver(newUri("https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub/"),capabilities);
/* Requires PHP Class
You need to use the class "Facebook\WebDriver\Chrome\ChromeOptions" into your PHP test before implementing following code. */$options=newChromeOptions();$options->addExtensions(array('<path to extension directory>.crx',));$caps=array("browser"=>"Chrome","os"=>"Windows","os_version"=>"10","chromeOptions"=>$options);$web_driver=RemoteWebDriver::create("https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",$caps);
chrome_options=Options()chrome_options.add_extension('<path to extension directory>.crx')desired_cap=chrome_options.to_capabilities()desired_cap.update({'browser':'chrome','os':'Windows','os_version':'10'})
caps=Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions"=>{"extensions"=>[Base64.strict_encode64(File.open("<path to extension directory>.crx",'rb').read)]})caps['browser']='Chrome'caps['os']='Windows'caps['os_version']='10'driver=Selenium::WebDriver.for:remote,url: 'https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub',desired_capabilities: caps
Did this page help you?
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback
Is this page helping you?
Yes
No
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked