What This Example Does
- Creates an Android instance with Playwright sandbox enabled
- Enables Chrome command-line flags required by Playwright
- Connects Playwright to the remote Android device
- Launches Chrome and navigates to the Playwright GitHub repository
- Interacts with page elements and takes a screenshot
- Cleans up the instance
Prerequisites
Set API Key
Install Dependencies
Running the Example
screenshot.png.
Complete Example Code
How It Works
Sandbox Feature
Thesandbox.playwrightAndroid.enabled option tells Limrun to set up a Playwright-compatible endpoint inside the Android instance. This enables direct CDP connections with minimal latency.
Chrome Flags
Playwright requires specific Chrome flags to be enabled. The example uses aConfiguration asset to set the required flag:
Connection URL
The sandbox provides a WebSocket URL that Playwright connects to:Chrome Initialization
Before automation, Chrome needs to complete first-run initialization. The example launches Chrome, waits briefly, then force-stops it:Browser Automation
Once Chrome is ready, use standard Playwright APIs:device.launchBrowser()- Start Chromebrowser.newPage()- Create a new tabpage.goto()- Navigate to URLpage.locator()- Find elementspage.screenshot()- Capture screenshots
Alternative: Local ADB Tunnel
You can also connect Playwright locally via ADB tunnel, but this is slower due to chatty CDP traffic:Performance Benefits
- Low Latency: CDP communication stays within the instance
- Fast Execution: No round-trips for every CDP command
- Scalable: Run many tests in parallel without network bottlenecks
Use Cases
- Automated web testing on Android Chrome
- WebView debugging and automation
- Cross-browser testing workflows
- Performance testing with real Chrome on Android
Next Steps
Android Instances
Learn about Android instance management
Tunneling
Learn about TCP tunneling and ADB connections