2023-07-28 10:15:46 -04:00
; Notes/Extra Info/#Includes
;------------------------------------------------
2023-07-28 10:54:50 -04:00
; Chrome Global Variables
;------------------------------------------------
; Chrome/Selenium
global ChromeFilepath
; Declare global variables here so they don't have to be declared in each script
global ChromeTabsURLArray
global DriverTitleArray
global LastWebsitePostURL
global CurrentTabURL
global URLOfLastErrorPage
2023-09-16 21:31:53 -04:00
global chromeDLURL64
global chromedriverDLURL64
2023-09-20 20:45:12 -04:00
global InstalledChromeVersion
2023-07-28 10:54:50 -04:00
; Chrome Related Functions
;------------------------------------------------
2023-09-20 20:45:12 -04:00
DownloadLatestChromium ( ) {
if ( ChromeFilepath = " " )
ChromeFilepath := GetInstalledChromeFilepath ( )
if ( chromedriverDLURL64 = " " or chromeDLURL64 = " " ) {
ChromeStableLatestVersion := GetLatestChromeStableVersion ( )
GetDownloadURLOfChromeAndDriver ( ChromeStableLatestVersion )
}
; Msgbox % "chromedriverDLURL64: " chromedriverDLURL64
; Msgbox % "chromeDLURL64: " chromeDLURL64
ParentFolder = %A_ScriptDir% \Lib \Downloads
ChromeDriverDownloadZipFilepath = %ParentFolder% \chromedriver - win64 . zip
ChromeDriverDownloadFilepath = %ParentFolder% \chromedriver - win64
ChromeDriverTemporaryExeFilepath = %ParentFolder% \chromedriver - win64 \chromedriver - win64 \chromedriver . exe
ChromeDownloadZipFilepath = %ParentFolder% \chrome - win64 . zip
2023-10-22 01:19:49 -04:00
ChromeExtractedDirectory = %A_ScriptDir% \Lib \chrome - win64
2023-09-20 20:45:12 -04:00
ChromeDriverMoverEXEFilepath = %A_ScriptDir% \Lib \Chromedriver - Mover . exe
2023-12-15 17:35:47 -05:00
ChromeDriverMoverURL = https : / / freedomain . dev / attachments / b7b608b6 - 379 a - 42 bb - a7c4 - 23 fd67a05bb3
2023-09-20 20:45:12 -04:00
ChromeDriverProgramFilesExeFilepath = C : \Program Files \SeleniumBasic \chromedriver . exe
ManualMoveChromedriverMessage = Please manually copy chromedriver . exe from : `n `n %ChromeDriverDownloadFilepath% `n `n To : `n `n C : \Program Files \SeleniumBasic \chromedriver . exe
/*
With URLDownloadToFile you don 't need to delete pre - existing files , as they get overwriten when a new file is downloaded .
FileRemoveDir , %ParentFolder% , 1
if ( ErrorLevel ) {
Message = Failed to download Parent Download Folder .
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
}
if ( ! FileExist ( ParentFolder ) ) {
; msgbox, creating dir
FileCreateDir , %ParentFolder%
}
Msgbox % " ParentFolder: " ParentFolder
msgbox % FileExist ( ParentFolder )
if ( ! FileExist ( ParentFolder ) ) {
msgbox , creating dir
FileCreateDir , %ParentFolder%
}
FileDelete , %ChromeDriverDownloadZipFilepath%
if ( ErrorLevel )
msgbox , failed to delete %ChromeDriverDownloadZipFilepath%
FileRemoveDir , %ChromeDownloadZipFilepath% , 1
if ( ErrorLevel )
msgbox , failed to delete %ChromeDownloadZipFilepath%
FileRemoveDir , %ChromeDriverDownloadFilepath% , 1
msgbox , failed to delete %ChromeDriverDownloadFilepath%
2023-10-22 01:19:49 -04:00
FileRemoveDir , %ChromeExtractedDirectory% , 1
2023-09-20 20:45:12 -04:00
* /
if ( ! FileExist ( ParentFolder ) ) {
; msgbox, creating dir
FileCreateDir , %ParentFolder%
}
2023-10-22 01:19:49 -04:00
; close any open instances of Chromium
SetTitleMatchMode , 2 ; substring
if ( WinExist ( " - Chromium " ) ) {
Message = Trying to close any open Chromium Windows
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
Loop , 10 {
WinClose , - Chromium ; , WinText, SecondsToWait, ExcludeTitle, ExcludeText]
sleep , 500
}
}
if ( WinExist ( " - Chromium " ) ) {
Message = Failed to close existing Chromium Window ( s ) . Please close them manually and then click the " Update Chrome " button again
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
ToolTip
MsgBox 0x10 , , %Message%
return
}
; msgbox
2023-09-20 20:45:12 -04:00
FileGetTime , ChromeDriverExeOldCreationTime , %ChromeDriverProgramFilesExeFilepath% , C
2023-10-22 01:19:49 -04:00
Message = Downloading Chromedriver v %ChromeStableLatestVersion% to : `n %ChromeDriverDownloadZipFilepath%
2023-09-20 20:45:12 -04:00
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
UrlDownloadToFile , %chromedriverDLURL64% , %ChromeDriverDownloadZipFilepath%
2023-10-22 01:19:49 -04:00
Message = Downloading Chromium v %ChromeStableLatestVersion% to : `n %ChromeDownloadZipFilepath%
2023-09-20 20:45:12 -04:00
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
UrlDownloadToFile , %chromeDLURL64% , %ChromeDownloadZipFilepath%
; delete the pre-existing chrome-win64 directory
Message = Deleting Old Chromium Directory
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
2023-10-22 01:19:49 -04:00
FileRemoveDir , %ChromeExtractedDirectory% , 1
if ( FileExist ( ChromeExtractedDirectory ) ) {
Message = Failed to delete the old Chromium . `n Please manually delete the following directory and then run the Chrome Update again . `n `n %ChromeExtractedDirectory%
2023-09-20 20:45:12 -04:00
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,ErrorSummaryVar " )
2023-10-22 01:19:49 -04:00
MsgBox 0x10 , , %Message%
2023-09-20 20:45:12 -04:00
ToolTip
return
}
2023-10-22 01:19:49 -04:00
; Double check that .zip files exist
ChromeDriverZipExists := FileExist ( ChromeDriverDownloadZipFilepath )
if ( ! ChromeDriverZipExists ) {
Message = Download of chromedriver failed for some reason . chromedriver . zip not found .
SaveOrPostProgress ( Message , PostType := " Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging " )
MsgBox 0x10 , , %Message%
Return
}
ChromeZipExists := FileExist ( ChromeDownloadZipFilepath )
if ( ! ChromeZipExists ) {
Message = Download of chrome failed for some reason . chrome . zip not found .
SaveOrPostProgress ( Message , PostType := " Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging " )
MsgBox 0x10 , , %Message%
Return
}
2023-09-20 20:45:12 -04:00
Message = Extracting Chromedriver v %ChromeStableLatestVersion% Zip file
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
Unzip ( ChromeDriverDownloadZipFilepath , ChromeDriverDownloadFilepath )
Message = Extracting Chromium v %ChromeStableLatestVersion% Zip file
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
2023-10-22 01:19:49 -04:00
Unzip ( ChromeDownloadZipFilepath , ChromeExtractedDirectory )
2023-09-20 20:45:12 -04:00
2023-09-16 22:45:00 -04:00
2023-09-20 20:45:12 -04:00
; Check if the Copy-ChromeDriver-To-Program-Files.exe file exists
2023-10-22 01:19:49 -04:00
; @todo, remove later. this is temporary to fix chromedriver-mover being broken and needing to be replaced
FileDelete , %ChromeDriverMoverEXEFilepath%
2023-09-20 20:45:12 -04:00
Message = Checking Chromedriver - Mover . exe exists
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
if ( ! FileExist ( ChromeDriverMoverEXEFilepath ) ) {
Message = Chromedriver - Mover not found . Downloading from Gitea
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
UrlDownloadToFile , %ChromeDriverMoverURL% , %ChromeDriverMoverEXEFilepath%
if ( ErrorLevel ) {
Message = Failed to download the Copy - ChromeDriver - To - Program - Files . exe executable . `n `n %ManualMoveChromedriverMessage%
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging " )
ToolTip
Return
}
}
if ( ! FileExist ( ChromeDriverMoverEXEFilepath ) ) {
Message = ChromeDriver - Mover not found after downloading . `n Possibly triggered and deleted by Antivirus ? `n `n %ManualMoveChromedriverMessage%
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging,msgbox " )
ToolTip
return
}
Message = Starting up Chromedriver - Mover
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
; Msgbox % "ChromeDriverMoverEXEFilepath: " ChromeDriverMoverEXEFilepath
; Msgbox % "ChromeDriverDownloadFilepath: " ChromeDriverDownloadFilepath
try , Run " %ChromeDriverMoverEXEFilepath% " " %ChromeDriverDownloadFilepath% "
if ( ErrorLevel = " ERROR " ) {
Message = Failed to run Chromedriver - Mover . exe program to automatically copy the chromedriver to Program Files . `n %ManualMoveChromedriverMessage%
MsgBox 0x40 , , %Message%
}
2023-10-22 01:19:49 -04:00
Message = Waiting 30 seconds for new Chromedriver to get moved to C : \Program Files \SeleniumBasic \
2023-09-20 20:45:12 -04:00
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
Loop , 30 {
sleep , 1000
FileGetTime , ChromeDriverExeCurrentCreationTime , %ChromeDriverProgramFilesExeFilepath% , C
; Msgbox % "ChromeDriverExeOldCreationTime: " ChromeDriverExeOldCreationTime
; Msgbox % "ChromeDriverExeCurrentCreationTime: " ChromeDriverExeCurrentCreationTime
2023-09-16 22:45:00 -04:00
2023-09-20 20:45:12 -04:00
if ( ErrorLevel ) {
Message = chromedriver . exe not found in %ChromeDriverProgramFilesExeFilepath% . `n Waiting for new version to get copied over .
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
; sleep, 1000
Continue
}
if ( ChromeDriverExeCurrentCreationTime != ChromeDriverExeOldCreationTime and ChromeDriverExeCurrentCreationTime != " " ) {
break
}
; sleep, 1000
Continue
}
if ( ! FileExist ( ChromeDriverProgramFilesExeFilepath ) ) {
Message = Failed to Automatically move chromedriver . exe `n %ManualMoveChromedriverMessage%
MsgBox 0x40 , , %Message%
ToolTip
return
}
Message = Chromium and Chromedriver . exe were updated successfully .
SaveOrPostProgress ( Message := Message , PostType := " Tooltip,ErrorLoggingTextFile,DiscordErrorLogging " )
MsgBox 0x40 , , %Message%
ToolTip
return
2023-09-16 21:31:53 -04:00
}
2023-09-20 20:45:12 -04:00
2023-09-16 22:45:00 -04:00
CheckForChromeUpdates ( ChromeFilepath := " " ) {
if ( ChromeFilepath = " " )
2023-09-20 20:45:12 -04:00
ChromeFilepath := GetInstalledChromeFilepath ( )
2023-09-16 22:45:00 -04:00
2023-09-20 20:45:12 -04:00
CurrentInstalledChromeVersion := GetInstalledChromeVersion ( )
2023-09-16 22:45:00 -04:00
CurrentChromeStableVersion := GetLatestChromeStableVersion ( )
2023-09-20 20:45:12 -04:00
if ( CurrentInstalledChromeVersion < CurrentChromeStableVersion ) {
2023-09-16 22:45:00 -04:00
ChromeUpdateAvailable := 1
return ChromeUpdateAvailable
}
else , Return 0
}
2023-09-16 21:31:53 -04:00
2023-09-20 20:45:12 -04:00
GetInstalledChromeFilepath ( ) {
2023-07-28 10:15:46 -04:00
; ChromeFilepath is global variable
2023-08-02 22:08:07 -04:00
if ( ChromeFilepath = " " ) {
2023-07-28 10:15:46 -04:00
2023-08-02 22:08:07 -04:00
ChromePortableFilepath = %A_ScriptDir% \Lib \chrome - win64 \chrome . exe
2023-09-20 20:45:12 -04:00
ChromePortableFilepath2 = %A_ScriptDir% \Lib \chrome - win64 \chrome - win64 \chrome . exe ; filepath of chrome.exe that was downloaded automatically using this uploader
if ( FileExist ( ChromePortableFilepath ) or FileExist ( ChromePortableFilepath2 ) ) {
if ( FileExist ( ChromePortableFilepath2 ) )
ChromeFilepath := ChromePortableFilepath2
2023-07-28 10:54:50 -04:00
2023-09-20 20:45:12 -04:00
if ( FileExist ( ChromePortableFilepath ) )
2023-08-02 22:08:07 -04:00
ChromeFilepath := ChromePortableFilepath
Message = Using Chromium Portable for Upload
2023-10-22 01:19:49 -04:00
SaveOrPostProgress ( Message := Message , PostType := " ErrorLoggingTextFile,DiscordErrorLogging " )
2023-08-02 22:08:07 -04:00
}
else {
2023-09-20 20:45:12 -04:00
MsgBox 0x10 , Chromium Portable not Found , Chromium Portable not found . `n Please make sure it 's located at one of the following paths and then try again . `n `n %ChromePortableFilepath% `n OR `n %ChromePortableFilepath2%
2023-07-28 10:15:46 -04:00
2023-09-20 20:45:12 -04:00
; Leave this in for now, but i don't think we will be going to using the system Chrome in the future.
; if(FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"))
; ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
; if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe"))
; ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe
2023-08-02 22:08:07 -04:00
}
2023-07-28 10:15:46 -04:00
}
2023-09-16 22:45:00 -04:00
ToolTip
2023-09-16 21:31:53 -04:00
2023-07-28 10:15:46 -04:00
}
2023-09-20 20:45:12 -04:00
GetInstalledChromeVersion ( ) {
2023-07-28 10:15:46 -04:00
if ( ChromeFilepath = " " ) {
2023-09-20 20:45:12 -04:00
GetInstalledChromeFilepath ( )
2023-07-28 10:15:46 -04:00
}
2023-09-20 20:45:12 -04:00
GetInstalledChromeVersionCommand = powershell ( Get - Item '%ChromeFilepath% ') . VersionInfo . ProductVersion
InstalledChromeVersion := RunCMD ( GetInstalledChromeVersionCommand )
2023-09-16 22:45:00 -04:00
2023-09-20 20:45:12 -04:00
if ( InStr ( InstalledChromeVersion , " `r " ) )
InstalledChromeVersion := StrReplace ( InstalledChromeVersion , " `r " ) ; replace any newline characters that powershell returns
2023-09-16 22:45:00 -04:00
2023-09-20 20:45:12 -04:00
return InstalledChromeVersion
2023-07-28 10:15:46 -04:00
}
2023-08-20 01:20:16 -04:00
GetLatestChromeStableVersion ( ) {
; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints
json_str := urldownloadtovar ( " https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json " )
; converts json data variable into object
parsed := JSON . Load ( json_str )
2023-09-20 20:45:12 -04:00
try ChromeStableLatestVersion := parsed . channels . stable . version
2023-08-20 01:20:16 -04:00
2023-09-20 20:45:12 -04:00
if ( ChromeStableLatestVersion = " " ) {
2023-08-20 01:20:16 -04:00
return " Failed to parse json. "
}
2023-09-20 20:45:12 -04:00
return ChromeStableLatestVersion
2023-08-20 01:20:16 -04:00
}
2023-09-20 20:45:12 -04:00
GetDownloadURLOfChromeAndDriver ( InstalledChromeVersion ) {
2023-08-20 01:20:16 -04:00
; Will return the download URL of Chrome for Testing and Chrome Driver, seperated by a ||
2023-07-28 10:15:46 -04:00
; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints
json_str := urldownloadtovar ( " https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json " )
; requires #include of json.ahk in parent script
parsed := JSON . Load ( json_str )
ChromelabsJsonEntriesCount := parsed . versions . count ( )
if ( ChromelabsJsonEntriesCount = " " ) {
return " Failed to parse chromedriver json. "
}
loop % ChromelabsJsonEntriesCount {
if ( A_index = ChromelabsJsonEntriesCount ) {
2023-09-20 20:45:12 -04:00
Message = " Failed to find %InstalledChromeVersion% in the ChromeLabs Json "
2023-07-28 10:15:46 -04:00
return Message
}
2023-09-20 20:45:12 -04:00
if ( InstalledChromeVersion = parsed . versions [ A_Index ] . version ) {
2023-07-28 10:15:46 -04:00
VersionIndex := A_Index
2023-08-20 01:20:16 -04:00
; loop through the platforms to get download URL for Chrome
loop % parsed . versions [ VersionIndex ] . downloads . chrome . count ( ) {
if ( parsed . versions [ VersionIndex ] . downloads . chrome [ A_Index ] . platform = " win64 " )
2023-09-20 20:45:12 -04:00
chromeDLURL64 := parsed . versions [ VersionIndex ] . downloads . chrome [ A_Index ] . url
2023-08-20 01:20:16 -04:00
}
; loop through the platforms to get download URL for Chromedriver
2023-07-28 10:15:46 -04:00
loop % parsed . versions [ VersionIndex ] . downloads . chromedriver . count ( ) {
if ( parsed . versions [ VersionIndex ] . downloads . chromedriver [ A_Index ] . platform = " win64 " )
chromedriverDLURL64 := parsed . versions [ VersionIndex ] . downloads . chromedriver [ A_Index ] . url
}
2023-08-20 01:20:16 -04:00
2023-07-28 10:15:46 -04:00
break
}
}
2023-08-20 01:20:16 -04:00
URLS = %chromeDLURL64% | | %chromedriverDLURL64%
return URLS
2023-07-28 10:15:46 -04:00
}