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:Microsoft Playwright BackendAdb

From Leeroopedia
Knowledge Sources
Domains Android, ADB
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for communicating with Android devices over the Android Debug Bridge (ADB) protocol provided by the Playwright library.

Description

The `AdbBackend` class implements the `Backend` interface for discovering Android devices via ADB. It issues the `host:devices` command to enumerate connected devices, returning an array of `AdbDevice` instances. Each `AdbDevice` implements the `DeviceBackend` interface with methods for running shell commands (`runCommand`), opening TCP sockets (`open`), and managing device lifecycle (`init`, `close`). The module communicates directly with the ADB daemon over TCP sockets using the ADB wire protocol (4-byte hex length prefix).

Usage

Use BackendAdb when automating Android devices with Playwright's Android automation support, which requires an ADB server running on the specified host and port.

Code Reference

Source Location

Signature

export class AdbBackend implements Backend {
  async devices(options?: channels.AndroidDevicesOptions): Promise<DeviceBackend[]>;
}

class AdbDevice implements DeviceBackend {
  serial: string;
  status: string;
  host: string | undefined;
  port: number | undefined;
  constructor(serial: string, status: string, host?: string, port?: number);
  async init(): Promise<void>;
  async close(): Promise<void>;
  runCommand(command: string): Promise<Buffer>;
  async open(command: string): Promise<SocketBackend>;
}

Import

import { AdbBackend } from '../server/android/backendAdb';

I/O Contract

Inputs

Name Type Required Description
options.host string No ADB server hostname (defaults to localhost)
options.port number No ADB server port (defaults to 5037)
command string Yes ADB shell command or transport command to execute

Outputs

Name Type Description
devices DeviceBackend[] Array of discovered Android device backends
result Buffer Raw command output buffer
socket SocketBackend Open TCP socket to the device

Usage Examples

import { AdbBackend } from '../server/android/backendAdb';

const backend = new AdbBackend();
const devices = await backend.devices({ host: 'localhost', port: 5037 });
for (const device of devices) {
  const output = await device.runCommand('shell:getprop ro.build.version.release');
  console.log(output.toString());
}

Related Pages

Page Connections

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