66BASE=" ${EDGE_INSTALL_BASE:- https:// cdn.edgepython.com/ cli} "
77INSTALL_DIR=" ${EDGE_INSTALL_DIR:- $HOME / .local/ bin} "
88
9+ # Bundle a pinned chrome-headless-shell in ~/.cache/edge (same as Puppeteer approach); Chromium isn't in AL2/AL2023/RHEL repos and ID_LIKE distro detection is unreliable.
10+ CHROME_DIR=" ${EDGE_CHROME_DIR:- $HOME / .cache/ edge} "
11+ CHROME_BUILD=" ${EDGE_CHROME_BUILD:- 131.0.6778.85} "
12+
913case " $( uname -s) " in
1014 Linux) os=" unknown-linux-musl" ;;
1115 Darwin) os=" apple-darwin" ;;
@@ -25,58 +29,48 @@ case "$target" in
2529 * ) echo " no prebuilt for $target yet; build from source with 'cargo install --path cli'" >&2 ; exit 1 ;;
2630esac
2731
28- # Pick sudo only when not root and sudo exists; respects rootless containers.
29- SUDO=" "
30- if [ " $( id -u) " -ne 0 ] && command -v sudo > /dev/null 2>&1 ; then
31- SUDO=" sudo"
32- fi
32+ # Map our target to the chrome-for-testing platform folder name.
33+ case " $target " in
34+ x86_64-unknown-linux-musl) chrome_platform=" linux64" ;;
35+ aarch64-unknown-linux-musl) chrome_platform=" " ;; # no headless-shell build for linux-arm64
36+ x86_64-apple-darwin) chrome_platform=" mac-x64" ;;
37+ aarch64-apple-darwin) chrome_platform=" mac-arm64" ;;
38+ esac
39+
40+ CHROME_BIN=" $CHROME_DIR /chrome-headless-shell-${chrome_platform} /chrome-headless-shell"
3341
34- # True if any Chrome/Chromium-flavored binary the engine accepts is already on PATH .
42+ # True if a Chrome/Chromium-flavored binary the engine accepts is already reachable .
3543have_browser () {
44+ [ -n " ${EDGE_CHROME_PATH:- } " ] && [ -x " ${EDGE_CHROME_PATH} " ] && return 0
45+ [ -n " $chrome_platform " ] && [ -x " $CHROME_BIN " ] && return 0
3646 command -v chromium > /dev/null 2>&1 \
3747 || command -v chromium-browser > /dev/null 2>&1 \
3848 || command -v google-chrome > /dev/null 2>&1 \
3949 || command -v microsoft-edge > /dev/null 2>&1
4050}
4151
42- # Install Chromium using the host 's native package manager. Reads /etc/os-release on Linux .
52+ # Download a pinned chrome-headless-shell zip from Google 's chrome-for-testing CDN .
4353install_browser () {
44- echo " no Chromium-flavored browser found; installing..."
45-
46- case " $( uname -s) " in
47- Darwin)
48- if command -v brew > /dev/null 2>&1 ; then
49- brew install --cask chromium
50- return
51- fi
52- echo " Homebrew not found; install Chrome/Chromium manually or set EDGE_CHROME_PATH" >&2
53- exit 1
54- ;;
55- Linux)
56- local id=" " id_like=" "
57- if [ -r /etc/os-release ]; then
58- # shellcheck disable=SC1091
59- . /etc/os-release
60- id=" ${ID:- } "
61- id_like=" ${ID_LIKE:- } "
62- fi
63- case " ${id} ${id_like} " in
64- * " debian " * |* " ubuntu " * )
65- $SUDO apt-get update && $SUDO apt-get install -y chromium ;;
66- * " fedora " * |* " rhel " * |* " centos " * )
67- $SUDO dnf install -y chromium ;;
68- * " arch " * )
69- $SUDO pacman -Sy --noconfirm chromium ;;
70- * " opensuse " * |* " suse " * )
71- $SUDO zypper install -y chromium ;;
72- * " alpine " * )
73- $SUDO apk add --no-cache chromium ;;
74- * )
75- echo " unsupported distro (${id:- unknown} ); install Chrome/Chromium manually or set EDGE_CHROME_PATH" >&2
76- exit 1 ;;
77- esac
78- ;;
79- esac
54+ if [ -z " $chrome_platform " ]; then
55+ echo " no chrome-headless-shell build for $target ; install Chrome/Chromium manually and set EDGE_CHROME_PATH" >&2
56+ exit 1
57+ fi
58+
59+ if ! command -v unzip > /dev/null 2>&1 ; then
60+ echo " unzip is required to extract chrome-headless-shell; install it (apt/dnf/yum/pacman/apk/brew install unzip) and re-run" >&2
61+ exit 1
62+ fi
63+
64+ echo " no Chromium-flavored browser found; downloading chrome-headless-shell ${CHROME_BUILD} (${chrome_platform} )..."
65+ local url=" https://storage.googleapis.com/chrome-for-testing-public/${CHROME_BUILD} /${chrome_platform} /chrome-headless-shell-${chrome_platform} .zip"
66+ local tmp
67+ tmp=" $( mktemp " ${TMPDIR:-/ tmp} /edge-chs.XXXXXX.zip" ) "
68+ mkdir -p " $CHROME_DIR "
69+ curl -fsSL " $url " -o " $tmp "
70+ unzip -q -o " $tmp " -d " $CHROME_DIR "
71+ rm -f " $tmp "
72+ chmod +x " $CHROME_BIN "
73+ echo " installed: $CHROME_BIN "
8074}
8175
8276mkdir -p " $INSTALL_DIR "
@@ -87,14 +81,21 @@ if ! have_browser; then
8781 install_browser
8882fi
8983
84+ case " $( basename " ${SHELL:- bash} " ) " in
85+ bash) rc=" $HOME /.bashrc" ;;
86+ zsh) rc=" $HOME /.zshrc" ;;
87+ * ) rc=" " ;;
88+ esac
89+
90+ # Persist EDGE_CHROME_PATH so the CLI finds the bundled headless shell across shells.
91+ if [ -n " $rc " ] && [ -n " $chrome_platform " ] && [ -x " $CHROME_BIN " ] && ! grep -qs ' EDGE_CHROME_PATH=' " $rc " 2> /dev/null; then
92+ printf ' \nexport EDGE_CHROME_PATH="%s"\n' " $CHROME_BIN " >> " $rc "
93+ echo " added EDGE_CHROME_PATH to $rc "
94+ fi
95+
9096case " :$PATH :" in
9197 * " :$INSTALL_DIR :" * ) ;;
9298 * )
93- case " $( basename " ${SHELL:- bash} " ) " in
94- bash) rc=" $HOME /.bashrc" ;;
95- zsh) rc=" $HOME /.zshrc" ;;
96- * ) rc=" " ;;
97- esac
9899 if [ -n " $rc " ] && ! grep -qs " $INSTALL_DIR " " $rc " 2> /dev/null; then
99100 printf ' \nexport PATH="%s:$PATH"\n' " $INSTALL_DIR " >> " $rc "
100101 echo " added $INSTALL_DIR to PATH in $rc ; run 'source $rc ' or open a new shell"
0 commit comments