Skip to content

Instantly share code, notes, and snippets.

@rishabhrpg
Last active October 7, 2024 13:00
Show Gist options
  • Save rishabhrpg/4025ff5da4f0159af1850cb358279e57 to your computer and use it in GitHub Desktop.
Save rishabhrpg/4025ff5da4f0159af1850cb358279e57 to your computer and use it in GitHub Desktop.
Run puppeteer inside termux

Run Puppeteer inside termux

Assumptions

  • You have termux installed and have sufficient permissions
  • You have loggedin as root user
  • You are okay with running Puppeteer inside a container (Alpine)

Gotchas

  • There is no build of Google Chrome available for ARM at this moment, so using chromium instead.
  • Installing chromium on Termux directly requires snap which is another big hurdle so alternively using alpine distro here.

Steps

proot-distro install alpine
proot-distro login alpine
apk update && apk add --no-cache nmap && \
  echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
  echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \
  apk update && \
  apk add --no-cache \
  chromium
git clone https://github.com/rishabhrpg/puppeteer-on-termux.git
cd puppeteer-on-termux
yarn
node index.js
  • If you see a message "screenshot saved" then puppeteer is successfully configured to run on termux
  • Use repo puppeteer-on-termux as starting point as it has correct args included to sucesfully run chromium on termux

