<commit_before>---
layout: docs
title: Using Chrome Device Emulation
permalink: /documentation/using-testcafe/common-concepts/browsers/using-chrome-device-emulation.html
---
# Using Chrome Device Emulation

You can run test in Chrome's built-in [device emulator](https://developers.google.com/web/tools/chrome-devtools/device-mode/). To do this, use the `emulation` browser parameter.

## Emulate a Device

Specify the target device with the `device` parameter.

```sh
testcafe "chrome:emulation:device=iphone X" tests/sample-fixture.js
```

```js
runner
    .src('tests/sample-fixture.js')
    .browsers('chrome:emulation:device=iphone X')
    .run();
```

## Emulate a Screen Size

You can configure the device emulator by providing `width`, `height`, `orientation`, etc.

```sh
testcafe "chrome:emulation:width=100;height=200;mobile=true;orientation=vertical;touch=true" tests/sample-fixture.js
```

```js
runner
    .src('tests/sample-fixture.js')
    .browsers('chrome:emulation:width=100;height=200;mobile=true;orientation=vertical;touch=true')
    .run();
```

## Use Emulation in Headless Mode

You can combine both device emulation and headless mode.

```sh
testcafe "chrome:headless:emulation:device=iphone X;cdpPort=9223" tests/sample-fixture.js
```

```js
runner
    .src('tests/sample-fixture.js')
    .browsers('chrome:headless:emulation:device=iphone X;cdpPort=9223')
    .run();
```

## Use Emulation in Portable Chrome

To enable device emulation in a portable Chrome, use the [browser alias](browser-support.md#locally-installed-browsers). The `path:` prefix does not work in this case.

```sh
testcafe "chrome:d:\chrome_portable\chrome.exe:emulation:device=iphone X" tests/test.js
```

## Substitute a User Agent

Use the `userAgent` parameter to substitute a user agent string.

> Important! TestCafe relies on the user agent string to emulate the browser behavior. Tests are not guaranteed to run correctly if you provide a user agent that is invalid or not supported by TestCafe.

You need to escape special characters in the user agent string when you specify it in the command line. These characters include:

* `\` (backslash)
* `'` (single quote)
* `"` (double quote)
* `,` (comma)
* `;` (semicolon)
* `:` (colon)

The way to escape special characters depends on the shell you use. You also need to escape semicolons from the TestCafe argument parser with an additional backslash.

The following examples show user agent strings escaped for `bash` and `PowerShell`.

**bash**

In `bash`, put a dollar sign before the argument to allow single quotes. Escape special characters with a backslash and use a double backslash for semicolons to escape them from the TestCafe argument parser:

```sh<commit_msg>Add a link (#3895)<commit_after>---
layout: docs
title: Using Chrome Device Emulation
permalink: /documentation/using-testcafe/common-concepts/browsers/using-chrome-device-emulation.html
---
# Using Chrome Device Emulation

You can run test in Chrome's built-in [device emulator](https://developers.google.com/web/tools/chrome-devtools/device-mode/). To do this, use the `emulation` browser parameter.

## Emulate a Device

Specify the target device with the `device` parameter.

```sh
testcafe "chrome:emulation:device=iphone X" tests/sample-fixture.js
```

```js
runner
    .src('tests/sample-fixture.js')
    .browsers('chrome:emulation:device=iphone X')
    .run();
```

## Emulate a Screen Size

You can configure the device emulator by providing `width`, `height`, `orientation`, etc.

```sh
testcafe "chrome:emulation:width=100;height=200;mobile=true;orientation=vertical;touch=true" tests/sample-fixture.js
```

```js
runner
    .src('tests/sample-fixture.js')
    .browsers('chrome:emulation:width=100;height=200;mobile=true;orientation=vertical;touch=true')
    .run();
```

## Use Emulation in Headless Mode

You can combine both device emulation and headless mode.

```sh
testcafe "chrome:headless:emulation:device=iphone X;cdpPort=9223" tests/sample-fixture.js
```

```js
runner
    .src('tests/sample-fixture.js')
    .browsers('chrome:headless:emulation:device=iphone X;cdpPort=9223')
    .run();
```

## Use Emulation in Portable Chrome

To enable device emulation in a portable Chrome, use the [browser alias](browser-support.md#locally-installed-browsers). The `path:` prefix does not work in this case.

```sh
testcafe "chrome:d:\chrome_portable\chrome.exe:emulation:device=iphone X" tests/test.js
```

## Substitute a User Agent

Use the `userAgent` parameter to substitute a user agent string.

> Important! TestCafe relies on the user agent string to emulate the browser behavior. Tests are not guaranteed to run correctly if you provide a user agent that is invalid or [not supported by TestCafe](browser-support.md).

You need to escape special characters in the user agent string when you specify it in the command line. These characters include:

* `\` (backslash)
* `'` (single quote)
* `"` (double quote)
* `,` (comma)
* `;` (semicolon)
* `:` (colon)

The way to escape special characters depends on the shell you use. You also need to escape semicolons from the TestCafe argument parser with an additional backslash.

The following examples show user agent strings escaped for `bash` and `PowerShell`.

**bash**

In `bash`, put a dollar sign before the argument to allow single quotes. Escape special characters with a backslash and use a double backslash for semicolons to escape them from the TestCafe argument parser:

```sh
{'fraction_non_alphanumeric': 0.1146763901549681, 'fraction_numerical': 0.008021877848678213, 'mean_word_length': 4.976034858387799, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4639122', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1642, 'n_words': 576}