Tutorial: How to Run Playwright on Termux (Android)
Running Playwright on Termux requires a specific manual patch, as the official package does not natively recognize "android" as a supported platform.
 Prerequisites
  * Termux installed on your Android device.
  * Node.js installed (pkg install nodejs).
 Step 1:
Project Initialization
Create a new directory for your scraper and initialize a blank Node.js project.
In my example, i'll be installing this from a project folder that already has my custom webscraper I want to use.
If you want to do the same, ignore the mkdir steps and cd into the folder with your own custom scraper.
  mkdir my-scraper-project
  cd my-scraper-project
  npm init -y
 Step 2:
Install Dependencies
Install the required packages.
We pin these to version 1.58.2 to ensure consistency.
   npm install playwright@1.58.2
   npm install playwright-extra@4.3.6
   npm install puppeteer-extra-plugin-stealth@2.11.2
   npm install dotenv@17.4.1
   npm install express@5.2.1
 Step 3:
The Manual Platform Patch
By default, Playwright will block execution on Android.
You MUST manually edit the registry file to allow it.
If you skip this step, Playwright won't be able to run chromium in Termux
  1. Open the registry index file in your terminal editor:
nano ./node_modules/playwright-core/lib/server/registry/index.js
 Search for this line (use Ctrl + W in nano to search):
if (process.platform === "linux")
 Change that line to include the android platform check:
if (process.platform === "linux" || process.platform === "android")
To be clear, there is a space before and after the "||"
Save and exit (Press Ctrl + O, Enter, then Ctrl + X).
Step 4: Verification
Test that the configuration is working by running a small script to initialize the browser engine.
node -e "const { chromium } = require('playwright'); console.log('Chromium loaded successfully');"
This should be one line
 If you see "Chromium loaded successfully", your environment is ready to use for scraping.
**Disclaimer and Configuration Guide** :
⚠️ Final Disclaimer:
Browser Configuration
When running Playwright on Termux, you **cannot** use the default "downloaded" Chromium browser because it is not compiled for the Android/ARM architecture.
The Special Configuration:
You must point Playwright to the system-installed Chromium binary. In your scraper.js (or whichever script launches the browser), you must update your chromium.launch block as follows:
```javascript
const browser = await chromium.launch({
headless: true,
// THIS LINE IS CRITICAL:
executablePath: '/data/data/com.termux/files/usr/bin/chromium-browser',
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-gpu'
]
});
```
Why this is required:
1. **executablePath**: Tells Playwright to use the Chromium browser installed via pkg install chromium (the native Termux version) instead of the incompatible one Playwright usually downloads.
2. **--no-sandbox**: The Termux/Android permissions model prevents the standard Chromium sandbox from functioning. This flag is **mandatory** to prevent immediate crashes.
3. **--disable-dev-shm-usage**: Termux has limited shared memory (/dev/shm). This flag forces the browser to use a different memory management strategy, preventing "out of memory" or buffer errors.
[!NOTE]
Ensure you have installed the browser in Termux first by running:
pkg install chromium