This tutoraial has been moved here [https://github.com/rishabhrpg/puppeteer-on-termux]

@rishabhrpg
Copy link
Author

You can try if there is a chromium binary available it should work.

@lumos675
Copy link

Is there anyway to use termux and pupeteer in a standalone project without need to download termux on the device and within the project itself

@rishabhrpg
Copy link
Author

Is there anyway to use termux and pupeteer in a standalone project without need to download termux on the device and within the project itself

Termux APP is open source Termux App
You can try to package termux and puppeteer

@lumos675
Copy link

Is there anyway to use termux and pupeteer in a standalone project without need to download termux on the device and within the project itself

Termux APP is open source Termux App
You can try to package termux and puppeteer

I was thinking if i can include these 2 packages inside an android project without root the possibilities could be endless when it comes to web automation..but i feel like i still need alot to learn but i am working on it

@fahadali32
Copy link

My device name is xioami arm71 i installed alpine but can't install chromium how to install it? Your command is not working

@SnwMds
Copy link

SnwMds commented Sep 11, 2021

@mazyaf, @fahadali32

There is no armv7 build of Chromium in the current @edge repository of Alphine. You need to switch to a older repo release:

echo @3.11 http://nl.alpinelinux.org/alpine/v3.11/community >> /etc/apk/repositories
apk add [email protected]
Install log

localhost:~# uname -m
armv7l
localhost:~# echo @3.11 http://nl.alpinelinux.org/alpine/v3.11/community >> /etc/apk/repositories
localhost:~# apk add [email protected]
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/armv7/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/armv7/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/v3.11/community/armv7/APKINDEX.tar.gz
(1/114) Installing eudev-libs (3.2.10-r0)
(2/114) Installing libgcc (10.3.1_git20210424-r2)
(3/114) Installing expat (2.4.1-r0)
(4/114) Installing brotli-libs (1.0.9-r5)
(5/114) Installing libbz2 (1.0.8-r1)
(6/114) Installing libpng (1.6.37-r1)
(7/114) Installing freetype (2.10.4-r1)
(8/114) Installing libuuid (2.37-r0)
(9/114) Installing fontconfig (2.13.1-r4)
(10/114) Installing libfontenc (1.1.4-r0)
(11/114) Installing mkfontscale (1.2.1-r1)
(12/114) Installing ttf-opensans (1.10-r1)
Executing ttf-opensans-1.10-r1.post-install
(13/114) Installing libogg (1.3.5-r0)
(14/114) Installing libstdc++ (10.3.1_git20210424-r2)
(15/114) Installing flac (1.3.3-r0)
(16/114) Installing libxau (1.0.9-r0)
(17/114) Installing libmd (1.0.3-r0)
(18/114) Installing libbsd (0.11.3-r0)
(19/114) Installing libxdmcp (1.1.3-r0)
(20/114) Installing libxcb (1.14-r2)
(21/114) Installing libx11 (1.7.2-r0)
(22/114) Installing libxcomposite (0.4.5-r0)
(23/114) Installing libxfixes (6.0.0-r0)
(24/114) Installing libxrender (0.9.10-r3)
(25/114) Installing libxcursor (1.2.0-r0)
(26/114) Installing libxdamage (1.1.5-r1)
(27/114) Installing libxext (1.3.4-r0)
(28/114) Installing libxi (1.7.10-r0)
(29/114) Installing libxrandr (1.5.2-r1)
(30/114) Installing libxscrnsaver (1.2.3-r0)
(31/114) Installing libxtst (1.2.3-r3)
(32/114) Installing alsa-lib (1.2.5-r2)
(33/114) Installing libffi (3.3-r2)
(34/114) Installing libintl (0.21-r0)
(35/114) Installing libblkid (2.37-r0)
(36/114) Installing libmount (2.37-r0)
(37/114) Installing pcre (8.44-r0)
(38/114) Installing glib (2.68.3-r0)
(39/114) Installing atk (2.36.0-r0)
(40/114) Installing dbus-libs (1.12.20-r2)
(41/114) Installing at-spi2-core (2.40.0-r0)
(42/114) Installing at-spi2-atk (2.38.0-r0)
(43/114) Installing sdl2 (2.0.14-r1)
(44/114) Installing fribidi (1.0.10-r0)
(45/114) Installing graphite2 (1.3.14-r0)
(46/114) Installing harfbuzz (2.8.1-r0)
(47/114) Installing libass (0.15.1-r0)
(48/114) Installing libdav1d (0.9.0-r0)
(49/114) Installing gmp (6.2.1-r0)
(50/114) Installing nettle (3.7.2-r0)
(51/114) Installing p11-kit (0.23.22-r0)
(52/114) Installing libtasn1 (4.17.0-r0)
(53/114) Installing libunistring (0.9.10-r1)
(54/114) Installing gnutls (3.7.1-r0)
(55/114) Installing ncurses-terminfo-base (6.2_p20210612-r0)
(56/114) Installing ncurses-libs (6.2_p20210612-r0)
(57/114) Installing lame (3.100-r0)
(58/114) Installing opus (1.3.1-r1)
(59/114) Installing libgomp (10.3.1_git20210424-r2)
(60/114) Installing soxr (0.1.3-r2)
(61/114) Installing libsrt (1.4.2-r0)
(62/114) Installing libssh (0.9.6-r0)
(63/114) Installing libtheora (1.1.1-r16)
(64/114) Installing libjpeg-turbo (2.1.0-r0)
(65/114) Installing v4l-utils-libs (1.20.0-r0)
(66/114) Installing libdrm (2.4.106-r0)
(67/114) Installing wayland-libs-client (1.19.0-r0)
(68/114) Installing libva (2.11.0-r0)
(69/114) Installing libvdpau (1.4-r0)
(70/114) Installing vidstab (1.1.0-r1)
(71/114) Installing libvorbis (1.3.7-r0)
(72/114) Installing libvpx (1.10.0-r0)
(73/114) Installing vulkan-loader (1.2.170-r1)
(74/114) Installing libwebp (1.2.0-r2)
(75/114) Installing x264-libs (20210211-r0)
(76/114) Installing x265-libs (3.4-r0)
(77/114) Installing xvidcore (1.3.7-r1)
(78/114) Installing ffmpeg-libs (4.4-r1)
(79/114) Installing pixman (0.40.0-r2)
(80/114) Installing cairo (1.16.0-r3)
(81/114) Installing avahi-libs (0.8-r5)
(82/114) Installing cups-libs (2.3.3-r2)
(83/114) Installing libevent (2.1.12-r2)
(84/114) Installing mesa (21.1.2-r0)
(85/114) Installing wayland-libs-server (1.19.0-r0)
(86/114) Installing mesa-gbm (21.1.2-r0)
(87/114) Installing pkgconf (1.7.4-r0)
(88/114) Installing xz-libs (5.2.5-r0)
(89/114) Installing libxml2 (2.9.12-r1)
(90/114) Installing shared-mime-info (2.1-r0)
(91/114) Installing hicolor-icon-theme (0.17-r1)
(92/114) Installing zstd-libs (1.4.9-r1)
(93/114) Installing tiff (4.2.0-r1)
(94/114) Installing gdk-pixbuf (2.42.6-r0)
(95/114) Installing gtk-update-icon-cache (2.24.33-r0)
(96/114) Installing libxinerama (1.1.4-r1)
(97/114) Installing cairo-gobject (1.16.0-r3)
(98/114) Installing libepoxy (1.5.8-r0)
(99/114) Installing libxft (2.3.3-r0)
(100/114) Installing pango (1.48.5-r0)
(101/114) Installing wayland-libs-cursor (1.19.0-r0)
(102/114) Installing wayland-libs-egl (1.19.0-r0)
(103/114) Installing xkeyboard-config (2.33-r0)
(104/114) Installing libxkbcommon (1.2.1-r0)
(105/114) Installing gtk+3.0 (3.24.28-r0)
Executing gtk+3.0-3.24.28-r0.post-install
(106/114) Installing nspr (4.31-r0)
(107/114) Installing sqlite-libs (3.35.5-r0)
(108/114) Installing nss (3.66-r0)
(109/114) Installing [email protected] (2019.12.01-r0)
(110/114) Installing snappy (1.1.8-r2)
(111/114) Installing libgpg-error (1.42-r0)
(112/114) Installing libgcrypt (1.9.4-r0)
(113/114) Installing libxslt (1.1.34-r1)
(114/114) Installing [email protected] (81.0.4044.113-r0)
Executing busybox-1.33.1-r3.trigger
Executing fontconfig-2.13.1-r4.trigger
Executing mkfontscale-1.2.1-r1.trigger
Executing glib-2.68.3-r0.trigger
Executing shared-mime-info-2.1-r0.trigger
Executing gdk-pixbuf-2.42.6-r0.trigger
Executing gtk-update-icon-cache-2.24.33-r0.trigger
OK: 237 MiB in 128 packages
localhost:~# chromium-browser --version
Chromium 81.0.4044.113

Since we are installing from a older repo release, we will get an outdated version of Chromium, sadly.

Also, you may need to install a patched version of proot due to this issue, otherwise you will get Segmentation fault when attempting to call chromium-browser,

@md-fahad-ali32
Copy link

Thanks i will try this

@mauro199304
Copy link

Error: Failed to launch the browser process! spawn /root/puppeteer-on-termux/node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome ENOENT
I have this error when executing the test script that comes in the repository.

@iamstarcode
Copy link

@mauro199304 I experienced the same problem, just wondering if you founf a solityion to this error ENOENT

@agreeed
Copy link

agreeed commented Sep 19, 2024

kill yourself nigger

@DewandaArya
Copy link

kill yourself nigger

the fuck?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment