This methods attaches Playwright to an existing Android device. Use android.launchServer([options]) to launch a new Android server instance.
A browser websocket endpoint to connect to.
Optional options: { Optional
Optional headers?: { Additional HTTP headers to be sent with web socket connect request. Optional.
Optional slowSlows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going
on. Defaults to 0.
Optional timeout?: numberMaximum time in milliseconds to wait for the connection to be established. Defaults to 30000 (30 seconds). Pass
0 to disable timeout.
Returns the list of detected Android devices.
Optional options: { Optional
Optional host?: stringOptional host to establish ADB server connection. Default to 127.0.0.1.
Optional omitPrevents automatic playwright driver installation on attach. Assumes that the drivers have been installed already.
Optional port?: numberOptional port to establish ADB server connection. Default to 5037.
Launches Playwright Android server that clients can connect to. See the following example:
Usage
Server Side:
const { _android } = require('playwright');
(async () => {
const browserServer = await _android.launchServer({
// If you have multiple devices connected and want to use a specific one.
// deviceSerialNumber: '<deviceSerialNumber>',
});
const wsEndpoint = browserServer.wsEndpoint();
console.log(wsEndpoint);
})();
Client Side:
const { _android } = require('playwright');
(async () => {
const device = await _android.connect('<wsEndpoint>');
console.log(device.model());
console.log(device.serial());
await device.shell('am force-stop com.android.chrome');
const context = await device.launchBrowser();
const page = await context.newPage();
await page.goto('https://webkit.org/');
console.log(await page.evaluate(() => window.location.href));
await page.screenshot({ path: 'page-chrome-1.png' });
await context.close();
})();
Optional options: { Optional
Optional adbOptional host to establish ADB server connection. Default to 127.0.0.1.
Optional adbOptional port to establish ADB server connection. Default to 5037.
Optional deviceOptional device serial number to launch the browser on. If not specified, it will throw if multiple devices are connected.
Optional host?: stringHost to use for the web socket. It is optional and if it is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise. Consider hardening it with picking a specific interface.
Optional omitPrevents automatic playwright driver installation on attach. Assumes that the drivers have been installed already.
Optional port?: numberPort to use for the web socket. Defaults to 0 that picks any available port.
Optional wsPath at which to serve the Android Server. For security, this defaults to an unguessable string.
NOTE Any process or web page (including those running in Playwright) with knowledge of the wsPath can take
control of the OS user. For this reason, you should use an unguessable token when using this option.
This setting will change the default maximum time for all the methods accepting
timeout option.
Maximum time in milliseconds
Generated using TypeDoc
Playwright has experimental support for Android automation. This includes Chrome for Android and Android WebView.
Requirements
adb devicesis all you need to do.Chrome 87or newer installed on the devicechrome://flags.Known limitations
How to run
An example of the Android automation script would be: