Skip to content

Instantly share code, notes, and snippets.

@tzvc
Created October 25, 2022 21:03
Show Gist options
  • Save tzvc/b3e444de00f99508d53ac20d9fbfd0f3 to your computer and use it in GitHub Desktop.
Save tzvc/b3e444de00f99508d53ac20d9fbfd0f3 to your computer and use it in GitHub Desktop.

Custom profiles on selenium-webdriver are sometimes fiddly. Try setting the preferences directly.

Here's the updated code for your example:

import {Builder, WebDriver} from 'selenium-webdriver';
import {Options} from "selenium-webdriver/firefox";

const customUA = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36";
const options = new Options().setPreference('general.useragent.override', customUA);
const builder = new Builder().forBrowser('firefox').setFirefoxOptions(options);

const webDriver = this.createClientBuilder().build();

webDriver.get('http://whatsmyuseragent.com/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment