microsoft/playwright · error · Error

More than one device found. Please specify deviceSerialNumbe

Error message

More than one device found. Please specify deviceSerialNumber

What it means

Thrown by AndroidServerLauncherImpl.launchServer when more than one device is visible and no `deviceSerialNumber` was provided. The server can bind to exactly one device (maxConnections: 1, preLaunchedAndroidDevice), so the ambiguity must be resolved by the caller.

Source

Thrown at packages/playwright-core/src/androidServerImpl.ts:48

    // 1. Pre-connect to the device
    const controller = new ProgressController();
    let devices = await controller.run(progress => playwright.android.devices(progress, {
      host: options.adbHost,
      port: options.adbPort,
      omitDriverInstall: options.omitDriverInstall,
    }));

    if (devices.length === 0)
      throw new Error('No devices found');

    if (options.deviceSerialNumber) {
      devices = devices.filter(d => d.serial === options.deviceSerialNumber);
      if (devices.length === 0)
        throw new Error(`No device with serial number '${options.deviceSerialNumber}' was found`);
    }

    if (devices.length > 1)
      throw new Error(`More than one device found. Please specify deviceSerialNumber`);

    const device = devices[0];

    const path = options.wsPath ? (options.wsPath.startsWith('/') ? options.wsPath : `/${options.wsPath}`) : `/${createGuid()}`;

    // 2. Start the server
    const server = new PlaywrightServer({ mode: 'launchServer', path, maxConnections: 1, preLaunchedAndroidDevice: device });
    const wsEndpoint = await server.listen(options.port, options.host);

    // 3. Return the BrowserServer interface
    const browserServer = new EventEmitter() as BrowserServer & EventEmitter;
    browserServer.wsEndpoint = () => wsEndpoint;
    browserServer.close = () => device.close(nullProgress);
    browserServer.kill = () => device.close(nullProgress);
    device.on('close', () => {
      server.close();
      browserServer.emit('close');
    });

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Set `options.deviceSerialNumber` to the target device's serial.
  2. Stop extra emulators/devices so only one remains.
  3. Drive selection from `adb devices` output programmatically.

Example fix

// before
await android.launchServer({});  // 2+ devices -> error

// after
const serial = process.env.ANDROID_SERIAL ?? 'emulator-5554';
await android.launchServer({ deviceSerialNumber: serial });
Defensive patterns

Strategy: validation

Validate before calling

import { execSync } from 'child_process';
function assertSingleDeviceOrSerial() {
  const out = execSync('adb devices', { encoding: 'utf8' });
  const devices = out.split('\n').filter(l => /\bdevice\b/.test(l) && !/List of devices/.test(l));
  if (devices.length > 1 && !process.env.ANDROID_SERIAL)
    throw new Error('Multiple Android devices; set ANDROID_SERIAL or --device-serial-number');
}

Type guard

function deviceSelectionIsUnambiguous(count: number, serial?: string): boolean {
  return count === 1 || (count > 1 && !!serial);
}

Try / catch

try {
  return await android.launchServer(options);
} catch (e) {
  if (/More than one device found/.test(e.message)) {
    options.deviceSerialNumber = await promptForSerial();
    return android.launchServer(options);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `android.launchServer({})` with two or more devices attached and no `deviceSerialNumber` option. The check is `if (devices.length > 1) throw`.

Common situations: Multiple emulators running; one emulator plus a physical device; CI that boots a second emulator inadvertently; team workstation with several test devices.

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/be594327baa78cbc. Report an issue: GitHub.