# How to change User-Agent for WebdriverIO  & Playwright Tests

One may want to change/update the user agent for various use cases.

One such use case is :

* Ensuring user analytics (e.g. Segment) is not triggered for your automated test cases. Not doing this may result in a higher analytics bill.
    

**Solution:**

The solution is to update your config and leave the tests untouched.

### Config for WebdriverIO BrowserStack Run

```json
export const config: WebdriverIO.Config = {
  runner: 'local',
  specs: ['./features/**/*.feature'],
  exclude: [],
  maxInstances: 2,
  capabilities: [
    {
      'bstack:options': {
        os: process.env.OS_NAME || 'OS X',
        osVersion: process.env.OS_VERSION || 'Big Sur',
      },
      browserName: 'Chrome',
      browserVersion: 'latest',
      'goog:chromeOptions': {
        args: ['user-agent=madeup-user-agent-name'],
      },
    },
  ],
}
```

### Config for WebDriverIO Local Run

```json
export const config: WebdriverIO.Config = {
  runner: 'local',
  specs: ['./features/**/*.feature'],
  exclude: [],
  maxInstances: 10,
  capabilities: [
    {
      maxInstances: 1,
      browserName: 'chrome',
      acceptInsecureCerts: true,
      'goog:chromeOptions': {
        args: ['user-agent=madeup-user-agent-name'],
      },
    },
  ],
}
```

### Config for Playwright Local Run

```json
const config: PlaywrightTestConfig = {
   use: {
    ignoreHTTPSErrors: true,
    contextOptions: {
      bypassCSP: true,
      recordVideo: {
        dir: 'e2e/videos',
      },
      userAgent: 'madeup-user-agent-name',
    },
    headless: true,
    screenshot: 'only-on-failure',
    trace: 'on',
    video: 'retain-on-failure',
  },
};
export default config;
```

### Config for Playwright Docker Run

```json
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  use: {
    headless: true,
    navigationTimeout: 30000,
    actionTimeout: 10000,
    screenshot: 'only-on-failure',
    ignoreHTTPSErrors: true,
    contextOptions: {
      bypassCSP: true,
    },
  },
  projects: [
    {
      name: 'Chrome',
      use: {
        browserName: 'chromium',
        contextOptions: {
          ignoreHTTPSErrors: true,
          userAgent: 'madeup-user-agent-name',
        },
      },
    },
  ],
};
export default config;
```

**Resources**

* [https://github.com/microsoft/playwright/issues/11829](https://github.com/microsoft/playwright/issues/11829)
