October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Emulate Touch Input for Mobile Website Screenshots in Playwright

A viewport alone does not enable touch in Playwright. Learn how to configure a touch-capable context, trigger taps, and capture the right screenshot dimensions.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture a mobile-style screenshot with touch support in Playwright, create a browser context with hasTouch: true, then navigate and take the screenshot. Set isMobile: true as well when you need mobile meta-viewport behavior; a narrow viewport by itself does not enable touch. The examples below use Chromium because Playwright documents isMobile as unsupported in Firefox.

Set up a mobile-like browser context

The quickest route is to start with a Playwright device descriptor, which can provide a user agent, screen and viewport dimensions, and touch capability. The descriptor names available depend on your installed Playwright version, so confirm the name in that version’s device registry. The official Playwright emulation guide shows how to spread a descriptor into browser.newContext().

As an Amazon Associate I earn from qualifying purchases.

import { chromium, devices } from 'playwright';

const browser = await chromium.launch();
const context = await browser.newContext({
  ...devices['iPhone 13'],
  // Overrides after the spread take precedence over descriptor values.
  hasTouch: true,
  isMobile: true,
});
const page = await context.newPage();

await page.goto('https://example.com');
await page.screenshot({ path: 'mobile.png', fullPage: true, scale: 'css' });

await browser.close();

Here, Chromium is launched explicitly. If the chosen descriptor already sets hasTouch and isMobile, the explicit values still make the intended configuration clear; placing them after the spread lets them override the preset.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a descriptor or set options yourself

Use a device descriptor when you want a coordinated set of device parameters. If you need a custom viewport or want configuration independent of a named preset, set the context values deliberately:

#1 Best Overall
Sale
Samsung Galaxy A17 5G Smart Phone 128GB US 1 Yr Manufacturer Warranty Black
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.
import { chromium } from 'playwright';

const browser = await chromium.launch();
const context = await browser.newContext({
  viewport: { width: 390, height: 844 },
  deviceScaleFactor: 1,
  hasTouch: true,
  isMobile: true,
});
const page = await context.newPage();

await page.goto('https://example.com');
await page.screenshot({ path: 'mobile.png', scale: 'css' });
await browser.close();

The example’s dimensions and scale factor are configuration choices, not a claim that they represent every phone. Choose values that match the viewport and output you want to test. A viewport sets the page’s visible dimensions; it does not, on its own, make the context touch-capable.

Understand hasTouch and isMobile

  • hasTouch says whether the context supports touch events. Its documented default is false. Set it to true to use touch APIs such as page.touchscreen.tap().
  • isMobile enables mobile-oriented behavior, including taking the page’s meta viewport tag into account, and enables touch events. The Playwright documentation says it is not supported in Firefox.
  • A device descriptor may set both options, along with other device parameters. Inspect or override those values when a test depends on a particular configuration.

These settings emulate a browser context; they do not turn a desktop browser into a physical phone. For a capture from connected or emulated Android hardware, use Playwright’s separate Android device API.

Rank #2
Tracfone Motorola Moto G 2025, 64GB, Saphire Blue (Locked to
  • Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Tracfone plan required, activating is easy, just 3 steps.
  • DISPLAY: Immersive viewing on a 6.7-inch super-bright 120Hz display with powerful stereo speakers and Bass Boost for cinematic entertainment.
  • CAMERA SYSTEM: Advanced 50MP Quad Pixel camera captures sharp, detailed photos and videos in any lighting condition
  • PERFORMANCE: Lightning-fast 5G connectivity paired with a powerful processor and RAM Boost for smooth multitasking.
  • BATTERY LIFE: Long-lasting 5000mAh battery with TurboPower charging technology delivers hours of power in minutes.

Trigger a touch before taking the screenshot

Once the context has touch enabled, use the touchscreen API for a coordinate tap. Coordinates are CSS pixels relative to the main-frame viewport. A single tap dispatches touchstart and touchend; the API throws if the context was not initialized with hasTouch: true. See the Touchscreen API documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.touchscreen.tap(120, 240);
await page.screenshot({ path: 'after-tap.png', scale: 'css' });

For interaction with a known element, a locator tap can be more robust than hard-coded coordinates. Playwright’s tap actions perform actionability checks and scroll the element into view before using the touchscreen; they also require touch support. See the Page API for the available tap action.

Rank #3
Sale
Samsung Galaxy A17 5G Smart Phone 128GB, US 1 Yr Manufacturer Warranty Blue
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.

When gesture logic needs legacy touch events

If the code under test needs a gesture such as a swipe, pan, or pinch, Playwright’s legacy touch-events guide demonstrates manually dispatching touch events. This is event simulation, not trusted hardware input: an event sent with locator.dispatchEvent() does not set Event.isTrusted. If the application checks that property, account for the check in the test. Coordinate fields such as clientX and clientY may be needed, and more fields can be necessary for complex interactions.

Prefer the touchscreen or locator tap APIs for ordinary taps. Manually dispatched events are useful when the test specifically needs to exercise event handling, but should not be treated as equivalent to a physical gesture.

Rank #4
Sale
Samsung Galaxy S26 Ultra, Unlocked Android Smartphone, 512GB, Black
  • PRIVACY DISPLAY: Automatically hide your screen from those beside you. The built-in privacy display can be preset¹ to turn on when receiving notifications, typing passwords, or using specific apps
  • TYPE IT IN. TRANSFORM IT FAST: Enhance any shot in seconds on your smartphone by using Photo Assist² with Galaxy AI.³ Add objects, restore details, or apply new styles by simply typing or tapping
  • NIGHTS, CAPTURED CLEARLY: From gigs to city lights, record and capture moments after dark with clarity using Nightography so your photos and videos stay crisp and clear on your Samsung Galaxy
  • MAKE IT. EDIT IT. SHARE IT: Turn everyday moments into something personal with creative tools built right into your mobile phone, whether it’s a special contact photo, custom wallpaper, an invitation or more⁴
  • HELP THAT KEEPS UP: Stay in the moment while Now Nudge with Galaxy AI helps you respond faster and stay organized with smart suggestions⁵ that appear exactly when you need them on your phone

Choose screenshot area and pixel scale

By default, Playwright’s screenshot scale is device. That produces one output pixel per device pixel, so a high device scale factor can make the image two times as wide and tall—or larger—than the CSS viewport. With scale: 'css', output pixels correspond one-to-one with CSS pixels. For reproducible visual baselines, select the scale explicitly. The Page API reference documents these screenshot options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Capture choice Use it when What it produces
Default viewport capture You need the currently visible page area. A screenshot of the viewport.
fullPage: true You need the whole scrollable document. A screenshot extending beyond the visible viewport.
scale: 'css' You want output dimensions tied to CSS pixels, useful for stable comparisons. One image pixel per CSS pixel.
scale: 'device' You want output at device-pixel scale. One image pixel per device pixel; dimensions may be larger on high-DPI settings.

For example, capture only the visible viewport with CSS-pixel output using await page.screenshot({ path: 'mobile-viewport.png', scale: 'css' });. To capture the full document at that same scale, use await page.screenshot({ path: 'mobile-full-page.png', fullPage: true, scale: 'css' });.

Best Value
Tracfone Moto g Play 2024 Prepaid Phone with a 1-Yr Plan Included
  • Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Activating is easy, just 3 steps.
  • ACTIVATION Promotion: Includes 1500 min, 1500 texts & 1500 MB Data + add more as you need it
  • CAMERA SYSTEM: 50MP Quad Pixel camera. Capture sharper, more vibrant photos day or night with 4x the light sensitivity.
  • PERFORMANCE: Blazing-fast Qualcomm performance. Get the speed you need for great entertainment with a Snapdragon 680 processor and 4GB of RAM.
  • 64GB built-in storage. Get plenty of room for photos, movies, songs, and apps. Made for US
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

  • touchscreen.tap() throws: the context was not created with touch enabled. Set hasTouch: true in browser.newContext(), or use a descriptor that enables touch.
  • The page looks narrow but behaves like a desktop page: viewport dimensions alone do not enable touch. Add hasTouch: true; if the page’s mobile meta viewport behavior matters, set isMobile: true too.
  • isMobile does not work as expected: Playwright documents this option as unsupported in Firefox. Use a supported engine such as Chromium for this configuration, or adjust the test expectations for the engine being exercised.
  • The screenshot is larger than expected: the default scale is device. Use scale: 'css' when you want one output pixel per CSS pixel.
  • A dispatched gesture fails an application trust check: manually dispatched legacy events are not trusted events. The documented dispatch behavior does not set isTrusted; test that application behavior accordingly rather than assuming a synthetic event is hardware input.
  • The device preset is missing: preset names are tied to the installed Playwright version. Check the device registry for that version or configure the context options directly.

Or skip the browser setup

For a screenshot returned from one request, ScreenshotNeo accepts a URL and returns an image or PDF. Its service removes known cookie-consent banners, newsletter popups, and chat widgets before capture, with each cleanup step configurable. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing status. ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents.

For example, save a WebP screenshot of a URL with cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo API documentation for request options and authentication. Free includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for ScreenshotNeo’s free plan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right capture target

Use context emulation when you need a repeatable browser setup with a chosen viewport and touch behavior. Use Playwright’s Android-device API when the target is Android hardware rather than an emulated desktop-browser context. In either case, keep the distinction clear: a touch-enabled viewport supports touch interactions, but it does not establish physical-device fidelity across every platform or browser.

Frequently Asked Questions

Does setting a mobile viewport enable Playwright touch events?

No. Configure touch support in the browser context with hasTouch: true or use a descriptor that supplies it.

Are manually dispatched touch events equivalent to a real tap?

No. Dispatched legacy events are synthetic and do not set Event.isTrusted; use Playwright’s touchscreen API for a tap.

Quick Recap

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.