CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-puppeteer

A high-level API to control headless Chrome over the DevTools Protocol

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

device-emulation.mddocs/

Device Emulation

Mobile device emulation, viewport management, and browser environment simulation for responsive testing.

Capabilities

Viewport Management

Control browser viewport dimensions and characteristics.

/**
 * Set viewport size and properties
 * @param viewport - Viewport configuration or null to disable
 */
setViewport(viewport: Viewport | null): Promise<void>;

/**
 * Get current viewport
 * @returns Current viewport or null
 */
viewport(): Viewport | null;

interface Viewport {
  /** Viewport width in pixels */
  width: number;
  /** Viewport height in pixels */
  height: number;
  /** Device scale factor */
  deviceScaleFactor?: number;
  /** Whether to emulate mobile device */
  isMobile?: boolean;
  /** Whether device has touch support */
  hasTouch?: boolean;
  /** Whether device is in landscape mode */
  isLandscape?: boolean;
}

Usage Examples:

// Set mobile viewport
await page.setViewport({
  width: 375,
  height: 667,
  deviceScaleFactor: 2,
  isMobile: true,
  hasTouch: true
});

// Set desktop viewport
await page.setViewport({
  width: 1920,
  height: 1080,
  deviceScaleFactor: 1
});

// Get current viewport
const viewport = page.viewport();
console.log(`Viewport: ${viewport?.width}x${viewport?.height}`);

Device Emulation

Emulate specific devices with predefined configurations.

/**
 * Emulate specific device
 * @param device - Device configuration
 */
emulate(device: Device): Promise<void>;

interface Device {
  /** Device name */
  name: string;
  /** User agent string */
  userAgent: string;
  /** Viewport configuration */
  viewport: Viewport;
}

/**
 * Predefined device configurations
 */
const KnownDevices: Record<string, Device>;

Usage Examples:

import { KnownDevices } from "puppeteer";

// Emulate iPhone
await page.emulate(KnownDevices["iPhone 13"]);

// Emulate iPad
await page.emulate(KnownDevices["iPad Pro"]);

// Custom device
await page.emulate({
  name: "Custom Mobile",
  userAgent: "Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36",
  viewport: {
    width: 360,
    height: 640,
    deviceScaleFactor: 3,
    isMobile: true,
    hasTouch: true
  }
});

Media Emulation

Emulate media types and features for CSS media queries.

/**
 * Emulate CSS media type
 * @param type - Media type or null to disable
 */
emulateMediaType(type?: "screen" | "print" | null): Promise<void>;

/**
 * Emulate CSS media features
 * @param features - Array of media features or null to disable
 */
emulateMediaFeatures(features?: MediaFeature[] | null): Promise<void>;

interface MediaFeature {
  /** Media feature name */
  name: string;
  /** Media feature value */
  value: string;
}

Usage Examples:

// Emulate print media
await page.emulateMediaType("print");

// Emulate dark mode
await page.emulateMediaFeatures([
  { name: "prefers-color-scheme", value: "dark" }
]);

// Emulate reduced motion
await page.emulateMediaFeatures([
  { name: "prefers-reduced-motion", value: "reduce" }
]);

// Multiple features
await page.emulateMediaFeatures([
  { name: "prefers-color-scheme", value: "dark" },
  { name: "prefers-reduced-motion", value: "reduce" },
  { name: "pointer", value: "coarse" }
]);

Geographic Emulation

Emulate geolocation and timezone.

/**
 * Set geolocation
 * @param options - Geolocation coordinates
 */
setGeolocation(options: GeolocationOptions): Promise<void>;

/**
 * Emulate timezone
 * @param timezoneId - Timezone identifier or null for default
 */
emulateTimezone(timezoneId?: string | null): Promise<void>;

interface GeolocationOptions {
  /** Latitude */
  latitude: number;
  /** Longitude */
  longitude: number;
  /** Accuracy in meters */
  accuracy?: number;
}

Usage Examples:

// Set location to New York
await page.setGeolocation({
  latitude: 40.7128,
  longitude: -74.0060,
  accuracy: 10
});

// Set timezone to Tokyo
await page.emulateTimezone("Asia/Tokyo");

// Set timezone to London
await page.emulateTimezone("Europe/London");

Performance Emulation

Emulate CPU throttling and network conditions.

/**
 * Emulate CPU throttling
 * @param factor - Throttling factor (1 = no throttling, 4 = 4x slower)
 */
emulateCPUThrottling(factor: number | null): Promise<void>;

/**
 * Emulate vision deficiency
 * @param type - Type of vision deficiency or null to disable
 */
emulateVisionDeficiency(
  type?: "achromatopsia" | "blurredVision" | "deuteranopia" | "protanopia" | "tritanopia" | null
): Promise<void>;

Usage Examples:

// Throttle CPU to 4x slower
await page.emulateCPUThrottling(4);

// Emulate color blindness
await page.emulateVisionDeficiency("deuteranopia");

// Emulate blurred vision
await page.emulateVisionDeficiency("blurredVision");

// Disable emulation
await page.emulateCPUThrottling(null);
await page.emulateVisionDeficiency(null);

Install with Tessl CLI

npx tessl i tessl/npm-puppeteer

docs

browser-management.md

device-emulation.md

element-handling.md

index.md

input-interaction.md

locators-waiting.md

media-generation.md

network-control.md

page-interaction.md

performance-debugging.md

tile.json