Implementation:Microsoft Playwright Server Android
| Knowledge Sources | |
|---|---|
| Domains | Mobile Automation, Android ADB |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for server-side Android device automation via ADB provided by the Playwright library.
Description
This module provides the server-side implementation for Android device automation. It defines the `Backend` and `DeviceBackend` interfaces for abstracting ADB communication, and the `AndroidDevice` class (extending `SdkObject`) which manages device interaction including shell commands, file operations, WebView discovery, browser launching via Chromium, and input events. The module uses ADB protocol for device communication, creates temporary artifacts folders, and leverages the Chromium browser engine to drive web content within Android WebViews. Socket-based communication is handled through the `SocketBackend` interface.
Usage
Use this module on the server side when implementing Android device automation features, such as discovering connected devices, running shell commands, managing WebViews, or launching Chromium-based browser contexts on Android devices.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/android/android.ts
Signature
export interface Backend {
devices(options: channels.AndroidDevicesOptions): Promise<DeviceBackend[]>;
}
export interface DeviceBackend {
serial: string;
status: string;
close(): Promise<void>;
init(): Promise<void>;
runCommand(command: string): Promise<Buffer>;
open(command: string): Promise<SocketBackend>;
}
export class AndroidDevice extends SdkObject {
readonly _android: Android;
readonly model: string;
readonly serial: string;
constructor(android: Android, backend: DeviceBackend, model: string, options: channels.AndroidDevicesOptions);
async shell(command: string): Promise<Buffer>;
async open(command: string): Promise<SocketBackend>;
async launchBrowser(pkg?: string, options?: types.BrowserContextOptions): Promise<BrowserContext>;
async close(): Promise<void>;
}
Import
import { AndroidDevice, Backend, DeviceBackend } from '../server/android/android';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| android | Android | Yes | Parent Android manager instance |
| backend | DeviceBackend | Yes | ADB backend for device communication |
| model | string | Yes | Device model name |
| options | channels.AndroidDevicesOptions | Yes | Device discovery options including port |
| command | string | Yes | Shell command or socket command to execute |
| pkg | string | No | Android browser package to launch (defaults to Chrome) |
Outputs
| Name | Type | Description |
|---|---|---|
| devices | DeviceBackend[] | List of discovered device backends |
| shell result | Buffer | Output of shell command execution |
| BrowserContext | BrowserContext | Chromium browser context launched on the device |
| SocketBackend | SocketBackend | Socket connection for bidirectional communication |
Usage Examples
// Server-side usage
const android = new Android(sdkObject, adbBackend);
const devices = await android.devices(progress, { port: 5037 });
const device = devices[0];
// Run a shell command
const output = await device.shell('pm list packages');
// Launch browser on device
const context = await device.launchBrowser('com.android.chrome', {
viewport: { width: 412, height: 732 }
});
await device.close();