-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor start_chrome_headless (#22257)
- Loading branch information
Showing
2 changed files
with
40 additions
and
48 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |