Skip to main content
Get Automate insights in Microsoft Teams with our new integration! Get Started!.

Set browser options for Playwright tests

Learn how to set the required Chrome arguments for Firefox user preferences in your Playwright tests

What browser options can be set?

Playwright allows you to set browser arguments for Chromium based browsers and Firefox user preferences if the selected browser is Firefox. These arguments need to be set in your Playwright capabilities while testing on BrowserStack as well.

Set args for Chromium based browsers

You can set args for Chromium based browsers i.e. when you select chrome, edge, or playwright-chromium as the browser within BrowserStack capabilities as shown in the example below:

// Import Playwright dependencies

(async () => {
const caps = {
    'browser': 'chrome',
    'os': 'osx',
    'os_version': 'catalina',
    'name': 'My first playwright test',
    'build': 'playwright-build-1',
    'browserstack.username': process.env.BROWSERSTACK_USERNAME || 'YOUR_USERNAME',
    'browserstack.accessKey': process.env.BROWSERSTACK_ACCESS_KEY || 'YOUR_ACCESS_KEY',
    'args': ['--incognito']  // You can specify an array of strings here. Valid only if the browser is chromium based
  };
// Add CDP endpoint here to connect to BrowserStack  
  const browser = await chromium.connect({
    wsEndpoint: `wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent(JSON.stringify(caps))}`,
});
// BrowserStack specific code ends here

// Insert your test script here
})();

You can specify any argument from the list of all supported Chromium arguments.

Set Firefox user preferences

You can set firefox_user_prefs if the selected browser is playwright-firefox using the capability firefox_user_prefs as shown below:

// Import Playwright dependencies

(async () => {
const caps = {
    'browser': 'chrome',
    'browserstack.username': process.env.BROWSERSTACK_USERNAME || 'YOUR_USERNAME',
    'browserstack.accessKey': process.env.BROWSERSTACK_ACCESS_KEY || 'YOUR_ACCESS_KEY',
    'firefox_user_prefs': '<Object<string, string|number|boolean>>'  // You can pass the capability in the same format as supported by Playwright in the launch arguments
};
// Add CDP endpoint here to connect to BrowserStack
  const browser = await chromium.connect({
    wsEndpoint: `wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent(JSON.stringify(caps))}`,
});
// BrowserStack specific code ends here

// Insert your test script here
})();

The firefox_user_prefs capability value can be passed in the same format as supported by Playwright in the launch arguments. You can pass any firefox_user_prefs as supported by Playwright.

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






Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert