Setting browser User Agent with Browserstack

Skip to first unread message

Shane Courville

Apr 26, 2017, 2:27:03 PM4/26/17
to Geb Development Mailing List
Hi all,

Not sure if this is the correct forum for this, but I am currently trying to figure out a way to set a browser's user-agent through Browserstack.

Currently, this is what our browser config area looks like in build.gradle:

browsers {
chrome_windows {
capabilities browser_version: "56.0", os: "Windows", os_version: "10", context: "desktop"

edge_windows {
capabilities browser_version: "14.0", os: "Windows", os_version: "10", context: "desktop"

ie_windows {
capabilities browser_version: "11.0", os: "Windows", os_version: "10", context: "desktop"

ipad2 {
capabilities browserName: "iPad", platform: "MAC", device: "iPad Air 2", context: "tablet"

iphone6S {
capabilities browserName: "iPhone", platform: "MAC", device: "iPhone 6S", context: "mobile"

We were thinking of trying to add this at the end of the capabilities, but it did not work:

user_agent: "--user-agent=<myagent>"

Marcin Erdmann

Apr 27, 2017, 3:58:48 AM4/27/17
Hi Shane,

The user group ( would probably be a better forum for this question as this is a list for discussions about development of Geb itself. I think we can live with this question here but please keep that in mind for the future.

Setting a user agent is browser specific (as this SO answer explains: so you won't get a one solution for all browsers to this problem.

In general you would need to create a custom implementation of BrowserStackDriverFactory which overrides configureCapabilities(DesiredCapabilities) and use that in your GebConfig.groovy instead of the one Geb ships with. It would look like the following if you were to do it for Firefox as an example:

class CustomUserAgentBrowserStackDriverFactory extends BrowserStackDriverFactory {

    protected void configureCapabilities(DesiredCapabilities desiredCapabilities) {
        if (desiredCapabilities.getCapability("browserName") == "firefox") {
            def profile = new FirefoxProfile()
            profile.setPreference("general.useragent.override", "whatever you want")
            desiredCapabilities.setCapability(FirefoxDriver.PROFILE, profile)


So basically you would be using the fact that overriding configureCapabilities(DesiredCapabilities) allows you to modify the DesiredCapabilities before a browser is provisioned for you by BrowserStack. You might find the following link useful as well as it explains how to configure ChromeOptions which are aparently used to set user agent in chrome:

Please let me know if you need more help with that.


You received this message because you are subscribed to the Google Groups "Geb Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

Shane Courville

Apr 27, 2017, 9:40:06 AM4/27/17
to Geb Development Mailing List
Hi Marcin,

Thank you for the response. This helps! I'll use the other user group in the future.

To unsubscribe from this group and stop receiving emails from it, send an email to
Reply all
Reply to author
0 new messages