{"record":{"id":"be594327baa78cbc","repo":"microsoft/playwright","slug":"more-than-one-device-found-please-specify-devices","errorCode":null,"errorMessage":"More than one device found. Please specify deviceSerialNumber","messagePattern":"More than one device found\\. Please specify deviceSerialNumber","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/androidServerImpl.ts","lineNumber":48,"sourceCode":"    // 1. Pre-connect to the device\n    const controller = new ProgressController();\n    let devices = await controller.run(progress => playwright.android.devices(progress, {\n      host: options.adbHost,\n      port: options.adbPort,\n      omitDriverInstall: options.omitDriverInstall,\n    }));\n\n    if (devices.length === 0)\n      throw new Error('No devices found');\n\n    if (options.deviceSerialNumber) {\n      devices = devices.filter(d => d.serial === options.deviceSerialNumber);\n      if (devices.length === 0)\n        throw new Error(`No device with serial number '${options.deviceSerialNumber}' was found`);\n    }\n\n    if (devices.length > 1)\n      throw new Error(`More than one device found. Please specify deviceSerialNumber`);\n\n    const device = devices[0];\n\n    const path = options.wsPath ? (options.wsPath.startsWith('/') ? options.wsPath : `/${options.wsPath}`) : `/${createGuid()}`;\n\n    // 2. Start the server\n    const server = new PlaywrightServer({ mode: 'launchServer', path, maxConnections: 1, preLaunchedAndroidDevice: device });\n    const wsEndpoint = await server.listen(options.port, options.host);\n\n    // 3. Return the BrowserServer interface\n    const browserServer = new EventEmitter() as BrowserServer & EventEmitter;\n    browserServer.wsEndpoint = () => wsEndpoint;\n    browserServer.close = () => device.close(nullProgress);\n    browserServer.kill = () => device.close(nullProgress);\n    device.on('close', () => {\n      server.close();\n      browserServer.emit('close');\n    });","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/androidServerImpl.ts#L30-L66","documentation":"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.","triggerScenarios":"Calling `android.launchServer({})` with two or more devices attached and no `deviceSerialNumber` option. The check is `if (devices.length > 1) throw`.","commonSituations":"Multiple emulators running; one emulator plus a physical device; CI that boots a second emulator inadvertently; team workstation with several test devices.","solutions":["Set `options.deviceSerialNumber` to the target device's serial.","Stop extra emulators/devices so only one remains.","Drive selection from `adb devices` output programmatically."],"exampleFix":"// before\nawait android.launchServer({});  // 2+ devices -> error\n\n// after\nconst serial = process.env.ANDROID_SERIAL ?? 'emulator-5554';\nawait android.launchServer({ deviceSerialNumber: serial });","handlingStrategy":"validation","validationCode":"import { execSync } from 'child_process';\nfunction assertSingleDeviceOrSerial() {\n  const out = execSync('adb devices', { encoding: 'utf8' });\n  const devices = out.split('\\n').filter(l => /\\bdevice\\b/.test(l) && !/List of devices/.test(l));\n  if (devices.length > 1 && !process.env.ANDROID_SERIAL)\n    throw new Error('Multiple Android devices; set ANDROID_SERIAL or --device-serial-number');\n}","typeGuard":"function deviceSelectionIsUnambiguous(count: number, serial?: string): boolean {\n  return count === 1 || (count > 1 && !!serial);\n}","tryCatchPattern":"try {\n  return await android.launchServer(options);\n} catch (e) {\n  if (/More than one device found/.test(e.message)) {\n    options.deviceSerialNumber = await promptForSerial();\n    return android.launchServer(options);\n  }\n  throw e;\n}","preventionTips":["Always pass deviceSerialNumber (or ANDROID_SERIAL) in multi-device setups.","Stop unused emulators before launch.","Script device selection against `adb devices` output."],"tags":["android","adb","launch-server","validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}