Last active
May 3, 2024 13:44
-
-
Save Zaczero/f4eb6d201e18510609df3c9a29f73556 to your computer and use it in GitHub Desktop.
Nix Playwright Firefox Fix Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This requires that you have the firefox-bin package installed. | |
# Then run `playwright install firefox` and execute this script to fix binaries. | |
# !Important: Ensure the playwright firefox and nix firefox versions match exactly. | |
set -euo pipefail | |
firefox_wrapper=$(which firefox) | |
firefox_lib=$(dirname "$firefox_wrapper") | |
firefox_lib=$(dirname "$firefox_lib")/lib | |
# /lib/firefox-bin-118.0.1/firefox (resolve first folder in lib) | |
firefox_lib=$(ls -d "$firefox_lib"/firefox-bin-* | head -n 1) | |
echo "firefox_lib: $firefox_lib" | |
for folder in ./browsers/firefox-*/firefox; do | |
echo "playwright_dir: $folder" | |
# Copy wrapper configuration from firefox-bin | |
folder_wrapper="$folder/firefox" | |
sed '$d' "$firefox_wrapper" > "$folder_wrapper" | |
echo "exec -a \"\$0\" \"$folder_wrapper-bin\" \"\$@\"" >> "$folder_wrapper" | |
chmod +x "$folder_wrapper" | |
find "$folder" -type f -executable | while read -r i_abs; do | |
i_rel=$(realpath --relative-to="$folder" "$i_abs") | |
# Skip the wrapper | |
if [ "$i_rel" = "firefox" ]; then continue; fi | |
firefix_lib_i="$firefox_lib/$i_rel" | |
echo "* $i_rel: $firefix_lib_i" | |
interpreter=$(patchelf --print-interpreter "$firefix_lib_i" 2>/dev/null || true) | |
if [ -n "$interpreter" ]; then | |
echo "[OK] interpreterr" | |
patchelf --set-interpreter "$interpreter" "$i_abs" | |
fi | |
rpath=$(patchelf --print-rpath "$firefix_lib_i") | |
echo "[OK] rpath" | |
patchelf --set-rpath "$rpath" "$i_abs" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment