Skip to content

Support for Termux on Android #777

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

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

Support for Termux on Android #777

gsmitheidw opened this issue Oct 31, 2024 · 8 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)

@corvusdeinanis
Copy link

@robertkirkman Sorry to bother you, but any updates?

@robertkirkman
Copy link

Yes, the last two updates are:

  • on February 6th, I uploaded a new patch into my PR for the firefox Termux package that I managed to write in such a way that the Segmentation fault in the firefox -headless command is fixed without seeming to break any other functionality
  • on February 26th, I was given push permission for the github.com/termux/termux-packages repository. That means that I now have the ability to merge my own PR if I want to.

It would probably not be polite for me to immediately merge my own PR with no notice, so I have given notice now and I will merge the PR in 24 hours if no problems are found with it. After that, pkg install x11-repo && pkg install firefox in normal F-Droid Termux should give you a Firefox that can be used with my "Headless Node.js Puppeteer on Android" gist example code without crashing, so that it will become possible to integrate with existing Puppeteer projects by adjusting them to match the Firefox settings shown in my puppeteer_search_headless.js example.

@robertkirkman
Copy link

OK, we can now try mermaid-cli on Termux!

Directions

  1. Install F-Droid Termux from https://f-droid.org/en/packages/com.termux/

  2. Open the app, then update the default packages by using pkg upgrade

  3. Install the dependencies of mermaid-cli

pkg install x11-repo # required for downloading the firefox package - the X11 server itself is no longer required
pkg install nodejs firefox
npm install puppeteer-core
  1. Verify that the version of the firefox package is at least 134.0.2-1
apt-cache policy firefox

Note

If the firefox package is only version 134.0.2 or older, then your Termux mirror is outdated, and you should select the primary mirror, packages.termux.dev, which has already received the patched firefox package.

  1. Use the termux-change-repo command, then use the arrow buttons and Enter to select:
  • "Choose a single mirror to use"
  • "packages.termux.dev"
  1. Use pkg upgrade again
  2. Verify that apt-cache policy firefox shows at least 134.0.2-1
  1. Create the appropriate puppeteer-config.json to direct puppeteer-core to use the Termux version of Firefox
cat > puppeteer-config.json << EOF
{
  "product": "firefox",
  "browser": "firefox",
  "executablePath": "/data/data/com.termux/files/usr/bin/firefox",
  "headless": true
}
EOF
  1. Download a .mmd file that is compatible with mermaid-cli
curl -O https://raw.githubusercontent.com/mermaid-js/mermaid-cli/7b19bf7f230b95fde1ba1a4bbda78bc96e696773/test-positive/mindmap.mmd
  1. Launch mermaid-cli with the correct environment variable and arguments
PUPPETEER_SKIP_DOWNLOAD=true npx @mermaid-js/mermaid-cli --puppeteerConfigFile puppeteer-config.json -i mindmap.mmd -o mindmap.svg
  1. Open the resulting .svg file and choose an image viewer app that is compatible with .svg
termux-open mindmap.svg

Note

If termux-open does not work for you, then you can export the .svg file from Termux using these commands, then open it manually using your normal web browser app

termux-setup-storage
cp mindmap.svg /storage/emulated/0/Documents/

Expected Result

Image

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

4 participants