From 49be840fb11bf3a56199ff0e47109564fd40ffa7 Mon Sep 17 00:00:00 2001 From: RJ Sampson Date: Mon, 4 Mar 2024 10:30:13 -0500 Subject: [PATCH] chore(chromium): Add launcher for passing startup env vars Allows passing startup vars to Chromium via CHROMIUM_USER_FLAGS Signed-off-by: RJ Sampson --- chromium.yaml | 4 ++-- chromium/chromium-launcher.sh | 32 ++++++++++++++++++++++++++++++++ chromium/test-chromedriver.py | 3 --- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100755 chromium/chromium-launcher.sh diff --git a/chromium.yaml b/chromium.yaml index 1f490500aae..106e86afc76 100644 --- a/chromium.yaml +++ b/chromium.yaml @@ -180,9 +180,9 @@ pipeline: mv *.pak ${{targets.destdir}}/usr/lib/${{package.name}} mv locales ${{targets.destdir}}/usr/lib/${{package.name}} # links - ln -sf /usr/lib/${{package.name}}/chrome ${{targets.destdir}}/usr/bin/chromium-browser + ln -sf /usr/lib/${{package.name}}/chrome ${{targets.destdir}}/usr/bin/chromium ln -sf /usr/lib/${{package.name}}/chromedriver ${{targets.destdir}}/usr/bin/chromedriver - ln -sf chromium-browser ${{targets.destdir}}/usr/bin/chromium + ln -sf chromium-launcher.sh ${{targets.destdir}}/usr/bin/chromium-browser mkdir -p ${{targets.destdir}}/etc/chromium - uses: strip diff --git a/chromium/chromium-launcher.sh b/chromium/chromium-launcher.sh new file mode 100755 index 00000000000..e794f8aaf9f --- /dev/null +++ b/chromium/chromium-launcher.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +for f in /etc/chromium/*.conf; do + [ -f "$f" ] && . "$f" +done + +# Append CHROMIUM_USER_FLAGS (from env) on top of system +# default CHROMIUM_FLAGS (from /etc/chromium/chromium.conf). +CHROMIUM_FLAGS="$CHROMIUM_FLAGS ${CHROMIUM_USER_FLAGS:+"$CHROMIUM_USER_FLAGS"}" + +# Let the wrapped binary know that it has been run through the wrapper +export CHROME_WRAPPER="$(readlink -f "$0")" + +PROGDIR=${CHROME_WRAPPER%/*} + +case ":$PATH:" in +*:$PROGDIR:*) + # $PATH already contains $PROGDIR + ;; +*) + # Append $PROGDIR to $PATH + export PATH="$PATH:$PROGDIR" + ;; +esac + +if [ $(id -u) -eq 0 ] && [ $(stat -c %u -L ${XDG_CONFIG_HOME:-${HOME}}) -eq 0 ]; then + # Running as root with HOME owned by root. + # Pass --user-data-dir to work around upstream failsafe. + CHROMIUM_FLAGS="--user-data-dir=${XDG_CONFIG_HOME:-"$HOME"/.config}/chromium $CHROMIUM_FLAGS" +fi + +exec "$PROGDIR/chromium" ${CHROMIUM_FLAGS} "$@" diff --git a/chromium/test-chromedriver.py b/chromium/test-chromedriver.py index 3ddcca73fa9..a1d23435fe7 100755 --- a/chromium/test-chromedriver.py +++ b/chromium/test-chromedriver.py @@ -1,9 +1,6 @@ from selenium import webdriver options = webdriver.ChromeOptions() -options.add_argument('--disable-gpu') -options.add_argument('--no-sandbox') -options.add_argument('--headless') driver = webdriver.Chrome( options=options