Skip to content

Commit 56cec44

Browse files
authored
Update NetWebView2Lib.au3 ++ __NetWebView2_Sleep()
1 parent 51174fc commit 56cec44

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

NetWebView2Lib.au3

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
Global $_g_bNetWebView2_DebugInfo = True
3030
;~ Global $_g_bNetWebView2_DebugDev = False
3131
Global $_g_bNetWebView2_DebugDev = (@Compiled = 1)
32+
Global $_g_bNetWebView2_Sleep = Sleep ; Default to calling standard Sleep function
3233

3334
#Region ; === NetWebView2Lib UDF === ENUMS
3435

@@ -92,6 +93,7 @@ Global Enum _ ; $NETWEBVIEW2_MESSAGE__* are set by mainly by __NetWebView2_Event
9293
$NETWEBVIEW2_MESSAGE__DOWNLOAD_COMPLETED, _
9394
$NETWEBVIEW2_MESSAGE__RESPONSE_RECEIVED, _
9495
$NETWEBVIEW2_MESSAGE__UNKNOWN_MESSAGE, _
96+
$NETWEBVIEW2_MESSAGE__USER_ABORT, _
9597
$NETWEBVIEW2_MESSAGE___FAKE_COUNTER
9698

9799
Global Enum _
@@ -211,7 +213,7 @@ Func _NetWebView2_Initialize($oWebV2M, $hUserGUI, $s_ProfileDirectory, $i_Left =
211213
Local $iTimeOut_ms = 10000 ; max 10 seconds for initialization
212214
Local $iMessage
213215
Do
214-
Sleep(50)
216+
__NetWebView2_Sleep(10)
215217
$iMessage = __NetWebView2_LastMessage_KEEPER($oWebV2M)
216218
If $iMessage = $NETWEBVIEW2_MESSAGE__INIT_FAILED _
217219
Or $iMessage = $NETWEBVIEW2_MESSAGE__PROFILE_NOT_READY _
@@ -467,7 +469,7 @@ Func _NetWebView2_LoadWait($oWebV2M, $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE
467469

468470
While 1
469471
; Allow AutoIt to "breathe" and process the GUI messages
470-
Sleep(10)
472+
__NetWebView2_Sleep(10)
471473

472474
; RULE 1: If we reached the target status or higher
473475
Local $bWebIsReady = $oWebV2M.IsReady
@@ -769,7 +771,7 @@ Func _NetWebView2_NavigateToPDF($oWebV2M, $s_URL_or_FilePath, Const $s_Parameter
769771
$oWebV2M.LockWebView()
770772
If $bFreeze Then __NetWebView2_freezer($oWebV2M, $idPic)
771773
_NetWebView2_Navigate($oWebV2M, $s_URL_or_FilePath, $iWaitMessage, $sExpectedTitle, $iTimeOut_ms)
772-
If Not @error Then Sleep($iSleep_ms)
774+
If Not @error Then __NetWebView2_Sleep($iSleep_ms)
773775
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1)
774776
If $bFreeze And $idPic Then __NetWebView2_freezer($oWebV2M, $idPic)
775777
$oWebV2M.UnLockWebView()
@@ -1099,6 +1101,26 @@ EndFunc ;==>_NetJson_EncodeB64
10991101
#EndRegion ; === NetWebView2Lib UDF === _NetJson_* functions
11001102

11011103
#Region ; === NetWebView2Lib UDF === #INTERNAL_USE_ONLY#
1104+
; #INTERNAL_USE_ONLY# ===========================================================================================================
1105+
; Name ..........: __NetWebView2_Sleep
1106+
; Description ...: Pause script execution for designated timeframe.
1107+
; Syntax ........: __NetWebView2_Sleep($iPause)
1108+
; Parameters ....: $iPause - Amount of time to pause (in milliseconds)
1109+
; Return values .: Success - None
1110+
; Failure - None and sets @error $NETWEBVIEW2_MESSAGE__USER_ABORT
1111+
; Author ........: @Danp2, mLipok
1112+
; Modified ......:
1113+
; Remarks .......: Calls standard Sleep() by default. This can be overridden by setting $_g_bNetWebView2_Sleep so that a user supplied function gets called instead.
1114+
; User's function can throw error which will lead to $NETWEBVIEW2_MESSAGE__USER_ABORT
1115+
; Related .......:
1116+
; Link ..........:
1117+
; Example .......: No
1118+
; ===============================================================================================================================
1119+
Func __NetWebView2_Sleep($iPause)
1120+
$_g_bNetWebView2_Sleep($iPause)
1121+
If @error Then Return SetError($NETWEBVIEW2_MESSAGE__USER_ABORT)
1122+
EndFunc ;==>__NetWebView2_Sleep
1123+
11021124
; #INTERNAL_USE_ONLY# ===========================================================================================================
11031125
; Name ..........: __NetWebView2_WaitForReadyState
11041126
; Description ...: Polls the browser until the document.readyState reaches 'complete'.
@@ -1143,7 +1165,7 @@ Func __NetWebView2_WaitForReadyState($oWebV2M, $hTimer, $iTimeOut_ms = 5000)
11431165
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " TIMEOUT: Document state is " & $sReadyState & " Timeout_ms: " & Round(TimerDiff($hTimer), 0), 1)
11441166
Return SetError(1, 0, False)
11451167
EndIf
1146-
Sleep(50)
1168+
__NetWebView2_Sleep(50)
11471169
WEnd
11481170
EndFunc ;==>__NetWebView2_WaitForReadyState
11491171

0 commit comments

Comments
 (0)