Playwright now runs on real iPhones and iPads

Your Playwright tests can now run in Safari on real iPhones and iPads (iOS 17+) and on iOS 18+ simulators. Same client, webkit.connect(), one capability change.

By

Since last week you can point your Playwright tests at Safari on a real iPhone or iPad in our device cloud. Simulators work as well. You keep the Playwright client you already have, call webkit.connect() instead of chromium.connect(), and ask for an iPhone in the capabilities.

This has been one of the most requested features since we added Playwright. Playwright's own answer to mobile Safari is emulation: devices['iPhone 15'] gives a desktop browser the screen size, user agent and touch support of an iPhone. The WebKit it downloads is a build for macOS, Linux and Windows. Both are useful, and neither is the Safari your visitors use on their phones. Fixed headers that jump when the address bar collapses, inputs that zoom the page when focused, a checkout button hidden behind the on-screen keyboard: you only see these in Mobile Safari.

A first test

Install Playwright 1.62 or newer (up to 1.65, more on that below) and run this:

npm i playwright-core@1.63.0
const { webkit } = require('playwright-core')

;(async () => {
  const capabilities = {
    browserName: 'safari',
    platformName: 'iOS',
    deviceName: 'iPhone.*',
    browserVersion: '>=17',
    realDevice: true,
    name: 'Homepage on iPhone',
    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()
  }
})()

deviceName is a regular expression, so 'iPhone.*' means "any free iPhone". That is usually what you want in CI: you don't wait for one particular phone to become available. Keep browserVersion: '>=17' next to it. Some of our older iPhones still run iOS 14 to 16, which Playwright can't drive, and the version filter keeps the wildcard away from them. A plain major version such as '26' works too if you want one iOS release.

When we ran this example while writing this post, the connection was up after 4 seconds, on an iPhone with Safari 27. Need a specific model? Use its name instead, for example 'iPhone 17 Pro', or 'iPad.*' for any iPad. The device picker on the Playwright on iOS docs page lists every device you can choose.

Afterwards the session is in your dashboard like any other test: a video of the screen, the logs, and the name and build from the capabilities.

The same thing in Python:

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

capabilities = {
    "browserName": "safari",
    "platformName": "iOS",
    "deviceName": "iPhone.*",
    "browserVersion": ">=17",
    "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()

Java and .NET work the same way: use the binding's webkit browser type and connect to the same URL.

Simulators

Remove realDevice: true and the same code runs in Safari on an iOS simulator:

const capabilities = {
  browserName: 'safari',
  platformName: 'iOS',
  deviceName: 'iPhone.*',
  browserVersion: '>=18',
  key: process.env.TB_KEY,
  secret: process.env.TB_SECRET
}

Simulators need iOS 18 or newer, hence '>=18' here. On iOS 17 simulators Safari was too unreliable under Playwright in our tests, so we turn those sessions away up front. A simulator sometimes has to boot first. Our test run connected after 15 seconds, but give the connect call a few minutes before it times out.

Two things only work on real devices. One is real hardware performance. The other is trusted input, which we'll get to in a moment. For covering a wide range of iOS versions and screen sizes, simulators are the cheaper and faster option.

What carries over from desktop, and what doesn't

Most of a typical test suite runs unchanged. Locators, click(), fill(), selectOption(), keyboard input, navigation, iframes and file uploads all work. So do screenshots of the viewport, the full page or one element. page.route() works for mocking and blocking requests, and so does storageState to reuse a logged-in session. Geolocation, timezone and offline mode can be set on the context. Tracing works too, minus the screenshot filmstrip.

Some things are different because Safari on a phone isn't a desktop browser:

  • You get one browser context at a time, with one page in it. You can open contexts one after another, and tabs the page opens itself (popups) work. Wait for those with context.waitForEvent('page'), because page.waitForEvent('popup') doesn't fire on iOS.
  • The viewport is the phone's screen. setViewportSize() and the viewport option do nothing.
  • Downloads, page.pdf(), recordVideo and CDP sessions aren't available. We record a video of every session anyway.

The docs have the full list.

Real taps for payment forms and bot checks

By default, Playwright's clicks and key presses are generated inside the page. That's quick, but the browser marks those events with isTrusted: false, and some payment fields and anti-bot widgets ignore them. On a real device you can set nativeInput: true. We then send actual taps and key presses through the iPhone, and the page sees trusted events.

const capabilities = {
  browserName: 'safari',
  platformName: 'iOS',
  deviceName: 'iPhone.*',
  browserVersion: '>=17',
  realDevice: true,
  nativeInput: true,
  key: process.env.TB_KEY,
  secret: process.env.TB_SECRET
}

A native tap takes about half a second, so we'd keep this to the tests that need it and leave it off for the rest of the suite.

Why only Playwright 1.62 to 1.65?

A Playwright server only accepts clients of its own minor version. So on the device side we run the playwright-core version that matches yours, and 1.62 is the first release whose WebKit support works with stock Safari. We add newer versions after we've tested them on the device fleet. Until then, a session from a newer client is refused straight away. You don't wait for a device only to get an error.

Real devices need iOS 17 or newer. For Safari on older iPhones, Appium still covers you.

Testing a staging or local site

TestingBot Tunnel works the same as with desktop browsers, with one catch. iOS won't reach localhost or 127.0.0.1 through the tunnel, so give your machine another hostname, for example in your hosts file, and use that in page.goto().

Common questions

Can Playwright test Safari on a real iPhone?

On TestingBot, yes. Connect with webkit.connect() to wss://cloud.testingbot.com/playwright. Set browserName: 'safari', platformName: 'iOS' and realDevice: true, plus a deviceName such as 'iPhone.*'. The test runs in the Safari app on a physical iPhone with iOS 17 or newer.

Do I need a Mac?

No. The phones, simulators and Safari are on our side. Your tests run wherever they run now, on Linux, Windows or macOS, locally or in CI.

And Android?

Chrome on real Android devices has been supported for a while: see Playwright on Android devices.

The Playwright on iOS documentation has the device picker, every capability and a troubleshooting section. If something in your suite doesn't behave on iOS the way it does on desktop, tell us. That kind of report is how the list of what works got this long.

Ready to start testing?

Start a free trial