fix: fallback writable firefox profile
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m12s

This commit is contained in:
nocci 2025-12-31 10:44:28 +00:00
parent 488a050f00
commit e6c43c8de6

View file

@ -17,23 +17,32 @@ fi
# https://bugs.chromium.org/p/chromium/issues/detail?id=367048
rm -f /fgc/data/browser/SingletonLock 2>/dev/null || true
# Firefox profile directory (persistent if writable; fallback to cache when bind-mount is read-only).
BROWSER_DIR=/fgc/data/browser
if [ ! -w "$BROWSER_DIR" ]; then
echo "Warning: $BROWSER_DIR not writable; using fallback profile at /home/fgc/.cache/browser"
BROWSER_DIR=/home/fgc/.cache/browser
mkdir -p "$BROWSER_DIR"
chown 1000:1000 "$BROWSER_DIR" 2>/dev/null || true
fi
mkdir -p "$BROWSER_DIR"
# clean up stale firefox locks that can trigger "already running"
rm -f "$BROWSER_DIR"/parent.lock "$BROWSER_DIR"/lock "$BROWSER_DIR"/.parentlock 2>/dev/null || true
# Firefox preferences are stored in $BROWSER_DIR/pref.js and can be overridden by a file user.js
# Since this file has to be in the volume (data/browser), we can't do this in Dockerfile.
mkdir -p /fgc/data/browser
# clean up stale firefox locks that can trigger "already running"
rm -f /fgc/data/browser/parent.lock /fgc/data/browser/lock /fgc/data/browser/.parentlock 2>/dev/null || true
# fix for 'Incorrect response' after solving a captcha correctly - https://github.com/vogler/free-games-claimer/issues/261#issuecomment-1868385830
# Only write the prefs file when the volume is writable (container runs as non-root).
if [ -w /fgc/data/browser ] && { [ ! -e /fgc/data/browser/user.js ] || [ -w /fgc/data/browser/user.js ] || rm -f /fgc/data/browser/user.js 2>/dev/null; }; then
cat << 'EOT' > /fgc/data/browser/user.js
if [ -w "$BROWSER_DIR" ] && { [ ! -e "$BROWSER_DIR/user.js" ] || [ -w "$BROWSER_DIR/user.js" ] || rm -f "$BROWSER_DIR/user.js" 2>/dev/null; }; then
cat << 'EOT' > "$BROWSER_DIR/user.js"
user_pref("privacy.resistFingerprinting", true);
// user_pref("privacy.resistFingerprinting.letterboxing", true);
// user_pref("browser.contentblocking.category", "strict");
// user_pref("webgl.disabled", true);
EOT
else
echo "Warning: /fgc/data/browser not writable; skipping user.js creation."
echo "Warning: $BROWSER_DIR not writable; skipping user.js creation."
fi
export BROWSER_DIR
# TODO disable session restore message?
# Remove X server display lock, fix for `docker compose up` which reuses container which made it fail after initial run, https://github.com/vogler/free-games-claimer/issues/31