diff --git a/docker/chromium/start_chrome_headless.sh b/docker/chromium/start_chrome_headless.sh index f2e8746bf5873..cfd59b83547c5 100644 --- a/docker/chromium/start_chrome_headless.sh +++ b/docker/chromium/start_chrome_headless.sh @@ -1,31 +1,27 @@ #!/bin/bash -ignore_certificate_errors="--ignore-certificate-errors" +# Default values (consider injecting them from the outside as arguments) +ignore_certificate_errors=true +chrome_binary="/opt/google/chrome/google-chrome" +remote_debugging_port=9222 +max_attempts=3 +user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36" while [[ "$#" -gt 0 ]]; do - case "${1}" in - --validate-certificates) ignore_certificate_errors="" - shift;; - *) # unknown option. - shift - echo "Unknown option was received: $1" - ;; - esac + case "${1}" in + --validate-certificates) ignore_certificate_errors=false ;; + --chrome-binary) chrome_binary="${2}"; shift ;; + --user-agent) user_agent="${2}"; shift ;; + --port) remote_debugging_port="${2}"; shift ;; + *) echo "Unknown option: ${1}" ;; + esac + shift done -echo "ignore_certificate_errors: ${ignore_certificate_errors}" +local cert_errors_option="" +if [ "$ignore_certificate_errors" = true ]; then + cert_errors_option="--ignore-certificate-errors" +fi -for value in {1..3} -do - echo "Trying to start chrome, attempt $value" - ps -aux | grep "chrome" | grep "9222" > /dev/null 2>&1 - if [[ "$?" == "0" ]]; then - echo "Chrome is running" - exit 0 - else - echo "Chrome is not running" - service dbus restart - nohup /opt/google/chrome/google-chrome --headless --disable-gpu --no-sandbox --hide-scrollbars --disable_infobars --start-maximized --start-fullscreen "${ignore_certificate_errors}" --disable-dev-shm-usage --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36" --remote-debugging-port=9222 & disown - fi - sleep 3 -done +echo "Starting Chrome..." +nohup "$chrome_binary" --headless --disable-gpu --no-sandbox --hide-scrollbars --disable-infobars --start-maximized --start-fullscreen $cert_errors_option --disable-dev-shm-usage --user-agent="\"$user_agent\"" --remote-debugging-port="$remote_debugging_port" & disown diff --git a/docker/py3-native/chromium/start_chrome_headless.sh b/docker/py3-native/chromium/start_chrome_headless.sh index f2e8746bf5873..cfd59b83547c5 100755 --- a/docker/py3-native/chromium/start_chrome_headless.sh +++ b/docker/py3-native/chromium/start_chrome_headless.sh @@ -1,31 +1,27 @@ #!/bin/bash -ignore_certificate_errors="--ignore-certificate-errors" +# Default values (consider injecting them from the outside as arguments) +ignore_certificate_errors=true +chrome_binary="/opt/google/chrome/google-chrome" +remote_debugging_port=9222 +max_attempts=3 +user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36" while [[ "$#" -gt 0 ]]; do - case "${1}" in - --validate-certificates) ignore_certificate_errors="" - shift;; - *) # unknown option. - shift - echo "Unknown option was received: $1" - ;; - esac + case "${1}" in + --validate-certificates) ignore_certificate_errors=false ;; + --chrome-binary) chrome_binary="${2}"; shift ;; + --user-agent) user_agent="${2}"; shift ;; + --port) remote_debugging_port="${2}"; shift ;; + *) echo "Unknown option: ${1}" ;; + esac + shift done -echo "ignore_certificate_errors: ${ignore_certificate_errors}" +local cert_errors_option="" +if [ "$ignore_certificate_errors" = true ]; then + cert_errors_option="--ignore-certificate-errors" +fi -for value in {1..3} -do - echo "Trying to start chrome, attempt $value" - ps -aux | grep "chrome" | grep "9222" > /dev/null 2>&1 - if [[ "$?" == "0" ]]; then - echo "Chrome is running" - exit 0 - else - echo "Chrome is not running" - service dbus restart - nohup /opt/google/chrome/google-chrome --headless --disable-gpu --no-sandbox --hide-scrollbars --disable_infobars --start-maximized --start-fullscreen "${ignore_certificate_errors}" --disable-dev-shm-usage --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36" --remote-debugging-port=9222 & disown - fi - sleep 3 -done +echo "Starting Chrome..." +nohup "$chrome_binary" --headless --disable-gpu --no-sandbox --hide-scrollbars --disable-infobars --start-maximized --start-fullscreen $cert_errors_option --disable-dev-shm-usage --user-agent="\"$user_agent\"" --remote-debugging-port="$remote_debugging_port" & disown