Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Termux on Android #777

Open
gsmitheidw opened this issue Oct 31, 2024 · 5 comments
Open

Support for Termux on Android #777

gsmitheidw opened this issue Oct 31, 2024 · 5 comments
Labels
blocked This issue/PR is blocked by another issue/PR (potentially in a different project)

Comments

@gsmitheidw
Copy link

I would like install mermaid-cli on Android in Termux. It's failing on puppeteer install citing "current platform is not supported"

My desire is to be able to create mmd files in vim in Termux and use them in conjunction with pandoc to create documents with embedded diagrams.

npm install @mermaid-js/mermaid-cli

> [email protected] postinstall
> node install.mjs

file:///data/data/com.termux/files/home/node_modules/puppeteer/lib/esm/puppeteer/node/install.js:43
        throw new Error('The current platform is not supported.');
              ^

Error: The current platform is not supported.
    at downloadBrowsers (file:///data/data/com.termux/files/home/node_modules/puppeteer/lib/esm/puppeteer/node/install.js:43:15)
    at file:///data/data/com.termux/files/home/node_modules/puppeteer/install.mjs:35:3

Node.js v22.8.0
npm error code 1
npm error path /data/data/com.termux/files/home/node_modules/puppeteer
npm error command failed
npm error command sh -c node install.mjs
npm error A complete log of this run can be found in: /data/data/com.termux/files/home/.npm/_logs/2024-10-31T11_07_09_706Z-debug-0.log

Test environment

Termux from the (recommended) F-Droid store

$ termux-info
Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=32447
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.1
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://mirror.twds.com.tw/termux/termux-main stable main
Updatable packages:
All packages up to date
termux-tools version:
1.44.2
Android version:
13
Kernel build information:
Linux localhost 5.10.168-android12-9-00003-g828a3b1f7462-ab10564101 #1 SMP PREEMPT Wed Jul 26 12:50:50 UTC 2023 aarch64 Android
Device manufacturer:
motorola
Device model:
moto g54 5G
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api versionCode:51

Solutions explored:

Workaround I've explored include messy workarounds using rooted devices and docker or proot distros which is quite a heavy-handed (particularly in terms of Android resources) solution to installing an otherwise small package.
I've tried installing puppeteer-core but that does not work.

Potential Solutions:

  • Provision of a prebuilt binary mmdc that includes the puppeteer functionality compiled in
  • An alternative in the code to puppeteer that will allow the npm installation to complete, perhaps using a different dependency.
@aloisklink
Copy link
Member

  • Provision of a prebuilt binary mmdc that includes the puppeteer functionality compiled in

We do have an issue for this #467, but as it's a non-trivial amount of work, I don't think it would get done anytime soon.

  • An alternative in the code to puppeteer that will allow the npm installation to complete, perhaps using a different dependency.

Unfortunately, mermaid-cli requries Puppeteer (or something similar like Playwright), since Mermaid doesn't support server-side rendering, see #750


As an alternate approach, can you install a chromium/firefox browser a different way (e.g. via apt install or apk add?

If so, you can install @mermaid-js/mermaid-cli with PUPPETEER_SKIP_DOWNLOAD=true enabled, e.g.

PUPPETEER_SKIP_DOWNLOAD=true npx @mermaid-js/mermaid-cli --help

Then, make a puppeteerConfig.json file with the executablePath key pointing to your version of chrome/firefox, e.g. like:

{
"executablePath": "/usr/bin/chromium-browser",
"args": [
"--no-sandbox"
]
}

Then, you pass it via --puppeteerConfigFile:

PUPPETEER_SKIP_DOWNLOAD=true npx @mermaid-js/mermaid-cli --puppeteerConfigFile puppeteer-config.json

There are some docs in https://pptr.dev/troubleshooting#running-puppeteer-in-docker and puppeteer/puppeteer#9460 that might help.

@aloisklink aloisklink added the blocked This issue/PR is blocked by another issue/PR (potentially in a different project) label Nov 1, 2024
@robertkirkman
Copy link

robertkirkman commented Nov 2, 2024

Hello just today I made this tutorial on the subject of Puppeteer on Android that might help

https://gist.github.com/robertkirkman/0c2f3426024069546ed9b7bb2f26cb99

@gsmitheidw
Copy link
Author

That looks like a good workaround albeit very heavy in terms of storage to install a full desktop environment just to run a small utility.

For anyone already using Termux with desktop this would be ideal.

I think the browser dependency is kinda non-negotiable, but perhaps the X desktop can be removed after getting the mmdc installed?

Hello just today I made this tutorial on the subject of Puppeteer on Android that might help

https://gist.github.com/robertkirkman/0c2f3426024069546ed9b7bb2f26cb99

@robertkirkman
Copy link

There is currently a Segmentation fault in the command firefox -headless, preventing the opening of firefox without X11 server present. I will try fix it maybe I can I'm not sure. If I can I will send the patch

@robertkirkman
Copy link

robertkirkman commented Nov 16, 2024

I am happy to announce good news that I have fixed the Segmentation fault error, and integrated the patch into a PR into the termux-packages repository, and also updated my guide to have a Headless Mode section that has a full code example for using Puppeteer on Android in Headless mode (would start working whenever the PR is accepted and Termux mirrors are updated. If the PR turns out to have bugs or other issues, and can't be accepted to termux-packages yet, then I will eventually post directions for using it as a custom downstream build of Firefox specifically for Headless Node.js Puppeteer on Android, so that the custom build could be used for that purpose without breaking Firefox for other users)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked This issue/PR is blocked by another issue/PR (potentially in a different project)
Projects
None yet
Development

No branches or pull requests

3 participants