Git Product home page Git Product logo

puppeteer-on-termux's Introduction

Puppeteer on termux

Run Puppeteer on Termux

What is Termux?

Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically - additional packages are available using the APT package manager.

screenshot

Assumptions

  • You have termux installed and have sufficient permissions
  • You have logged-in 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 alternatively using alpine distro here.

Install Prerequisites

pkg install proot-distro
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
  • Node js v12.14+
  • Yarn v1.22+

Usage

git clone https://github.com/rishabhrpg/puppeteer-on-termux.git
cd puppeteer-on-termux
yarn install
node index.js
  • If you see a message "screenshot saved" then puppeteer is successfully configured to run on termux
  • Use this repo as starting point as it has correct args included to successfully run chromium on termux
  • To view screenshot on your device you can run npx http-server and aceess the screenshot directory from a browser.

References

License

MIT

puppeteer-on-termux's People

Contributors

rishabhrpg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

puppeteer-on-termux's Issues

Error: Cannot find module 'puppeteer'

Failed to run the file due to an import error
package.json dont have puppeteer as dependency
was it require("puppeteer-core")?

Command to run:

git clone https://github.com/rishabhrpg/puppeteer-on-termux.git
cd puppeteer-on-termux
yarn install
node index.js

Error output:

Error: Cannot find module 'puppeteer'
Require stack:
- /home/puppeteer-on-termux/index.js

Code that cause error:
const puppeteer = require('puppeteer');

Running:
rerunning
Dependecies:
IMG_20220320_082116

Installing issue

Hey i do that same but not working please help me


Community forum: https://termux.com/community
Gitter chat:     https://gitter.im/termux/termux
IRC channel:     #termux on libera.chat

Working with packages:

 * Search packages:   pkg search <query>
 * Install a package: pkg install <package>
 * Upgrade packages:  pkg upgrade

Subscribing to additional repositories:

 * Root:     pkg install root-repo
 * Unstable: pkg install unstable-repo
 * X11:      pkg install x11-repo

Report issues at https://termux.com/issues

The Google Play version of the Termux app no longer
receives updates. For more information, visit:
https://wiki.termux.com/wiki/Termux_Google_Play

~ $ pkg install proot-distro
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
Testing the available mirrors:
[*] https://packages.termux.org/apt/termux-main: ok
[*] https://deb.kcubeterm.me/termux-main:
ok
[*] https://termux.mentality.rip/termux-main: ok
[*] https://grimler.se/termux-packages-24: ok
[*] https://termux.librehat.com/apt/termux-main: ok
Picking mirror: https://grimler.se/termux-packages-24
Get:1 https://grimler.se/termux-packages-24 stable InRelease [16.8 kB]
Get:2 https://packages.termux.org/apt/termux-games games InRelease [14.2 kB]
Get:3 https://packages.termux.org/apt/termux-science science InRelease [14.2 kB]
Get:4 https://grimler.se/termux-packages-24 stable/main arm Packages [278 kB]
Get:5 https://grimler.se/termux-packages-24 stable/main all Packages [22.3 kB]
Get:6 https://packages.termux.org/apt/termux-games games/stable arm Packages [7816 B]
Get:7 https://packages.termux.org/apt/termux-science science/stable arm Packages [19.2 kB]
Fetched 373 kB in 7s (55.4 kB/s)
Reading package lists... Done
Building dependency tree... Done
32 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree... Done
The following additional packages will be installed:
  libtalloc ncurses ncurses-utils proot
The following NEW packages will be installed:
  libtalloc ncurses-utils proot proot-distro
The following packages will be upgraded:
  ncurses
1 upgraded, 4 newly installed, 0 to remove and 31 not upgraded.
Need to get 707 kB of archives.
After this operation, 795 kB of additional disk space will be used.
Get:1 https://grimler.se/termux-packages-24 stable/main arm ncurses arm 6.2.20200725-6 [494 kB]
Get:2 https://grimler.se/termux-packages-24 stable/main arm libtalloc arm 2.3.3 [34.1 kB]
Get:3 https://grimler.se/termux-packages-24 stable/main arm ncurses-utils arm 6.2.20200725-6 [81.8 kB]
Get:4 https://grimler.se/termux-packages-24 stable/main arm proot arm 5.1.107-49 [77.3 kB]
Get:5 https://grimler.se/termux-packages-24 stable/main arm proot-distro all 2.8.0 [20.7 kB]
Fetched 707 kB in 4s (164 kB/s)
(Reading database ... 3711 files and directories currently installed.)
Preparing to unpack .../ncurses_6.2.20200725-6_arm.deb ...
Unpacking ncurses (6.2.20200725-6) over (6.2.20200725-4) ...
Setting up ncurses (6.2.20200725-6) ...
Selecting previously unselected package libtalloc.
(Reading database ... 3714 files and directories currently installed.)
Preparing to unpack .../libtalloc_2.3.3_arm.deb ...
Unpacking libtalloc (2.3.3) ...
Selecting previously unselected package ncurses-utils.
Preparing to unpack .../ncurses-utils_6.2.20200725-6_arm.deb ...
Unpacking ncurses-utils (6.2.20200725-6) ...
Selecting previously unselected package proot.
Preparing to unpack .../proot_5.1.107-49_arm.deb ...
Unpacking proot (5.1.107-49) ...
Selecting previously unselected package proot-distro.
Preparing to unpack .../proot-distro_2.8.0_all.deb ...
Unpacking proot-distro (2.8.0) ...
Setting up ncurses-utils (6.2.20200725-6) ...
Setting up libtalloc (2.3.3) ...
Setting up proot (5.1.107-49) ...
Setting up proot-distro (2.8.0) ...
[*] Installing Alpine Linux (edge)...
[*] Creating directory '/data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/alpine'...
[*] Creating directory '/data/data/com.termux/files/usr/var/lib/proot-distro/dlcache'...
[*] Downloading rootfs tarball...

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:-  0     0    0     0    0     0      0      0 --:-100   666  100   666    0     0    667      0 --:--:-- --:--:-- --:--:--   667
  0     0    0     0    0     0      0      0 --:-  0     0    0     0    0     0      0      0 --:-  0     0    0     0    0     0      0      0 --:-  3 2119k    3 82483    0     0  17769      0  0:0  9 2119k    9  208k    0     0  37223      0  0:0 24 2119k   24  528k    0     0  81456      0  0:0 37 2119k   37  796k    0     0   102k      0  0:0 50 2119k   50 1074k    0     0   124k      0  0:0 63 2119k   63 1352k    0     0   140k      0  0:0 78 2119k   78 1653k    0     0   155k      0  0:0 90 2119k   90 1915k    0     0   163k      0  0:0100 2119k  100 2119k    0     0   172k      0  0:00:12  0:00:12 --:--:--  293k

[*] Checking integrity, please wait...
[*] Extracting rootfs, please wait...
[*] Writing '/data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/alpine/etc/profile.d/termux-proot.sh'...
[*] Writing resolv.conf file (NS 1.1.1.1/1.0.0.1)...
[*] Writing hosts file...
[*] Registering Android-specific UIDs and GIDs...
[*] Installation finished.

Now run 'proot-distro login alpine' to log in.

localhost:~# ls
localhost:~# apk update && apk add --no-cache nmap
 && \
>   echo @edge http://nl.alpinelinux.org/alpine/ed
ge/community >> /etc/apk/repositories && \
>   echo @edge http://nl.alpinelinux.org/alpine/ed
ge/main >> /etc/apk/repositories && \
>   apk update && \
>   apk add --no-cache \
>   chromium
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/armv7/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/armv7/APKINDEX.tar.gz
v3.15.0_rc3-37-g5a5dfe777d [http://dl-cdn.alpinelinux.org/alpine/edge/main]
v3.15.0_rc3-61-ge4504c9628 [http://dl-cdn.alpinelinux.org/alpine/edge/community]
OK: 15354 distinct packages available
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/armv7/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/armv7/APKINDEX.tar.gz
(1/9) Installing libcrypto1.1 (1.1.1l-r5)
(2/9) Installing libgcc (10.3.1_git20211027-r0)
(3/9) Installing lua5.3-libs (5.3.6-r1)
(4/9) Installing libpcap (1.10.1-r0)
(5/9) Installing pcre (8.45-r1)
(6/9) Installing libssh2 (1.10.0-r2)
(7/9) Installing libssl1.1 (1.1.1l-r5)
(8/9) Installing libstdc++ (10.3.1_git20211027-r0)
(9/9) Installing nmap (7.92-r2)
Executing busybox-1.34.0-r3.trigger
OK: 20 MiB in 20 packages
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/armv7/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/armv7/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/community/armv7/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/main/armv7/APKINDEX.tar.gz
v3.15.0_rc3-37-g5a5dfe777d [http://dl-cdn.alpinelinux.org/alpine/edge/main]
v3.15.0_rc3-61-ge4504c9628 [http://dl-cdn.alpinelinux.org/alpine/edge/community]
v3.15.0_rc3-61-ge4504c9628 [http://nl.alpinelinux.org/alpine/edge/community]
v3.15.0_rc3-37-g5a5dfe777d [http://nl.alpinelinux.org/alpine/edge/main]
OK: 15354 distinct packages available
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/armv7/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/armv7/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/community/armv7/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/main/armv7/APKINDEX.tar.gz
ERROR: unable to select packages:
  chromium (no such package):
    required by: world[chromium]
localhost:~# git clone https://github.com/rishabhr
pg/puppeteer-on-termux.git
-ash: git: not found
localhost:~# cd puppeteer-on-termux
-ash: cd: can't cd to puppeteer-on-termux: No such file or directory
localhost:~# yarn install
-ash: yarn: not found
localhost:~# node index.js
-ash: node: not found
localhost:~# git clone https://github.com/rishabhr
pg/puppeteer-on-termux.git
-ash: git: not found
localhost:~# apt search git
Ability to run this command as root has been disabled permanently for safety purposes.
localhost:~#  ```

doesn't work

localhost:~/puppeteer-on-termux# node index.js
/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/common/assert.js:26
throw new Error(message);
^

Error: Unsupported platform: android
at Object.exports.assert (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/common/assert.js:26:15)
at BrowserFetcher.setPlatform (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserFetcher.js:175:25)
at new BrowserFetcher (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserFetcher.js:159:14)
at resolveExecutablePath (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.js:442:28)
at ChromeLauncher.launch (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.js:77:53)
at async screenshot (/root/puppeteer-on-termux/index.js:7:19)

Node.js v17.7.1
localhost:~/puppeteer-on-termux#`

Just want to thank you!

I just want to thank you!
Really, thank you. Worked like magic and now my motorola one macro have something to live for again!
you are a genius!

Some issue with cjs/puppeteer/common/assert.js:26

If I understand it's some problem with location path in termux and proot or version nodejs?
I'm lunch code with
"type": "module",
and
(async () => {
const browser = await puppeteer.launch({headless: true, args:['--no-sandbox']});

localhost:~/puppeteer-on-termux# node index.
js
/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/common/assert.js:26
        throw new Error(message);
              ^

Error: Unsupported platform: android
    at exports.assert (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/common/assert.js:26:15)
    at BrowserFetcher.setPlatform (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserFetcher.js:175:25)
    at new BrowserFetcher (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserFetcher.js:159:14)
    at resolveExecutablePath (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.js:442:28)
    at ChromeLauncher.launch (/root/puppeteer-on-termux/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.js:77:53)
    at async file:///root/puppeteer-on-termux/index.js:4:19

Node.js v19.6.1
localhost:~/puppeteer-on-termux# node --trac
e-warnings index.index.js
node:internal/modules/cjs/loader:1093
  throw err;
  ^

Error: Cannot find module '/root/puppeteer-on-termux/index.index.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1090:15)
    at Module._load (node:internal/modules/cjs/loader:934:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v19.6.1
localhost:~/puppeteer-on-termux# ls
README.md         package.json
index.js          screenshots
node_modules      yarn.lock
package.j19.4.0x
localhost:~/puppeteer-on-termux#

chromium package not found

This was working, but recently stopped:

apk add --no-cache chromium

fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/aarch64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/community/aarch64/APKINDEX.tar.gz
WARNING: Permanently redirected to https://nl.alpinelinux.org:443/alpine/edge/community/aarch64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/main/aarch64/APKINDEX.tar.gz
WARNING: Permanently redirected to https://nl.alpinelinux.org:443/alpine/edge/main/aarch64/APKINDEX.tar.gz
ERROR: unable to select packages:
  chromium (no such package):
    required by: world[chromium]

Has something changed?

is still work ?

running update on alpine container is doesn't work


apk update && apk add --no-cache nmap
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/aarch64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/edge/main: temporary error (try again later)
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/edge/main: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/aarch64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/edge/community: temporary error (try again later)
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/edge/community: No such file or directory
2 errors; 14 distinct packages available

``

Unsupported platform: android

Output:
/root/puppeteer-on-termux/node_modules/puppeteer/lib/cjs/puppeteer/common/assert.js:26
throw new Error(message);
^

Error: Unsupported platform: android

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.