Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Getgauge Taiko Device Descriptors

From Leeroopedia
Knowledge Sources
Domains Browser Automation, Device Emulation
Last Updated 2026-02-12 03:00 GMT

Overview

Device Descriptors is a catalog of 50+ mobile and tablet device profiles that Taiko uses to emulate specific hardware environments in the browser via the Chrome DevTools Protocol.

Description

The devices.js module (located at lib/data/devices.js) defines a single DEVICES constant object containing named device descriptors for a wide range of mobile phones and tablets. Each descriptor provides a userAgent string and a viewport object with properties for width, height, deviceScaleFactor, isMobile, hasTouch, and isLandscape. The module exports this object as module.exports.default = DEVICES.

This file was originally imported from the Puppeteer project (https://github.com/GoogleChrome/puppeteer) with minor modifications by Taiko maintainers. It is licensed under Apache License 2.0 with the Thoughtworks copyright header. The catalog includes both portrait and landscape variants for most devices, effectively doubling the entry count. Device families covered include: BlackBerry (PlayBook, Z30), Samsung Galaxy (Note II, Note 3, S III, S5), Apple iPad (standard, Mini, Pro), Apple iPhone (4 through 11 Pro, SE, X), Amazon Kindle Fire HDX, LG Optimus L70, Microsoft Lumia (550, 950), Google Nexus (4, 5, 5X, 6, 6P, 7, 10), Nokia (Lumia 520, N9), and Google Pixel (2, 2 XL).

The descriptors provide the exact parameters needed for CDP methods Emulation.setDeviceMetricsOverride and Network.setUserAgentOverride, enabling Taiko to faithfully simulate how a website renders and behaves on a specific physical device.

Usage

This module is consumed in two places:

  • lib/handlers/emulationHandler.js -- The emulation handler imports devices.default and uses it when emulateDevice(deviceModel) is called. It looks up the given device name in the DEVICES object to retrieve the userAgent and viewport settings, then applies them to the browser session via CDP.
  • bin/taiko.js -- The Taiko CLI REPL imports the devices catalog to provide device name autocompletion and validation when users invoke device emulation interactively.

Typical usage is triggered when a test script calls emulateDevice('iPhone X') or similar, which resolves the device name against this catalog.

Code Reference

Source Location

Signature

const DEVICES = {
  "Blackberry PlayBook": { userAgent: "...", viewport: { ... } },
  "Blackberry PlayBook landscape": { userAgent: "...", viewport: { ... } },
  // ... 50+ device entries with portrait and landscape variants
  "Pixel 2 XL landscape": { userAgent: "...", viewport: { ... } },
};

module.exports.default = DEVICES;

Import

const devices = require("../data/devices").default;

I/O Contract

Inputs

Name Type Required Description
(none) N/A N/A This is a static data module. Consumers access entries by device name lookup, e.g., devices["iPhone X"].

Outputs

Name Type Description
module.exports.default Object<string, DeviceDescriptor> A flat object where each key is a device name string and each value is a device descriptor object.

DeviceDescriptor structure:

Property Type Description
userAgent string The full User-Agent string that identifies the device's browser to web servers.
viewport object An object defining the device's screen characteristics (see below).

Viewport properties:

Property Type Description
width number Viewport width in CSS pixels (e.g., 375 for iPhone 6).
height number Viewport height in CSS pixels (e.g., 667 for iPhone 6).
deviceScaleFactor number Device pixel ratio (e.g., 2 for Retina, 3 for iPhone X, 3.5 for Nexus 6).
isMobile boolean Always true for all entries; indicates mobile rendering mode.
hasTouch boolean Always true for all entries; enables touch event simulation.
isLandscape boolean false for portrait entries, true for landscape entries (width and height are swapped).

Usage Examples

Emulating an iPhone X

const { openBrowser, emulateDevice, goto, closeBrowser } = require('taiko');

(async () => {
  await openBrowser();
  await emulateDevice('iPhone X');
  // Browser now uses: width=375, height=812, scale=3, mobile UA
  await goto('https://example.com');
  await closeBrowser();
})();

Emulating a Tablet in Landscape

const { openBrowser, emulateDevice, goto, closeBrowser } = require('taiko');

(async () => {
  await openBrowser();
  await emulateDevice('iPad Pro landscape');
  // Browser now uses: width=1366, height=1024, scale=2, mobile UA
  await goto('https://example.com');
  await closeBrowser();
})();

Directly Accessing the Devices Catalog

const devices = require("./lib/data/devices").default;

// List all available device names
console.log(Object.keys(devices));
// => ["Blackberry PlayBook", "Blackberry PlayBook landscape", "BlackBerry Z30", ...]

// Inspect a specific device
const pixel2 = devices["Pixel 2"];
// => {
//   userAgent: "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 ...) Chrome/69.0.3452.0 Mobile Safari/537.36",
//   viewport: { width: 411, height: 731, deviceScaleFactor: 2.625, isMobile: true, hasTouch: true, isLandscape: false }
// }

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment