From e6778352d6da9240af14f40f73e1346080a1fd60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:52:40 +0100 Subject: [PATCH 1/4] WinHttp.WinHttpRequest.5.1 usage --- wd_helper.au3 | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/wd_helper.au3 b/wd_helper.au3 index b01dd572..1b02508b 100644 --- a/wd_helper.au3 +++ b/wd_helper.au3 @@ -2009,12 +2009,20 @@ EndFunc ;==>_WD_SelectFiles ; =============================================================================================================================== Func _WD_IsLatestRelease() Local Const $sFuncName = "_WD_IsLatestRelease" - Local Const $sGitURL = "https://github.com/Danp2/au3WebDriver/releases/latest" + Local Const $sURL = "https://github.com/Danp2/au3WebDriver/releases/latest" Local $bResult = Null Local $iErr = $_WD_ERROR_Success Local $sRegex = ' -1 Then @@ -2484,6 +2479,40 @@ Func _WD_DownloadFile($sURL, $sDest, $iOptions = Default) Return SetError(__WD_Error($sFuncName, $iErr, $sParameters, $iExt), $iExt, $bResult) EndFunc ;==>_WD_DownloadFile +; #FUNCTION# ==================================================================================================================== +; Name ..........: _WD_DownloadAsBinary +; Description ...: Download document (file or HTML content) as binary data from a given URL +; Syntax ........: _WD_DownloadAsBinary($sURL) +; Parameters ....: $sURL - URL representing file to be downloaded +; Return values .: Success - BinaryData (Download succeeded). +; Failure - '' (Download failed) and sets @error to one of the following values: +; - $_WD_ERROR_GeneralError +; Author ........: mLipok +; Modified ......: +; Remarks .......: in case of error @extended will follow WinHttp.WinHttpRequest.5.1 @error number +; Related .......: +; Link ..........: +; Example .......: No +; =============================================================================================================================== +Func _WD_DownloadAsBinary($sURL) + Local Const $sFuncName = "_WD_DownloadAsBinary" + Local Const $sParameters = 'Parameters: URL=' & $sURL + Local $iErr = $_WD_ERROR_Success, $iExt = 0 + Local $dResult + + Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") + If Not @error Then $oHTTP.Open("GET", $sURL, False) + If Not @error Then $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0") + If Not @error Then $oHTTP.Send("") + If Not @error Then $dResult = $oHTTP.ResponseBody + If @error Then + $iErr = $_WD_ERROR_GeneralError + $iExt = @error + $dResult = '' + EndIf + Return SetError(__WD_Error($sFuncName, $iErr, $sParameters, $iExt), $iExt, $dResult) +EndFunc ;==>_WD_DownloadAsBinary + ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WD_SetTimeouts ; Description ...: User friendly function to set webdriver session timeouts. @@ -3548,20 +3577,14 @@ Func __WD_GetLatestWebdriverInfo($aBrowser, $sBrowserVersion, $bFlag64) Local $sURL = $aBrowser[0][$_WD_BROWSER_LatestReleaseURL] Local $sRegex = $aBrowser[0][$_WD_BROWSER_LatestReleaseRegex] Local $sNewURL = $aBrowser[0][$_WD_BROWSER_NewDriverURL] - #forceref $sBrowserVersion, $bFlag64 + #forceref $bFlag64 If StringRegExp($sURL, '["'']') Then $sURL = Execute($sURL) EndIf Local $sDriverLatest = InetRead($sURL) - If @error Then - Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") - $oHTTP.Open("GET", $sURL, False) - $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0") - $oHTTP.Send("") - $sDriverLatest = $oHTTP.ResponseBody - EndIf + If @error Then $sDriverLatest = _WD_DownloadAsBinary($sURL) If @error = $_WD_ERROR_Success Then Select From de8a3e8cd5f54d1324bdded7545f07b22edbb5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:47:30 +0100 Subject: [PATCH 3/4] fix --- wd_helper.au3 | 8 -------- 1 file changed, 8 deletions(-) diff --git a/wd_helper.au3 b/wd_helper.au3 index 0ec27ada..f9c2078d 100644 --- a/wd_helper.au3 +++ b/wd_helper.au3 @@ -2019,14 +2019,6 @@ Func _WD_IsLatestRelease() If @error Then $iErr = $_WD_ERROR_GeneralError Else - Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") - $oHTTP.Open("GET", $sURL, False) - $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0") - $oHTTP.Send("") - $sResult = $oHTTP.ResponseBody - EndIf - - If $iErr = $_WD_ERROR_Success Then Local $aLatestWDVersion = StringRegExp(BinaryToString($sResult), $sRegex, $STR_REGEXPARRAYMATCH) If Not @error Then From 8c54a7775f076919ab62e90e9d98384b4b3ade28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Fri, 1 Mar 2024 08:19:10 +0100 Subject: [PATCH 4/4] error handling --- wd_helper.au3 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/wd_helper.au3 b/wd_helper.au3 index f9c2078d..a49d4dbc 100644 --- a/wd_helper.au3 +++ b/wd_helper.au3 @@ -2488,19 +2488,24 @@ EndFunc ;==>_WD_DownloadFile ; =============================================================================================================================== Func _WD_DownloadAsBinary($sURL) Local Const $sFuncName = "_WD_DownloadAsBinary" - Local Const $sParameters = 'Parameters: URL=' & $sURL + Local Const $sParameters = "Parameters: URL=" & $sURL Local $iErr = $_WD_ERROR_Success, $iExt = 0 Local $dResult + ; Handle COM Errors + Local $oErr = ObjEvent("AutoIt.Error", __WD_ErrHnd) + #forceref $oErr + + Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") - If Not @error Then $oHTTP.Open("GET", $sURL, False) - If Not @error Then $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0") - If Not @error Then $oHTTP.Send("") + $oHTTP.Open("GET", $sURL, False) + $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0") + $oHTTP.Send("") If Not @error Then $dResult = $oHTTP.ResponseBody If @error Then $iErr = $_WD_ERROR_GeneralError $iExt = @error - $dResult = '' + $dResult = "" EndIf Return SetError(__WD_Error($sFuncName, $iErr, $sParameters, $iExt), $iExt, $dResult) EndFunc ;==>_WD_DownloadAsBinary