---
title: 'Playwright testing on iOS: real devices and simulators'
description: Run Playwright tests against Mobile Safari on real iPhones and iPads
  and on iOS simulators in the TestingBot cloud. Connect with webkit.connect(), pick
  a device, and get a video and logs of every session.
source_url:
  html: https://testingbot.com/support/web-automate/playwright/ios
  md: https://testingbot.com/support/web-automate/playwright/ios.md
---

# Playwright testing on iOS: real devices and simulators

TestingBot runs your Playwright tests against **Mobile Safari on physical iPhones and iPads** and on **iOS simulators**. It is the iOS Safari app, not a desktop WebKit build and not an emulated viewport.

You use a stock Playwright client and the same endpoint as for desktop browsers. Only the capabilities change, and you connect with `webkit`: `chromium.connect()` cannot drive Safari.

```bash
npm i playwright-core@1.63.0
```

```javascript
const { webkit } = require('playwright-core')

(async () => {
  const capabilities = {
    browserName: 'safari',
    platformName: 'iOS',
    deviceName: 'iPhone 16 Pro',
    realDevice: true,
    name: 'My first iPhone test',
    build: 'build-42',
    key: process.env.TB_KEY,
    secret: process.env.TB_SECRET
  }

  const browser = await webkit.connect(
    `wss://cloud.testingbot.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
  )
  try {
    const context = await browser.newContext()
    const page = await context.newPage()
    await page.goto('https://testingbot.com/')
    console.log(await page.title())
    await page.screenshot({ path: 'iphone.png', fullPage: true })
  } finally {
    await browser.close()
  }
})()
```

The example opens Safari on an iPhone 16 Pro, loads TestingBot's homepage and saves a full-page screenshot. When the device is free, the connection is up within a few seconds.

After the test, a video and the logs of the session are in the TestingBot dashboard, grouped under the `build` you set.

You can also put `deviceName`, `realDevice`, `name`, `key` and `secret` inside a `'tb:options'` object, as the other Playwright pages do. Both forms work.

To run the same test on an [iOS simulator](https://testingbot.com#simulators), leave out `realDevice` and pick a simulator.

Looking for Chrome on Android? See [Playwright on Android devices](https://testingbot.com/support/web-automate/playwright/mobile).

## Pick a device

Set `deviceName` to the device you want. To narrow the choice to an iOS version, add `browserVersion` with that version, for example `'26'`. It is optional.

Pick a real device or a simulator below to generate the capabilities. Only devices and simulators running iOS 17 or newer are listed.

  ![OS selected](https://testingbot.com/assets/environments/svg/ios-383468addf160fa18d0e431f529420739d7f7d1206175f682fead627d2e99a52.svg) iOS › ![Browser selected](https://testingbot.com/assets/environments/svg/safari-e4837bb5f9a9729fef843af4180372e975c62587808b8ab479f615f3e240e858.svg) iPhone or iPad 

Loading environments...

Please wait while we load the available browsers and platforms.

The same list is available from the API: `GET /v1/browsers/playwright?platformName=iOS` (see the [API reference](https://testingbot.com/support/api)).

## iOS simulators

Playwright also drives Mobile Safari in iOS simulators on iOS 17 or newer. Use the same capabilities without `realDevice`, and set `deviceName` to a simulator:

```javascript
const capabilities = {
  browserName: 'safari',
  platformName: 'iOS',
  deviceName: 'iPhone 17',
  browserVersion: '26',
  key: process.env.TB_KEY,
  secret: process.env.TB_SECRET
}
const browser = await webkit.connect(
  `wss://cloud.testingbot.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
)
```

The Playwright version range, the iOS 17 minimum, what works and the [limits](https://testingbot.com#limits) are the same as on real devices, with these differences:

- [Native input](https://testingbot.com#native-input) is available on real devices only. On a simulator, input is always synthesised in the page (`event.isTrusted` is `false`).
- JavaScript dialogs (`alert`, `confirm`, `prompt`) are answered through Playwright's own dialog handling rather than by tapping Safari's dialog.
- A simulator may have to boot first, which can take a minute or more. If you set a timeout on the connect call, allow a few minutes.

Simulators are a fast way to cover many iOS versions and screen sizes. Use real devices for what a simulator does not reproduce, such as real hardware performance and trusted input.

## Requirements

| Playwright client | **1.62 to 1.65** , any patch release. The client and the cloud must match on major and minor version; TestingBot loads the matching version for you. Sessions from other versions are refused. |
| --- | --- |
| iOS | **17 or newer** , on real devices and simulators. For Safari on older iOS versions, use [Appium](https://testingbot.com/support/web-automate/mobile). |
| Devices | Physical iPhones and iPads, and iOS simulators. |
| Browser | Safari, with `browserName: 'safari'` and the `webkit` client. |
| Languages | Any Playwright binding at a supported version: Node.js, Python, Java, .NET. Use the binding's `webkit` browser type to connect. |

The same connection in Python:

```python
import json, os
from urllib.parse import quote
from playwright.sync_api import sync_playwright

capabilities = {
    "browserName": "safari",
    "platformName": "iOS",
    "deviceName": "iPhone 16 Pro",
    "realDevice": True,
    "key": os.environ["TB_KEY"],
    "secret": os.environ["TB_SECRET"],
}
ws_url = "wss://cloud.testingbot.com/playwright?capabilities=" + quote(json.dumps(capabilities))

with sync_playwright() as playwright:
    browser = playwright.webkit.connect(ws_url, timeout=180000)
    try:
        page = browser.new_context().new_page()
        page.goto("https://testingbot.com/")
        print(page.title())
    finally:
        browser.close()
```

## What works

- Navigation, including cross-site, `goBack()`, `goForward()`, `reload()` and `waitForURL()`
- Locators, `click()`, `fill()`, `check()`, `selectOption()`, `setContent()`, `evaluate()` and handles
- Keyboard: Backspace, Delete, Enter (submits a form), Tab and Shift+Tab, arrow keys and select-all
- Screenshots of the viewport, the full page or an element
- `page.route()` with `fulfill`, `abort`, `continue` and `fallback`; request and response events, including subresources
- Cookies (`addCookies`, `cookies`, `clearCookies`), `setExtraHTTPHeaders`, `addInitScript` and `exposeFunction`
- `newContext({ storageState })` and `context.storageState()`, with cookies and localStorage: see [reusing a login state](https://testingbot.com/support/web-automate/playwright/reuse-login-state)
- Context options `timezoneId`, `geolocation` with `permissions: ['geolocation']`, `httpCredentials`, `userAgent`, `extraHTTPHeaders` and `offline`; `setGeolocation()`, `grantPermissions()`, `clearPermissions()` and `setOffline()`
- API requests with `context.request`
- Console and page error events, iframes and `setInputFiles()`
- JavaScript dialogs (`alert`, `confirm`, `prompt`): the real Safari dialogs are answered
- Popups: a tab the page opens arrives through `context.waitForEvent('page')`
- `page.close()` followed by `context.newPage()`
- Tracing with `context.tracing.start()` and `stop()`, without the screenshot filmstrip
- `browser.version()` returns Safari's version
- A video and logs of every session, test names and builds, [pass/fail status](https://testingbot.com#status) and [TestingBot Tunnel](https://testingbot.com#tunnel)

## Limits

Safari on iOS is not a desktop browser, and some Playwright features do not carry over:

- **One browser context at a time, and one page per context.** A second `browser.newContext()` or `context.newPage()` while the first is open is refused with a clear message. Contexts one after the other are fine, and each starts clean. Tabs that the page itself opens (popups) work.
- **Input events are synthesised** , so `event.isTrusted` is `false`, unless you turn on [native input](https://testingbot.com#native-input).
- The viewport is the device's screen. `page.setViewportSize()` and the `viewport`, `deviceScaleFactor`, `isMobile` and `hasTouch` options have no effect.
- Not available: `locale`, `ignoreHTTPSErrors: true`, downloads, the `filechooser` event (`setInputFiles()` works), `recordVideo` (TestingBot records every session itself), `page.pdf()` and CDP sessions.
- `page.waitForEvent('popup')` does not fire. Use `context.waitForEvent('page')` instead.
- A page you reach with `goBack()` or `goForward()` is reloaded, not restored from Safari's cache.
- `httpCredentials` are sent with the first request instead of after a 401 response. With an `origin` they go to that origin only; without one, to every server the page talks to.

```javascript
// Popups: wait on the context, not the page
const [popup] = await Promise.all([
  context.waitForEvent('page'),
  page.click('a[target=_blank]')
])
await popup.waitForLoadState()
```

## Native input (real devices)

By default, clicks and key presses are synthesised inside the page. That is fast and works for most tests, but the events have `event.isTrusted === false`.

On a real device, set `nativeInput: true` (at the top level of the capabilities or inside `'tb:options'`) to send real taps and key presses through the device instead. The events are then trusted (`event.isTrusted === true`).

- A tap takes about half a second.
- `keyboard.type()` and `pressSequentially()` send the whole string at once.
- `fill()` is not affected: it sets the value directly.

```javascript
const capabilities = {
  browserName: 'safari',
  platformName: 'iOS',
  deviceName: 'iPhone 16 Pro',
  realDevice: true,
  nativeInput: true,
  key: process.env.TB_KEY,
  secret: process.env.TB_SECRET
}
```

Native input is off by default. Turn it on for tests that depend on trusted events, such as some payment or anti-bot widgets.

## Testing local sites

Start [TestingBot Tunnel](https://testingbot.com/support/tunnel) to test a site that only your machine or network can reach. The session uses the tunnel the same way desktop sessions do.

**iOS cannot reach `localhost` or `127.0.0.1` through the tunnel** , on real devices or simulators. Use another hostname that points at your machine, for example one you add to your hosts file or your machine's name on the network. This restriction applies to every iOS test on TestingBot, not just Playwright.

## Test name and status

Set `name` and `build` in the capabilities, as in the first example. To mark the test as passed or failed, send the `testingbot_executor` command before you close the browser:

```javascript
await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({
  action: 'setSessionStatus',
  arguments: { passed: true, reason: 'Checkout works on iPhone' }
})}`)
```

See [marking a test as passed or failed](https://testingbot.com/support/web-automate/playwright/mark-test-status) for more.

## Troubleshooting

- **The connection times out.** This usually means the device you asked for is in use. Try again later, or ask for another device.
- **The session is refused right away.** Check the client version (`npx playwright --version`, or the `playwright-core` version in your lockfile): it must be 1.62 to 1.65. Check that the device runs iOS 17 or newer.
- **Safari is not driven, or the wrong browser starts.** Connect with `webkit.connect()` and set `browserName: 'safari'`, `platformName: 'iOS'` and `realDevice: true`.
- **A second page or context is refused.** Close the first one before you open the next; see [Limits](https://testingbot.com#limits).
- **Your local site does not load through the tunnel.** Do not use `localhost`; see [Testing local sites](https://testingbot.com#tunnel).

## Frequently asked questions

Can Playwright test Safari on a real iPhone?

Yes. On TestingBot, Playwright drives the Safari app on a physical iPhone or iPad. Connect with webkit.connect() to wss://cloud.testingbot.com/playwright and set browserName to safari, platformName to iOS, a deviceName and realDevice: true. It is the real Mobile Safari on the device, not a desktop WebKit build and not an emulated viewport.

Which Playwright and iOS versions are supported?

Playwright 1.62 to 1.65 (any patch release), in any language binding at those versions, and real devices or simulators running iOS 17 or newer. Sessions with other Playwright versions or older iOS versions are refused.

Can I use the iOS Simulator with Playwright on TestingBot?

Yes. Leave out realDevice: true and pick a simulator as deviceName, with iOS 17 or newer. The simulator runs the iOS Safari app, so the same Playwright code works on both. See [iOS simulators](https://testingbot.com#simulators) for the differences.

Why is my click not a trusted event on iOS?

By default Playwright's input on iOS is synthesised in the page, so event.isTrusted is false. On a real device, set nativeInput: true in your capabilities to send real taps and key presses through the device. See [native input](https://testingbot.com#native-input).

Can I test a site on localhost on an iPhone?

Through [TestingBot Tunnel](https://testingbot.com/support/tunnel), yes, but not with the hostnames localhost or 127.0.0.1: iOS cannot reach those through the tunnel. Use another hostname that points at your machine.

## Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new) [Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
