2929Global $_g_bNetWebView2_DebugInfo = True
3030; ~ Global $_g_bNetWebView2_DebugDev = False
3131Global $_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
9799Global Enum _
@@ -211,7 +213,9 @@ 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 )
217+ If @error Then Return SetError (@error , @extended , ' ' )
218+
215219 $iMessage = __NetWebView2_LastMessage_KEEPER($oWebV2M )
216220 If $iMessage = $NETWEBVIEW2_MESSAGE__INIT_FAILED _
217221 Or $iMessage = $NETWEBVIEW2_MESSAGE__PROFILE_NOT_READY _
@@ -466,8 +470,9 @@ Func _NetWebView2_LoadWait($oWebV2M, $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE
466470 __NetWebView2_LastMessage_Navigation($oWebV2M , $NETWEBVIEW2_MESSAGE__NONE )
467471
468472 While 1
469- ; Allow AutoIt to "breathe" and process the GUI messages
470- Sleep (10 )
473+ ; Allow AutoIt to "breathe" and process the GUI messages, also allow user to abort
474+ __NetWebView2_Sleep(10 )
475+ If @error Then Return SetError (@error , @extended , ' ' )
471476
472477 ; RULE 1: If we reached the target status or higher
473478 Local $bWebIsReady = $oWebV2M .IsReady
@@ -719,14 +724,14 @@ EndFunc ;==>_NetWebView2_GetSource
719724; Name ..........: _NetWebView2_NavigateToPDF
720725; Description ...: Navigate to a PDF (local PDF file or online direct URL link to PDF file)
721726; Syntax ........: _NetWebView2_NavigateToPDF($oWebV2M, $s_URL_or_FilePath[, $s_Parameters = ''[, $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE_CHANGED[,
722- ; $sExpectedTitle = ""[, $iTimeOut_ms = 5000[, $iSleep_ms = 1000[, $bFreeze = True]]]]]])
727+ ; $sExpectedTitle = ""[, $iTimeOut_ms = 5000[, $iSleepAfter_ms = 1000[, $bFreeze = True]]]]]])
723728; Parameters ....: $oWebV2M - an object.
724729; $s_URL_or_FilePath - a string value.
725730; $s_Parameters - [optional] a string value. Default is ''.
726731; $iWaitMessage - [optional] an integer value. Default is $NETWEBVIEW2_MESSAGE__TITLE_CHANGED.
727732; $sExpectedTitle - [optional] Expected title to LoadWait for, as StringRegExp() pattern, By Default vaule it will compute the $s_URL_or_FilePath to guess RegExp for the Title
728733; $iTimeOut_ms - [optional] Maximum time to wait in milliseconds. 0 for infinite. Default is 5000ms
729- ; $iSleep_ms - [optional] an integer value. Default is 1000.
734+ ; $iSleepAfter_ms - [optional] an integer value. Default is 1000.
730735; $bFreeze - [optional] a boolean value. Default is True.
731736; Return values .: None
732737; Author ........: mLipok
@@ -736,7 +741,7 @@ EndFunc ;==>_NetWebView2_GetSource
736741; Link ..........:
737742; Example .......: No
738743; ===============================================================================================================================
739- Func _NetWebView2_NavigateToPDF($oWebV2M , $s_URL_or_FilePath , Const $s_Parameters = ' ' , $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE_CHANGED , $sExpectedTitle = Default , $iTimeOut_ms = 5000 , Const $iSleep_ms = 1000 , Const $bFreeze = True )
744+ Func _NetWebView2_NavigateToPDF($oWebV2M , $s_URL_or_FilePath , Const $s_Parameters = ' ' , $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE_CHANGED , $sExpectedTitle = Default , $iTimeOut_ms = 5000 , Const $iSleepAfter_ms = 1000 , Const $bFreeze = True )
740745 Local Const $s_Prefix = " [_NetWebView2_NavigateToPDF]: URL_or_File:" & $s_URL_or_FilePath ; #TODO suplement
741746
742747 If (Not IsObj ($oWebV2M )) Or ObjName ($oWebV2M , $OBJ_PROGID ) <> ' NetWebView2Lib.WebView2Manager' Then Return SetError (1 , 0 , " ERROR: Invalid Object" )
@@ -769,7 +774,9 @@ Func _NetWebView2_NavigateToPDF($oWebV2M, $s_URL_or_FilePath, Const $s_Parameter
769774 $oWebV2M .LockWebView()
770775 If $bFreeze Then __NetWebView2_freezer($oWebV2M , $idPic )
771776 _NetWebView2_Navigate($oWebV2M , $s_URL_or_FilePath , $iWaitMessage , $sExpectedTitle , $iTimeOut_ms )
772- If Not @error Then Sleep ($iSleep_ms )
777+ If Not @error Then __NetWebView2_Sleep($iSleepAfter_ms )
778+ If @error Then Return SetError (@error , @extended , ' ' )
779+
773780 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
774781 If $bFreeze And $idPic Then __NetWebView2_freezer($oWebV2M , $idPic )
775782 $oWebV2M .UnLockWebView()
@@ -1099,6 +1106,26 @@ EndFunc ;==>_NetJson_EncodeB64
10991106#EndRegion ; === NetWebView2Lib UDF === _NetJson_* functions
11001107
11011108#Region ; === NetWebView2Lib UDF === #INTERNAL_USE_ONLY#
1109+ ; #INTERNAL_USE_ONLY# ===========================================================================================================
1110+ ; Name ..........: __NetWebView2_Sleep
1111+ ; Description ...: Pause script execution for designated timeframe.
1112+ ; Syntax ........: __NetWebView2_Sleep($iPause)
1113+ ; Parameters ....: $iPause - Amount of time to pause (in milliseconds)
1114+ ; Return values .: Success - None
1115+ ; Failure - None and sets @error $NETWEBVIEW2_MESSAGE__USER_ABORT
1116+ ; Author ........: @Danp2, mLipok
1117+ ; Modified ......:
1118+ ; Remarks .......: Calls standard Sleep() by default. This can be overridden by setting $_g_bNetWebView2_Sleep so that a user supplied function gets called instead.
1119+ ; User's function can throw error which will lead to $NETWEBVIEW2_MESSAGE__USER_ABORT
1120+ ; Related .......:
1121+ ; Link ..........:
1122+ ; Example .......: No
1123+ ; ===============================================================================================================================
1124+ Func __NetWebView2_Sleep($iPause )
1125+ $_g_bNetWebView2_Sleep ($iPause )
1126+ If @error Then Return SetError ($NETWEBVIEW2_MESSAGE__USER_ABORT , @extended )
1127+ EndFunc ; ==>__NetWebView2_Sleep
1128+
11021129; #INTERNAL_USE_ONLY# ===========================================================================================================
11031130; Name ..........: __NetWebView2_WaitForReadyState
11041131; Description ...: Polls the browser until the document.readyState reaches 'complete'.
@@ -1143,7 +1170,9 @@ Func __NetWebView2_WaitForReadyState($oWebV2M, $hTimer, $iTimeOut_ms = 5000)
11431170 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & " TIMEOUT: Document state is " & $sReadyState & " Timeout_ms: " & Round (TimerDiff ($hTimer ), 0 ), 1 )
11441171 Return SetError (1 , 0 , False )
11451172 EndIf
1146- Sleep (50 )
1173+ __NetWebView2_Sleep(50 )
1174+ If @error Then Return SetError (@error , @extended , ' ' )
1175+
11471176 WEnd
11481177EndFunc ; ==>__NetWebView2_WaitForReadyState
11491178
0 commit comments