Skip to content

Instantly share code, notes, and snippets.

@Zaczero
Last active May 3, 2024 13:44
Show Gist options
  • Save Zaczero/f4eb6d201e18510609df3c9a29f73556 to your computer and use it in GitHub Desktop.
Save Zaczero/f4eb6d201e18510609df3c9a29f73556 to your computer and use it in GitHub Desktop.
Nix Playwright Firefox Fix Script
#!/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