Skip to content

Commit

Permalink
aisingapore#216 - add fix for new headless Chrome versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kensoh committed Apr 6, 2021
1 parent dc4c4a4 commit 98a9a28
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/end_processes.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if not "%php_process_id%"=="" (
)

:repeat_kill_chrome
for /f "tokens=* usebackq" %%p in (`wmic process where "caption like '%%chrome.exe%%' and commandline like '%%tagui_user_profile --remote-debugging-port=9222%%'" get processid 2^>nul ^| cut -d" " -f 1 ^| sort -nur ^| head -n 1`) do set chrome_process_id=%%p
for /f "tokens=* usebackq" %%p in (`wmic process where "caption like '%%chrome.exe%%' and commandline like '%%tagui_user_profile_ --remote-debugging-port=9222%%'" get processid 2^>nul ^| cut -d" " -f 1 ^| sort -nur ^| head -n 1`) do set chrome_process_id=%%p
if not "%chrome_process_id%"=="" (
taskkill /PID %chrome_process_id% /T /F > nul 2>&1
goto repeat_kill_chrome
Expand Down Expand Up @@ -47,4 +47,4 @@ for /f "tokens=* usebackq" %%p in (`wmic process where "executablepath like '%%\
if not "%tagui_process_id%"=="" (
taskkill /PID %tagui_process_id% /T /F > nul 2>&1
goto repeat_kill_tagui
)
)
8 changes: 4 additions & 4 deletions src/tagui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ chrome_command="google-chrome"

if [ -z "$1" ]
then
echo "tagui v5.16: use following options and this syntax to run - ./tagui flow_filename option(s)"
echo "tagui v5.17: use following options and this syntax to run - ./tagui flow_filename option(s)"
echo
echo "chrome - run on visible Chrome web browser instead of invisible PhantomJS (first install Chrome)"
echo "headless - run on invisible Chrome web browser instead of default PhantomJS (first install Chrome)"
Expand Down Expand Up @@ -292,21 +292,21 @@ headless_switch=""; if [ "$tagui_web_browser" == "headless" ]; then headless_swi
if [ "$tagui_data_set" -eq 1 ] || [ "$tagui_speed_mode" == false ]; then

# check for which operating system and launch chrome accordingly
chrome_started="$(uname -s)"; chrome_switches="--user-data-dir=chrome/tagui_user_profile --remote-debugging-port=9222 about:blank"
chrome_started="$(uname -s)"; chrome_switches="--remote-debugging-port=9222 about:blank"
if [ "$chrome_started" == "Darwin" ]; then
if ! [ -f "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ]; then
echo "ERROR - cannot find Chrome at \"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome\""
echo "Chrome is at a non-standard location on your macOS, raise an issue on TagUI GitHub page"; exit 1; fi
chrome_process_id="$(ps x | grep remote-debugging-port=9222 | grep tagui_user_profile | grep window-size | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)"
if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $chrome_switches $window_size $headless_switch > /dev/null 2>&1 &
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir="$TAGUI_DIR/chrome/tagui_user_profile" $chrome_switches $window_size $headless_switch > /dev/null 2>&1 &
else
if ! type "$chrome_command" > /dev/null; then
echo "ERROR - cannot find Chrome command \"$chrome_command\""
echo "update chrome_command setting in tagui/src/tagui and make sure symlink to command is created"; exit 1; fi
chrome_process_id="$(ps x | grep remote-debugging-port=9222 | grep tagui_user_profile | grep window-size | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)"
if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi
$chrome_command $chrome_switches $window_size $headless_switch > /dev/null 2>&1 &
$chrome_command --user-data-dir="$TAGUI_DIR/chrome/tagui_user_profile" $chrome_switches $window_size $headless_switch > /dev/null 2>&1 &
fi

# wait until chrome is ready with websocket url for php thread
Expand Down
13 changes: 7 additions & 6 deletions src/tagui.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rem enable windows for loop advanced flow control
setlocal enableextensions enabledelayedexpansion

if "%~1"=="" (
echo tagui v5.16: use following options and this syntax to run - tagui flow_filename option^(s^)
echo tagui v5.17: use following options and this syntax to run - tagui flow_filename option^(s^)
echo.
echo chrome - run on visible Chrome web browser instead of invisible PhantomJS ^(first install Chrome^)
echo headless - run on invisible Chrome web browser instead of default PhantomJS ^(first install Chrome^)
Expand Down Expand Up @@ -596,16 +596,17 @@ if exist "tagui_chrome.in" (

rem check for which operating system and launch chrome accordingly
set chrome_started=Windows
set chrome_switches=--user-data-dir=chrome\tagui_user_profile --remote-debugging-port=9222 about:blank
set chrome_switches=--remote-debugging-port=9222 about:blank
if not exist "%chrome_command%" (
echo ERROR - cannot find Chrome at "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
echo ERROR - cannot find Chrome at "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
echo ERROR - or at another common folder "C:\Program Files\Google\Chrome\Application\chrome.exe"
echo ERROR - or at user folder "%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe"
echo update chrome_command setting in tagui\src\tagui.cmd to your chrome.exe
exit /b 1
)
for /f "tokens=* usebackq" %%p in (`wmic process where "caption like '%%chrome.exe%%' and commandline like '%%tagui_user_profile --remote-debugging-port=9222%%'" get processid 2^>nul ^| cut -d" " -f 1 ^| sort -nur ^| head -n 1`) do set chrome_process_id=%%p
for /f "tokens=* usebackq" %%p in (`wmic process where "caption like '%%chrome.exe%%' and commandline like '%%tagui_user_profile_ --remote-debugging-port=9222%%'" get processid 2^>nul ^| cut -d" " -f 1 ^| sort -nur ^| head -n 1`) do set chrome_process_id=%%p
if not "!chrome_process_id!"=="" taskkill /PID !chrome_process_id! /T /F > nul 2>&1
start "" "%chrome_command%" !chrome_switches! !window_size! !headless_switch!
start "" "%chrome_command%" --user-data-dir="%~dp0chrome\tagui_user_profile" !chrome_switches! !window_size! !headless_switch!

:scan_ws_again
rem wait until chrome is ready with websocket url for php thread
Expand Down Expand Up @@ -635,7 +636,7 @@ if exist "tagui_chrome.in" echo finish > tagui_chrome.in

rem kill chrome processes by checking which os the processes are started on
if not "!chrome_started!"=="" if %tagui_speed_mode%==false (
for /f "tokens=* usebackq" %%p in (`wmic process where "caption like '%%chrome.exe%%' and commandline like '%%tagui_user_profile --remote-debugging-port=9222%%'" get processid 2^>nul ^| cut -d" " -f 1 ^| sort -nur ^| head -n 1`) do set chrome_process_id=%%p
for /f "tokens=* usebackq" %%p in (`wmic process where "caption like '%%chrome.exe%%' and commandline like '%%tagui_user_profile_ --remote-debugging-port=9222%%'" get processid 2^>nul ^| cut -d" " -f 1 ^| sort -nur ^| head -n 1`) do set chrome_process_id=%%p
if not "!chrome_process_id!"=="" taskkill /PID !chrome_process_id! /T /F > nul 2>&1
)
rem end of big loop for managing multiple data sets in datatable
Expand Down

0 comments on commit 98a9a28

Please sign in to comment.