diff --git a/NetWebView2Lib.au3 b/NetWebView2Lib.au3 index cdb3c58..f9c0593 100644 --- a/NetWebView2Lib.au3 +++ b/NetWebView2Lib.au3 @@ -124,9 +124,9 @@ Global Enum _ ; Indicates the reason for the process failure. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _NetWebView2_CreateManager ; Description ...: Create WebView2 object -; Syntax ........: _NetWebView2_CreateManager([$sUserAgent = ''[, $s_fnEventPrefix = ""[, $s_AddBrowserArgs = ""[, +; Syntax ........: _NetWebView2_CreateManager([$sUserAgent = ""[, $s_fnEventPrefix = ""[, $s_AddBrowserArgs = ""[, ; $bVerbose = False]]]]) -; Parameters ....: $sUserAgent - [optional] a string value. Default is ''. +; Parameters ....: $sUserAgent - [optional] a string value. Default is "". ; $s_fnEventPrefix - [optional] a string value. Default is "". ; $s_AddBrowserArgs - [optional] a string value. Default is "". Allows passing command-line switches (e.g., --disable-gpu, --mute-audio, --proxy-server="...") to the Chromium engine. ; $bVerbose - [optional] True/False - Enable/Disable diagnostic logging. Default is False = Disabled. @@ -140,7 +140,7 @@ Global Enum _ ; Indicates the reason for the process failure. ; Link ..........: https://peter.sh/experiments/chromium-command-line-switches/ ; Example .......: No ; =============================================================================================================================== -Func _NetWebView2_CreateManager($sUserAgent = '', $s_fnEventPrefix = "", $s_AddBrowserArgs = "", $bVerbose = False) +Func _NetWebView2_CreateManager($sUserAgent = "", $s_fnEventPrefix = "", $s_AddBrowserArgs = "", $bVerbose = False) Local Const $s_Prefix = "[_NetWebView2_CreateManager]: fnEventPrefix=" & $s_fnEventPrefix & " AddBrowserArgs=" & $s_AddBrowserArgs Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler @@ -151,14 +151,14 @@ Func _NetWebView2_CreateManager($sUserAgent = '', $s_fnEventPrefix = "", $s_AddB If @error Then $ERR = @error $EXT = @extended - $MSG = "Manager Creation Error : #SLN=" & @ScriptLineNumber + $MSG = " Manager Creation Error " & " #SLN=" & @ScriptLineNumber Else ; Enable/Disable diagnostic logging ; When enabled, the console will show entries like: +++[NetWebView2Lib][HANDLE:0x...][HH:mm:ss.fff] Message ; Verbose property was added to allow real-time diagnostic logging to the SciTE console (or any stdout listener). ; The diagnostic logs use a distinctive prefix and include the instance handle for easier filtering in multi-window applications. $oWebV2M.Verbose = $bVerbose -;~ If $_g_bNetWebView2_DebugDev Then __NetWebView2_ObjName_FlagsValue($oWebV2M) ; FOR DEV TESTING ONLY +;~ If $_g_bNetWebView2_DebugDev Then __NetWebView2_ObjName_FlagsValue($oWebV2M) ; FOR DEV TESTING ONLY If $sUserAgent Then $oWebV2M.SetUserAgent($sUserAgent) If $s_AddBrowserArgs Then $oWebV2M.AdditionalBrowserArguments = $s_AddBrowserArgs @@ -206,18 +206,19 @@ Func _NetWebView2_Initialize($oWebV2M, $hUserGUI, $s_ProfileDirectory, $i_Left = If Not IsHWnd($hUserGUI) Then $ERR = $NETWEBVIEW2_MESSAGE__CRITICAL_ERROR - $EXT = 0 $RET = False - $MSG = " !!! ERROR: $hUserGUI is not a valid HWND pointer #SLN=" & @ScriptLineNumber + $MSG = " !!! ERROR: $hUserGUI is not a valid HWND pointer" & " #SLN=" & @ScriptLineNumber Else ; ⚠️ Important: Enclose ($hUserGUI) in parentheses to force "Pass-by-Value". ; This prevents the COM layer from changing the AutoIt variable type from Ptr to Int64. $RET = $oWebV2M.Initialize(($hUserGUI), $s_ProfileDirectory, $i_Left, $i_Top, $i_Width, $i_Height) If @error Then - Return SetError(@error, @extended, $RET) + $ERR = @error + $EXT = @extended + $MSG = " !!! ERROR: Initialization COM issue" & " #SLN=" & @ScriptLineNumber Else - If $_g_bNetWebView2_DebugDev Then ConsoleWrite("! IFNC: FailureReportFolderPath = " & $oWebV2M.FailureReportFolderPath & @CRLF) + If $_g_bNetWebView2_DebugDev Then ConsoleWrite("! IFNC: DEV: FailureReportFolderPath = " & $oWebV2M.FailureReportFolderPath & @CRLF) #Region ; After Initialization wait for the engine to be ready before navigating Local $hTimer = TimerInit() @@ -225,35 +226,52 @@ Func _NetWebView2_Initialize($oWebV2M, $hUserGUI, $s_ProfileDirectory, $i_Left = Local $iMessage Do __NetWebView2_Sleep(10) - If @error Then Return SetError(@error, @extended, '') - - $iMessage = __NetWebView2_LastMessage_KEEPER($oWebV2M) - If $iMessage = $NETWEBVIEW2_MESSAGE__INIT_FAILED _ - Or $iMessage = $NETWEBVIEW2_MESSAGE__PROFILE_NOT_READY _ - Or $iMessage = $NETWEBVIEW2_MESSAGE__PROCESS_FAILED _ - Or $iMessage = $NETWEBVIEW2_MESSAGE__CRITICAL_ERROR Then - Return SetError($iMessage, @extended, '') + If @error Then + $ERR = @error + $EXT = @extended + $RET = "" + $MSG = " !!! ERROR: Sleep aborted" & " #SLN=" & @ScriptLineNumber + ExitLoop + Else + $iMessage = __NetWebView2_LastMessage_KEEPER($oWebV2M) ; get last message + If $iMessage = $NETWEBVIEW2_MESSAGE__INIT_FAILED _ + Or $iMessage = $NETWEBVIEW2_MESSAGE__PROFILE_NOT_READY _ + Or $iMessage = $NETWEBVIEW2_MESSAGE__PROCESS_FAILED _ + Or $iMessage = $NETWEBVIEW2_MESSAGE__CRITICAL_ERROR Then + $ERR = 1 + $RET = $iMessage + $MSG = " !!! ERROR: Last Message= " & $iMessage & " #SLN=" & @ScriptLineNumber + ExitLoop + Else + If TimerDiff($hTimer) >= $iTimeOut_ms Then + $ERR = 2 + $RET = "" + $MSG = " !!! ERROR: TimeOut happend" & " #SLN=" & @ScriptLineNumber + ExitLoop + EndIf + EndIf EndIf - If TimerDiff($hTimer) >= $iTimeOut_ms Then Return SetError(1, 0, '') Until $oWebV2M.IsReady Or $iMessage = $NETWEBVIEW2_MESSAGE__INIT_READY -;~ If Not __NetWebView2_WaitForReadyState($oWebV2M, $hTimer, $iTimeOut_ms) Then Return SetError(2, 0, '') +;~ If Not __NetWebView2_WaitForReadyState($oWebV2M, $hTimer, $iTimeOut_ms) Then Return SetError(2, 0, "") #EndRegion ; After Initialization wait for the engine to be ready before navigating - ; WebView2 Configuration - $oWebV2M.SetAutoResize($b_SetAutoResize) ; Using SetAutoResize(True) to skip WM_SIZE - $oWebV2M.AreDevToolsEnabled = $b_DevToolsEnabled ; Allow F12 - $oWebV2M.ZoomFactor = $i_ZoomFactor - $oWebV2M.BackColor = $s_BackColor + If Not $ERR Then + ; WebView2 Configuration + $oWebV2M.SetAutoResize($b_SetAutoResize) ; Using SetAutoResize(True) to skip WM_SIZE + $oWebV2M.AreDevToolsEnabled = $b_DevToolsEnabled ; Allow F12 + $oWebV2M.ZoomFactor = $i_ZoomFactor + $oWebV2M.BackColor = $s_BackColor - If $b_InitConsole Then - $oWebV2M.AddInitializationScript(__Get_Core_Bridge_JS()) - EndIf + If $b_InitConsole Then + $oWebV2M.AddInitializationScript(__Get_Core_Bridge_JS()) + EndIf - $EXT = $oWebV2M.GetBrowserProcessId() + $EXT = $oWebV2M.GetBrowserProcessId() + EndIf EndIf EndIf + __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) - If $ERR Then __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " !!! Manager Creation ERROR", 1) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_Initialize @@ -282,12 +300,12 @@ Func _NetWebView2_IsRegisteredCOMObject() ObjCreate("NetWebView2Lib.WebView2Manager") If @error Then $ERR = 1 - $MSG = " NetWebView2Lib.WebView2Manager Not Registered" + $MSG = " NetWebView2Lib.WebView2Manager Not Registered" & " #SLN=" & @ScriptLineNumber Else ObjCreate("NetWebView2Lib.WebView2Parser") If @error Then $ERR = 2 - $MSG = " NetWebView2Lib.WebView2Parser Not Registered" + $MSG = " NetWebView2Lib.WebView2Parser Not Registered" & " #SLN=" & @ScriptLineNumber Else $RET = True EndIf @@ -314,14 +332,14 @@ Func _NetWebView2_IsAlreadyInstalled() Local Const $s_Prefix = "[_NetWebView2_IsAlreadyInstalled]:" Local $ERR = 0, $EXT = 0, $RET = "", $MSG = "" ; predefined endpoint results If @AutoItX64 Then - $RET = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}', 'pv') + $RET = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}", "pv") Else - $RET = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}', 'pv') + $RET = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}", "pv") EndIf If $RET Then $EXT = 1 Else - $RET = RegRead('HKEY_CURRENT_USER\Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}', 'pv') + $RET = RegRead("HKEY_CURRENT_USER\Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}", "pv") $EXT = 2 EndIf @@ -366,24 +384,24 @@ Func _NetWebView2_CleanUp(ByRef $oWebV2M, ByRef $oJSBridge) If Not IsObj($oWebV2M) Then $ERR = 1 $EXT = 1 - $MSG = " ! NetWebView2Lib.WebView2Manager is not object : #SLN=" & @ScriptLineNumber + $MSG = " ! NetWebView2Lib.WebView2Manager is not object " & " #SLN=" & @ScriptLineNumber ElseIf ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then $ERR = 2 $EXT = 1 - $MSG = " ! NetWebView2Lib.WebView2Manager object has invalid ProgID : #SLN=" & @ScriptLineNumber + $MSG = " ! NetWebView2Lib.WebView2Manager object has invalid ProgID " & " #SLN=" & @ScriptLineNumber ;~ ElseIf Not IsObj($oJSBridge) Then ; $oJSBridge usage is optional ;~ $ERR = 3 ;~ $EXT = 2 -;~ $MSG = " ! NetWebView2Lib.WebView2Bridge is not object : #SLN=" & @ScriptLineNumber +;~ $MSG = " ! NetWebView2Lib.WebView2Bridge is not object " & " #SLN=" & @ScriptLineNumber ;~ ElseIf ObjName($oJSBridge, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Bridge" Then ; $oJSBridge usage is optional ;~ $ERR = 4 ;~ $EXT = 2 -;~ $MSG = " ! NebView2Lib.WebView2Bridge object has invalid ProgID : #SLN=" & @ScriptLineNumber +;~ $MSG = " ! NebView2Lib.WebView2Bridge object has invalid ProgID " & " #SLN=" & @ScriptLineNumber Else _NetWebView2_SetLockState($oWebV2M, True) $RET = $oWebV2M.Cleanup() $ERR = @error - If $ERR Then $MSG = " ! Error during internal CleanUp : #SLN=" & @ScriptLineNumber + If $ERR Then $MSG = " ! Error during internal CleanUp " & " #SLN=" & @ScriptLineNumber $oWebV2M = 0 $oJSBridge = 0 @@ -434,12 +452,17 @@ Func _NetWebView2_ExecuteScript($oWebV2M, $sJavaScript, $iMode = $NETWEBVIEW2_EX Switch $iMode Case 0 $RET = $oWebV2M.ExecuteScript($sJavaScript) + $ERR = @error + If @error Then $MSG = " ! Manager.ExecuteScript($sJavaScript) ERROR " & " #SLN=" & @ScriptLineNumber Case 1 $RET = $oWebV2M.ExecuteScriptOnPage($sJavaScript) + $ERR = @error + If @error Then $MSG = " ! Manager.ExecuteScriptOnPage($sJavaScript) ERROR " & " #SLN=" & @ScriptLineNumber Case 2 $RET = $oWebV2M.ExecuteScriptWithResult($sJavaScript) + $ERR = @error + If @error Then $MSG = " ! Manager.ExecuteScriptWithResult($sJavaScript) ERROR " & " #SLN=" & @ScriptLineNumber EndSwitch - $ERR = @error __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_ExecuteScript @@ -467,7 +490,7 @@ Func _NetWebView2_GetBridge($oWebV2M, $s_fnEventPrefix = "") Local $oWebJS = $oWebV2M.GetBridge() If @error Then $ERR = @error - $MSG = " ! Manager.GetBridge() ERROR : #SLN=" & @ScriptLineNumber + $MSG = " ! Manager.GetBridge() ERROR " & " #SLN=" & @ScriptLineNumber Else ObjEvent($oWebJS, "__NetWebView2_JSEvents__", "IBridgeEvents") If $s_fnEventPrefix Then ObjEvent($oWebJS, $s_fnEventPrefix, "IBridgeEvents") @@ -499,7 +522,7 @@ Func _NetWebView2_GetVersion($oWebV2M) $RET = $oWebV2M.version $ERR = @error - $MSG = " : Version=" & $RET & " : #SLN=" & @ScriptLineNumber + $MSG = " : Version=" & $RET & " #SLN=" & @ScriptLineNumber __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) @@ -516,6 +539,7 @@ EndFunc ;==>_NetWebView2_GetVersion ; $iTimeOut_ms - [optional] Maximum time to wait in milliseconds. 0 for infinite. Default is 5000ms ; Return values .: Success - True ; Failure - False and sets @error: +#TODO @error numbers changed revise the header ; 3 - Navigation Error ($NETWEBVIEW2_MESSAGE__NAV_ERROR) ; 4 - Timeout reached ; Author ........: mLipok, ioa747 @@ -526,7 +550,7 @@ EndFunc ;==>_NetWebView2_GetVersion ; Example .......: No ; =============================================================================================================================== Func _NetWebView2_LoadWait($oWebV2M, $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, $sExpectedTitle = "", $iTimeOut_ms = 5000) - Local Const $s_Prefix = '[_NetWebView2_LoadWait]: WaitMessage:' & $iWaitMessage & ' WAIT:' & $iWaitMessage & ' ExpectedTitle="' & $sExpectedTitle & '" TimeOut_ms=' & $iTimeOut_ms + Local Const $s_Prefix = "[_NetWebView2_LoadWait]: WaitMessage:" & $iWaitMessage & " ExpectedTitle=" & (($sExpectedTitle) ? ($sExpectedTitle) : (" is EMPTY")) & " TimeOut_ms=" & $iTimeOut_ms Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results Local $hTimer = TimerInit() @@ -534,64 +558,71 @@ Func _NetWebView2_LoadWait($oWebV2M, $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE __NetWebView2_LastMessage_Navigation($oWebV2M, $NETWEBVIEW2_MESSAGE__NONE) While 1 - ; Allow AutoIt to "breathe" and process the GUI messages, also allow user to abort - __NetWebView2_Sleep(10) - If @error Then Return SetError(@error, @extended, '') - - ; RULE 1: If we reached the target status or higher - Local $bWebIsReady = $oWebV2M.IsReady + __NetWebView2_Sleep(10) ; Allow AutoIt to "breathe" and process the GUI messages, also allow user to abort If @error Then - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return SetError(1, 0, False) ; browser/COM error ? + $ERR = @error + $EXT = @extended + $RET = False + ExitLoop EndIf - ; RULE 2: TimeOut Check - If $iTimeOut_ms And TimerDiff($hTimer) >= $iTimeOut_ms Then + Local $bWebIsReady = $oWebV2M.IsReady ; RULE 1: If we reached the target status or higher + If @error Then ; browser/COM error ? + $ERR = 1 + $RET = False + ExitLoop + ElseIf $iTimeOut_ms And TimerDiff($hTimer) >= $iTimeOut_ms Then ; RULE 2: TimeOut Check __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " - TIME OUT - the waiting time has expired", 1, $ERR, $EXT) - Return SetError(2, 0, False) + $ERR = 2 + $RET = False + ExitLoop + ElseIf Not $bWebIsReady Then ; RULE 3: if browser is not ready continue waiting + ContinueLoop ; For navigation events, ensure the browser reports IsReady EndIf - ; RULE 3: if browser is not ready continue waiting - If Not $bWebIsReady Then ContinueLoop ; For navigation events, ensure the browser reports IsReady - ; RULE 4: checking browser ReadyState Local $iLastMessage = -1 Local $sReadyState = _NetWebView2_ExecuteScript($oWebV2M, "document.readyState", $NETWEBVIEW2_EXECUTEJS_MODE2_RESULT) If @error Then - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return SetError(7, 0, False) + $ERR = 7 + $RET = False + $MSG = " document.readyState execution Error " & " #SLN=" & @ScriptLineNumber + ExitLoop ElseIf StringLeft($sReadyState, 6) == "ERROR:" Then - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return SetError(8, 0, False) + $ERR = 8 + $RET = False + $MSG = " document.readyState execution Error " & " #SLN=" & @ScriptLineNumber + ExitLoop ElseIf $sReadyState = "complete" Then ; RULE 5: checking events messages $iLastMessage = __NetWebView2_LastMessage_Navigation($oWebV2M) - If $_g_bNetWebView2_DebugDev Then ConsoleWrite('! IFNC: TEST LOAD WAIT: ReadyState=' & $sReadyState & ' LastMessage=' & $iLastMessage & ' WaitMessage=' & $iWaitMessage & ' SLN=' & @ScriptLineNumber & @CRLF) + If $_g_bNetWebView2_DebugDev Then ConsoleWrite("! IFNC: DEV: TEST LOAD WAIT: ReadyState=" & $sReadyState & " LastMessage=" & $iLastMessage & " WaitMessage=" & $iWaitMessage & " #SLN=" & @ScriptLineNumber & @CRLF) If $iLastMessage = $NETWEBVIEW2_MESSAGE__NAV_ERROR Or $iLastMessage = $NETWEBVIEW2_MESSAGE__PROCESS_FAILED Or $iLastMessage = $NETWEBVIEW2_MESSAGE__CRITICAL_ERROR Then - If $_g_bNetWebView2_DebugDev Then ConsoleWrite('! IFNC: TEST LOAD WAIT: ' & $iLastMessage & ' SLN=' & @ScriptLineNumber & @CRLF) - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return SetError(3, $iLastMessage, False) -;~ ElseIf $iLastMessage >= $iWaitMessage Then ; checking events + If $_g_bNetWebView2_DebugDev Then ConsoleWrite("! IFNC: DEV: TEST LOAD WAIT: " & $iLastMessage & " #SLN=" & @ScriptLineNumber & @CRLF) + $ERR = 3 + $RET = False + ExitLoop ElseIf $iLastMessage >= $iWaitMessage Then ; checking events ; RULE 6: checking document title Local $sCurrentTitle = $oWebV2M.GetDocumentTitle() Local $bTitleCheck = ($sExpectedTitle And StringRegExp($sCurrentTitle, $sExpectedTitle, $STR_REGEXPMATCH) = 1) - Local $s_MessageInfo = '! IFNC: TEST LOAD WAIT: CurrentTitle="' & $sCurrentTitle & '" ExpectedTitle"' & $sExpectedTitle & '" TitleCheck=' & $bTitleCheck & ' LastMessage=' & $iLastMessage + Local $s_DEV_Info = "! IFNC: DEV: TEST LOAD WAIT: Prefix:: " & $s_Prefix & " TitleCheck=" & $bTitleCheck & " LastMessage=" & $iLastMessage If $sExpectedTitle And $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE_CHANGED And $bTitleCheck Then - If $_g_bNetWebView2_DebugDev Then ConsoleWrite($s_MessageInfo & ' SLN=' & @ScriptLineNumber & @CRLF) - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " LastMessage=" & $iLastMessage, 1, $ERR, $EXT) - Return True + If $_g_bNetWebView2_DebugDev Then ConsoleWrite($s_DEV_Info & " #SLN=" & @ScriptLineNumber & @CRLF) + $MSG = " LastMessage=" & $iLastMessage & " : ExpectedTitle=" & $sExpectedTitle & " #SLN=" & @ScriptLineNumber + $RET = True + ExitLoop Else - If $_g_bNetWebView2_DebugDev Then ConsoleWrite($s_MessageInfo & ' SLN=' & @ScriptLineNumber & @CRLF) - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " LastMessage=" & $iLastMessage, 1, $ERR, $EXT) - Return True + If $_g_bNetWebView2_DebugDev Then ConsoleWrite($s_DEV_Info & " #SLN=" & @ScriptLineNumber & @CRLF) + $MSG = " LastMessage=" & $iLastMessage & " #SLN=" & @ScriptLineNumber + $RET = True + ExitLoop EndIf EndIf EndIf - If $_g_bNetWebView2_DebugDev Then ConsoleWrite("> IFNC: TEST LOAD WAIT: __NetWebView2_LastMessage_Navigation($oWebV2M)=" & $iLastMessage & ' >> ' & __NetWebView2_LastMessage_Navigation($oWebV2M) & ' SLN=' & @ScriptLineNumber & @CRLF) + If $_g_bNetWebView2_DebugDev Then ConsoleWrite("! IFNC: DEV: TEST LOAD WAIT: __NetWebView2_LastMessage_Navigation($oWebV2M)=" & $iLastMessage & " >> " & __NetWebView2_LastMessage_Navigation($oWebV2M) & " #SLN=" & @ScriptLineNumber & @CRLF) WEnd - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_LoadWait @@ -620,18 +651,19 @@ EndFunc ;==>_NetWebView2_LoadWait ; Example .......: No ; =============================================================================================================================== Func _NetWebView2_Navigate($oWebV2M, $s_URL, $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, $sExpectedTitle = "", $iTimeOut_ms = 5000) - Local Const $s_Prefix = "[_NetWebView2_Navigate]: URL:" & $s_URL & " WAIT:" & $iWaitMessage & " TimeOut_ms=" & $iTimeOut_ms + Local Const $s_Prefix = "[_NetWebView2_Navigate]: URL:" & $s_URL & " WaitMessage: " & $iWaitMessage & " ExpectedTitle=" & (($sExpectedTitle) ? ($sExpectedTitle) : (" is EMPTY")) & " TimeOut_ms=" & $iTimeOut_ms Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler #forceref $oMyError - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object $ERR = 1 - $MSG = "ERROR: Invalid Object" - ELseif $iWaitMessage < $NETWEBVIEW2_MESSAGE__INIT_READY Or $iWaitMessage > $NETWEBVIEW2_MESSAGE__TITLE_CHANGED Then + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + ElseIf $iWaitMessage < $NETWEBVIEW2_MESSAGE__INIT_READY Or $iWaitMessage > $NETWEBVIEW2_MESSAGE__TITLE_CHANGED Then ; Parameter Validation - higher messsages are not for NAVIGATION thus not checking in _NetWebView2_LoadWait() $ERR = 2 - $MSG = "ERROR: $iWaitMessage not valid" + $MSG = " ERROR: $iWaitMessage not valid" & " #SLN=" & @ScriptLineNumber Else ; Execute Navigation ; The Local Error Handler catches potential "Disposed Object" crashes here @@ -645,7 +677,7 @@ Func _NetWebView2_Navigate($oWebV2M, $s_URL, $iWaitMessage = $NETWEBVIEW2_MESSAG $ERR = @error $EXT = @extended If @error Then ; If an error occurred (3: Nav Error, 4: Timeout), log the failure - $MSG = " -> LOAD WAIT FAILED" + $MSG = " -> LOAD WAIT FAILED" & " #SLN=" & @ScriptLineNumber EndIf EndIf $oWebV2M.UnLockWebView() @@ -674,31 +706,32 @@ EndFunc ;==>_NetWebView2_Navigate ; Example .......: No ; =============================================================================================================================== Func _NetWebView2_NavigateToString($oWebV2M, $s_HTML, $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, $sExpectedTitle = "", $iTimeOut_ms = 5000) - Local Const $s_Prefix = "[_NetWebView2_NavigateToString]:" & " HTML Size:" & StringLen($s_HTML) & " WaitMessage:" & $iWaitMessage & " TimeOut_ms=" & $iTimeOut_ms + Local Const $s_Prefix = "[_NetWebView2_NavigateToString]:" & " HTML Size:" & StringLen($s_HTML) & " WaitMessage:" & $iWaitMessage & " ExpectedTitle=" & (($sExpectedTitle) ? ($sExpectedTitle) : (" is EMPTY")) & " TimeOut_ms=" & $iTimeOut_ms Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler #forceref $oMyError - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object $ERR = 1 - $MSG = " Invalid Object Error: #SLN=" & @ScriptLineNumber + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber ElseIf $iWaitMessage < $NETWEBVIEW2_MESSAGE__INIT_READY Then $ERR = 2 - $MSG = " $iWaitMessage Error: #SLN=" & @ScriptLineNumber + $MSG = " $iWaitMessage Error" & " #SLN=" & @ScriptLineNumber ElseIf $iWaitMessage > $NETWEBVIEW2_MESSAGE__TITLE_CHANGED Then ; higher messsages are not for NAVIGATION thus not checking in _NetWebView2_LoadWait() $ERR = 3 - $MSG = " $iWaitMessage Error: #SLN=" & @ScriptLineNumber + $MSG = " $iWaitMessage Error" & " #SLN=" & @ScriptLineNumber Else $oWebV2M.LockWebView() $RET = $oWebV2M.NavigateToString($s_HTML) $ERR = @error If $ERR Then - $MSG = " NavigateToString Error: #SLN=" & @ScriptLineNumber + $MSG = " NavigateToString Error" & " #SLN=" & @ScriptLineNumber Else _NetWebView2_LoadWait($oWebV2M, $iWaitMessage, $sExpectedTitle, $iTimeOut_ms) $ERR = @error $EXT = @extended - $MSG = " LoadWait internal Error: #SLN=" & @ScriptLineNumber + $MSG = " LoadWait internal Error" & " #SLN=" & @ScriptLineNumber EndIf $oWebV2M.UnLockWebView() EndIf @@ -740,16 +773,18 @@ Func _NetWebView2_BrowserSetupWrapper($hOuterParentWindow, ByRef $oOuterWeb, $sE $hInnerWebViewWindow = GUICreate("", $iW, $iH, $iX, $iY, $WS_CHILD, -1, $hOuterParentWindow) GUISetState(@SW_SHOW, $hInnerWebViewWindow) - $oOuterWeb = _NetWebView2_CreateManager("", $sEventPrefix & '_Manager__', $s_AddBrowserArgs) - If @error Then Return SetError(@error, @extended, $oOuterWeb) - - Local $Result = _NetWebView2_Initialize($oOuterWeb, $hInnerWebViewWindow, $sProfile, 0, 0, $iW, $iH) - If @error Then Return SetError(@error, @extended, $Result) - - $oOuterBridge = _NetWebView2_GetBridge($oOuterWeb, $sEventPrefix & "_Bridge__") - If @error Then Return SetError(@error, @extended, $oOuterBridge) - - #TODO ENDPOINT REFACTORING + $oOuterWeb = _NetWebView2_CreateManager("", $sEventPrefix & "_Manager__", $s_AddBrowserArgs) + If Not @error Then + _NetWebView2_Initialize($oOuterWeb, $hInnerWebViewWindow, $sProfile, 0, 0, $iW, $iH) + If Not @error Then + $oOuterBridge = _NetWebView2_GetBridge($oOuterWeb, $sEventPrefix & "_Bridge__") + If Not @error Then + $RET = True + EndIf + EndIf + EndIf + $ERR = @error + $EXT = @extended __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_BrowserSetupWrapper @@ -757,10 +792,10 @@ EndFunc ;==>_NetWebView2_BrowserSetupWrapper ; #FUNCTION# ==================================================================================================================== ; Name ..........: _NetWebView2_ExportPageData ; Description ...: Captures page data using Chrome DevTools Protocol. Can return MHTML or other CDP formats based on the `cdpParameters` JSON string. -; Syntax ........: _NetWebView2_ExportPageData($oWebV2M, $iFormat[, $sFilePath = '']) +; Syntax ........: _NetWebView2_ExportPageData($oWebV2M, $iFormat[, $sFilePath = ""]) ; Parameters ....: $oWebV2M - an object. ; $iFormat - a string value. 0 HTML only, 1 MHTML Snapshot -; $sFilePath - [optional] a string value. Default is '' which mean make Base64 as a result instead write to file +; $sFilePath - [optional] a string value. Default is "" which mean make Base64 as a result instead write to file ; Return values .: Success - Depends on $sFilePath String with Base64 encoded binary content of the PDF or "SUCCESS: File saved to ...." ; Failure - string with error description "ERROR: ........." and set @error to 1 ; Author ........: mLipok @@ -770,19 +805,21 @@ EndFunc ;==>_NetWebView2_BrowserSetupWrapper ; Link ..........: ; Example .......: No ; =============================================================================================================================== -Func _NetWebView2_ExportPageData($oWebV2M, $iFormat, $sFilePath = '') - Local Const $s_Prefix = "[_NetWebView2_ExportPageData]:" & " Format:" & $iFormat & " FilePath:" & (($sFilePath) ? ($sFilePath) : ('"EMPTY"')) +Func _NetWebView2_ExportPageData($oWebV2M, $iFormat, $sFilePath = "") + Local Const $s_Prefix = "[_NetWebView2_ExportPageData]:" & " Format:" & $iFormat & " FilePath:" & (($sFilePath) ? ($sFilePath) : (" is EMPTY")) Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler #forceref $oMyError #TODO $sParameters - search for => "name": "captureSnapshot" ; https://github.com/ChromeDevTools/devtools-protocol/blob/master/json/browser_protocol.json - Local $s_Result = $oWebV2M.ExportPageData($iFormat, $sFilePath) - If StringLeft($s_Result, 6) = 'ERROR:' Then SetError(1) - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " RESULT:" & ((@error) ? ($s_Result) : ("SUCCESS")), 1, $ERR, $EXT) - Return SetError(@error, @extended, $s_Result) + $RET = $oWebV2M.ExportPageData($iFormat, $sFilePath) + If StringLeft($RET, 6) = "ERROR:" Then + $ERR = 1 + $MSG = " RESULT:" & $RET & " #SLN=" & @ScriptLineNumber + Else + $MSG = " RESULT: SUCCESS" & " #SLN=" & @ScriptLineNumber + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_ExportPageData @@ -806,11 +843,9 @@ Func _NetWebView2_GetSource($oWebV2M) Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler #forceref $oMyError - Local $sSource = $oWebV2M.GetSource() - If @error Then __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return SetError(@error, @extended, $sSource) + $RET = $oWebV2M.GetSource() + $ERR = @error - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_GetSource @@ -818,11 +853,11 @@ EndFunc ;==>_NetWebView2_GetSource ; #FUNCTION# ==================================================================================================================== ; Name ..........: _NetWebView2_NavigateToPDF ; Description ...: Navigate to a PDF (local PDF file or online direct URL link to PDF file) -; Syntax ........: _NetWebView2_NavigateToPDF($oWebV2M, $s_URL_or_FilePath[, $s_Parameters = ''[, $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE_CHANGED[, +; Syntax ........: _NetWebView2_NavigateToPDF($oWebV2M, $s_URL_or_FilePath[, $s_Parameters = ""[, $iWaitMessage = $NETWEBVIEW2_MESSAGE__TITLE_CHANGED[, ; $sExpectedTitle = ""[, $iTimeOut_ms = 5000[, $iSleepAfter_ms = 1000[, $bFreeze = True]]]]]]) ; Parameters ....: $oWebV2M - an object. ; $s_URL_or_FilePath - a string value. -; $s_Parameters - [optional] a string value. Default is ''. +; $s_Parameters - [optional] a string value. Default is "". ; $iWaitMessage - [optional] an integer value. Default is $NETWEBVIEW2_MESSAGE__TITLE_CHANGED. ; $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 ; $iTimeOut_ms - [optional] Maximum time to wait in milliseconds. 0 for infinite. Default is 5000ms @@ -836,49 +871,52 @@ EndFunc ;==>_NetWebView2_GetSource ; Link ..........: ; Example .......: No ; =============================================================================================================================== -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) - #TODO suplement => $s_Prefix - Local Const $s_Prefix = "[_NetWebView2_NavigateToPDF]: URL_or_File:" & $s_URL_or_FilePath +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) + Local Const $s_Prefix = "[_NetWebView2_NavigateToPDF]: URL_or_File:" & $s_URL_or_FilePath & " Parameters: " & $s_Parameters & " WaitMessage: " & $iWaitMessage & " ExpectedTitle=" & (($sExpectedTitle) ? ($sExpectedTitle) : (" is EMPTY")) & " TimeOut_ms=" & $iTimeOut_ms & " SleepAfter_ms: " & $iSleepAfter_ms & " Freeze: " & $bFreeze Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(1, 0, "ERROR: Invalid Object") - - If $sExpectedTitle = Default Then - Local $aFilePath = StringSplit($s_URL_or_FilePath, "\") - If @error Then - $sExpectedTitle = '' - Else - $sExpectedTitle = $aFilePath[$aFilePath[0]] - $sExpectedTitle = StringReplace($sExpectedTitle, '(', '\(') - $sExpectedTitle = StringReplace($sExpectedTitle, ')', '\)') - $sExpectedTitle = StringReplace($sExpectedTitle, '.', '\.') + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + Else + If $sExpectedTitle = Default Then + Local $aFilePath = StringSplit($s_URL_or_FilePath, "\") + If @error Then + $sExpectedTitle = "" + Else + $sExpectedTitle = $aFilePath[$aFilePath[0]] + $sExpectedTitle = StringReplace($sExpectedTitle, "(", "\(") + $sExpectedTitle = StringReplace($sExpectedTitle, ")", "\)") + $sExpectedTitle = StringReplace($sExpectedTitle, ".", "\.") + EndIf EndIf - EndIf - If FileExists($s_URL_or_FilePath) Then - $s_URL_or_FilePath = StringReplace($s_URL_or_FilePath, '\', '/') - $s_URL_or_FilePath = StringReplace($s_URL_or_FilePath, ' ', '%20') - $s_URL_or_FilePath = "file:///" & $s_URL_or_FilePath - EndIf + If FileExists($s_URL_or_FilePath) Then ; check if it is local path - yes=change path - otherwise treat as url + $s_URL_or_FilePath = StringReplace($s_URL_or_FilePath, "\", "/") + $s_URL_or_FilePath = StringReplace($s_URL_or_FilePath, " ", "%20") + $s_URL_or_FilePath = "file:///" & $s_URL_or_FilePath + EndIf - If $s_Parameters Then - $s_URL_or_FilePath &= $s_Parameters - #TIP: FitToPage: https://stackoverflow.com/questions/78820187/how-to-change-webview2-fit-to-page-button-on-pdf-toolbar-default-to-fit-to-width#comment138971950_78821231 - #TIP: Open desired PAGE: https://stackoverflow.com/questions/68500164/cycle-pdf-pages-in-wpf-webview2#comment135402565_68566860 - EndIf + If $s_Parameters Then + $s_URL_or_FilePath &= $s_Parameters + #TIP: FitToPage: https://stackoverflow.com/questions/78820187/how-to-change-webview2-fit-to-page-button-on-pdf-toolbar-default-to-fit-to-width#comment138971950_78821231 + #TIP: Open desired PAGE: https://stackoverflow.com/questions/68500164/cycle-pdf-pages-in-wpf-webview2#comment135402565_68566860 + EndIf - Local $idPic = 0 - $oWebV2M.LockWebView() - If $bFreeze Then __NetWebView2_freezer($oWebV2M, $idPic) - _NetWebView2_Navigate($oWebV2M, $s_URL_or_FilePath, $iWaitMessage, $sExpectedTitle, $iTimeOut_ms) - If Not @error Then __NetWebView2_Sleep($iSleepAfter_ms) - If @error Then Return SetError(@error, @extended, '') + Local $idPic = 0 + $oWebV2M.LockWebView() + If $bFreeze Then __NetWebView2_freezer($oWebV2M, $idPic) + _NetWebView2_Navigate($oWebV2M, $s_URL_or_FilePath, $iWaitMessage, $sExpectedTitle, $iTimeOut_ms) + $ERR = @error + $EXT = @extended + If Not @error Then __NetWebView2_Sleep($iSleepAfter_ms) - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - If $bFreeze And $idPic Then __NetWebView2_freezer($oWebV2M, $idPic) - $oWebV2M.UnLockWebView() + If $bFreeze And $idPic Then __NetWebView2_freezer($oWebV2M, $idPic) + $oWebV2M.UnLockWebView() + $RET = True + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_NavigateToPDF @@ -904,19 +942,23 @@ Func _NetWebView2_PrintToPdfStream($oWebV2M, $b_TBinary_FBase64) Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler #forceref $oMyError - Local $s_Result = $oWebV2M.PrintToPdfStream() - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - If StringInStr($s_Result, 'ERROR:') Then SetError(1) - - If $b_TBinary_FBase64 Then - ; decode Base64 encoded data do Binary - $s_Result = _NetWebView2_DecodeB64ToBinary($oWebV2M, $s_Result) + $RET = $oWebV2M.PrintToPdfStream() + If StringInStr($RET, "ERROR:") Then + $ERR = 1 + $MSG = " RESULT: " & $RET & " #SLN=" & @ScriptLineNumber + Else + If $b_TBinary_FBase64 Then + ; decode Base64 encoded data do Binary + $RET = _NetWebView2_DecodeB64ToBinary($oWebV2M, $RET) + $ERR = 2 + EndIf + EndIf + If $ERR Then + $RET = "" + Else + $MSG = " RESULT: SUCCESS" & " #SLN=" & @ScriptLineNumber EndIf - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " RESULT:" & ((@error) ? ($s_Result) : ("SUCCESS")), 1, $ERR, $EXT) - Return SetError(@error, @extended, $s_Result) - - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_PrintToPdfStream @@ -942,16 +984,18 @@ EndFunc ;==>_NetWebView2_PrintToPdfStream Func _NetWebView2_AddInitializationScript($oWebV2M, $vScript) Local Const $s_Prefix = "[_NetWebView2_AddInitializationScript]:" Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(1, 0, "ERROR: Invalid Object") - - ; Smart Detection - If FileExists($vScript) Then $vScript = FileRead($vScript) + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + Else + ; Smart Detection + If FileExists($vScript) Then $vScript = FileRead($vScript) - Local $sScriptId = $oWebV2M.AddInitializationScript($vScript) - If StringInStr($sScriptId, "ERROR:") Then Return SetError(2, 0, $sScriptId) - Return SetError(0, 0, $sScriptId) + $RET = $oWebV2M.AddInitializationScript($vScript) ; Returns a Script ID (string) + If StringInStr($ERR, "ERROR:") Then $ERR = 2 + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_AddInitializationScript @@ -972,13 +1016,18 @@ EndFunc ;==>_NetWebView2_AddInitializationScript ; Example .......: No ; =============================================================================================================================== Func _NetWebView2_RemoveInitializationScript($oWebV2M, $sScriptId) - Local Const $s_Prefix = "[_NetWebView2_AddInitializationScript]:" + Local Const $s_Prefix = "[_NetWebView2_AddInitializationScript]: ScriptId: " & $sScriptId Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(1, 0, False) ; Error 1: Not an object - $oWebV2M.RemoveInitializationScript($sScriptId) - Return SetError(@error, 0, (@error ? False : True)) + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + Else + $oWebV2M.RemoveInitializationScript($sScriptId) + $ERR = @error + $RET = (@error = 0) + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_RemoveInitializationScript @@ -1001,13 +1050,18 @@ EndFunc ;==>_NetWebView2_RemoveInitializationScript ; Example .......: No ; =============================================================================================================================== Func _NetWebView2_SetVirtualHostNameToFolderMapping($oWebV2M, $sHostName, $sFolderPath, $iAccessKind = 0) - Local Const $s_Prefix = "[_NetWebView2_SetVirtualHostNameToFolderMapping]:" + Local Const $s_Prefix = "[_NetWebView2_SetVirtualHostNameToFolderMapping]: HostName: " & $sHostName & " FolderPath: " & $sFolderPath & " AccessKind: " & $iAccessKind Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(1, 0, False) - $oWebV2M.SetVirtualHostNameToFolderMapping($sHostName, $sFolderPath, $iAccessKind) - Return SetError(@error, 0, (@error ? False : True)) + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + Else + $oWebV2M.SetVirtualHostNameToFolderMapping($sHostName, $sFolderPath, $iAccessKind) + $ERR = @error + $RET = (@error = 0) + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_SetVirtualHostNameToFolderMapping @@ -1028,13 +1082,18 @@ EndFunc ;==>_NetWebView2_SetVirtualHostNameToFolderMapping ; Example .......: No ; =============================================================================================================================== Func _NetWebView2_SetLockState($oWebV2M, $bLockState) - Local Const $s_Prefix = "[_NetWebView2_SetLockState]:" + Local Const $s_Prefix = "[_NetWebView2_SetLockState]: LockState: " & $bLockState Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(1, 0, False) - $oWebV2M.SetLockState($bLockState) - Return SetError(@error, 0, (@error ? False : True)) + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + Else + $oWebV2M.SetLockState($bLockState) + $ERR = @error + $RET = (@error = 0) + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_SetLockState @@ -1057,12 +1116,18 @@ EndFunc ;==>_NetWebView2_SetLockState Func _NetWebView2_EncodeBinaryToB64($oWebV2M, ByRef $dBinary) Local Const $s_Prefix = "[_NetWebView2_EncodeBinaryToB64]:" Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(1, 0, "") - Local $sResult = $oWebV2M.EncodeBinaryToB64($dBinary) - If @error Then Return SetError(@error, 0, "") - Return SetError(0, 0, $sResult) + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + Else + $RET = $oWebV2M.EncodeBinaryToB64($dBinary) + If @error Then + $ERR = @error + $RET = "" + EndIf + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_EncodeBinaryToB64 @@ -1085,12 +1150,23 @@ EndFunc ;==>_NetWebView2_EncodeBinaryToB64 Func _NetWebView2_DecodeB64ToBinary($oWebV2M, ByRef $sB64) Local Const $s_Prefix = "[_NetWebView2_DecodeB64ToBinary]:" Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(1, 0, Binary("")) - Local $dResult = $oWebV2M.DecodeB64ToBinary($sB64) - If @error Then Return SetError(@error, 0, Binary("")) - Return SetError(0, 0, $dResult) - #TODO ENDPOINT REFACTORING + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $EXT = 1 + $RET = Binary("") + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + Else + Local $dResult = $oWebV2M.DecodeB64ToBinary($sB64) + If @error Then + $ERR = @error + $EXT = 2 + $RET = Binary("") + Else + $RET = $dResult + EndIf + EndIf + __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_DecodeB64ToBinary @@ -1111,13 +1187,18 @@ EndFunc ;==>_NetWebView2_DecodeB64ToBinary ; Example .......: No ; =============================================================================================================================== Func _NetWebView2_SetBuiltInErrorPageEnabled($oWebV2M, $bEnabled) - Local Const $s_Prefix = "[_NetWebView2_SetBuiltInErrorPageEnabled]:" + Local Const $s_Prefix = "[_NetWebView2_SetBuiltInErrorPageEnabled]: Enabled: " & $bEnabled Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(1, 0, False) - $oWebV2M.IsBuiltInErrorPageEnabled = $bEnabled - Return SetError(@error, 0, (@error ? False : True)) + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + Else + $oWebV2M.IsBuiltInErrorPageEnabled = $bEnabled + $ERR = @error + $RET = (@error = 0) + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_SetBuiltInErrorPageEnabled @@ -1128,21 +1209,27 @@ EndFunc ;==>_NetWebView2_SetBuiltInErrorPageEnabled ; Syntax ........: _NetWebView2_GetFrame($oWebV2M, $iIndex) ; Parameters ....: $oWebV2M - an object. ; $iIndex - an int value. -; Return values .: Frame Object or Null +; Return values .: Success - Frame Object +; Failure - Null and sets @error ; Author ........: ioa747 -; Modified ......: +; Modified ......: mLipok ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _NetWebView2_GetFrame($oWebV2M, $iIndex) - Local Const $s_Prefix = "[_NetWebView2_GetFrame]:" + Local Const $s_Prefix = "[_NetWebView2_GetFrame]: Index: " & $iIndex Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - Local $oFrame = $oWebV2M.GetFrame($iIndex) - Return SetError(@error, @extended, $oFrame) + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $RET = Null + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + Else + $RET = $oWebV2M.GetFrame($iIndex) + $ERR = @error + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetWebView2_GetFrame @@ -1155,7 +1242,7 @@ EndFunc ;==>_NetWebView2_GetFrame ; Return values .: Success - Clean HTML string. ; Failure - Sets @error and returns empty string. ; Author ........: ioa747 -; Modified ......: +; Modified ......: mLipok ; Remarks .......: ; Related .......: ; Link ..........: @@ -1164,32 +1251,40 @@ EndFunc ;==>_NetWebView2_GetFrame Func _WebView2_FrameGetHtmlSource($oFrame) Local Const $s_Prefix = "[_WebView2_FrameGetHtmlSource]:" Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If Not IsObj($oFrame) Then Return SetError(1, 0, "") - - ; Execute script synchronously - Local $sRaw = $oFrame.ExecuteScriptWithResult("document.documentElement.outerHTML") - - ; Basic validation - If $sRaw = "null" Or $sRaw = "" Then Return "" - If StringLeft($sRaw, 6) = "ERROR:" Then Return SetError(2, 0, "") + If Not IsObj($oFrame) Then + $ERR = 1 + $RET = "" + Else + ; Execute script synchronously + Local $sRaw = $oFrame.ExecuteScriptWithResult("document.documentElement.outerHTML") + + ; Basic validation + If $sRaw = "null" Or $sRaw = "" Then + $ERR = 1 + $RET = "" + ElseIf StringLeft($sRaw, 6) = "ERROR:" Then + $ERR = 2 + $RET = $sRaw + Else + ; Pre-process: Strip the mandatory JSON quotes BEFORE unescaping. + ; This prevents the C# Parser from "double-wrapping" the string. + If StringLeft($sRaw, 1) = '"' And StringRight($sRaw, 1) = '"' Then + $sRaw = StringMid($sRaw, 2, StringLen($sRaw) - 2) + EndIf - ; Pre-process: Strip the mandatory JSON quotes BEFORE unescaping. - ; This prevents the C# Parser from "double-wrapping" the string. - If StringLeft($sRaw, 1) = '"' And StringRight($sRaw, 1) = '"' Then - $sRaw = StringMid($sRaw, 2, StringLen($sRaw) - 2) + ; Initialize Parser from the library + Local $oJson = _NetJson_CreateParser() + If @error Then + $ERR = 3 + $RET = "" + Else + ; Use the Parser's UnescapeString to handle all escapes (\uXXXX, \n, \", etc.) + $RET = $oJson.UnescapeString($sRaw) + $ERR = @error + EndIf + EndIf EndIf - ; Initialize Parser from the library - Local $oJson = _NetJson_CreateParser() - If @error Then Return SetError(3, 0, "") - - ; Use the Parser's UnescapeString to handle all escapes (\uXXXX, \n, \", etc.) - Local $sClean = $oJson.UnescapeString($sRaw) - - Return $sClean - - - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_WebView2_FrameGetHtmlSource @@ -1219,14 +1314,15 @@ Func _NetJson_CreateParser($sInitialJson = "{}") If $sInitialJson = "" Or $sInitialJson = Default Then $sInitialJson = "{}" Local $oParser = ObjCreate("NetWebView2Lib.WebView2Parser") ; REGISTERED VERSION ;~ If $_g_bNetWebView2_DebugDev Then __NetWebView2_ObjName_FlagsValue($oParser) ; FOR DEV TESTING ONLY - If Not IsObj($oParser) Then Return SetError(1, 0, 0) - If @error Then Return SetError(@error, @extended, 0) - - $oParser.Parse($sInitialJson) - If @error Then __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return $oParser + If @error Or Not IsObj($oParser) Then + $ERR = 1 + $RET = 0 + Else + $oParser.Parse($sInitialJson) + $ERR = @error + $RET = $oParser + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetJson_CreateParser @@ -1252,15 +1348,18 @@ Func _NetJson_DecodeB64($sData) Local $oJson = _NetJson_CreateParser() If @error Then - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return SetError(@error, @extended, $oJson) + $ERR = @error + $EXT = @extended + $RET = $oJson + Else + Local $dBinary = $oJson.Decode64($sData) + If @error Then + $ERR = @error + $EXT = @extended + EndIf + $RET = $dBinary EndIf - Local $dBinary = $oJson.Decode64($sData) - If @error Then __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return SetError(@error, @extended, $dBinary) - - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetJson_DecodeB64 @@ -1270,7 +1369,7 @@ EndFunc ;==>_NetJson_DecodeB64 ; Description ...: ; Syntax ........: _NetJson_EncodeB64($sData) ; Parameters ....: $sData - a string value. -; Return values .: None +; Return values .: #TODO ; Author ........: mLipok ; Modified ......: ; Remarks .......: @@ -1286,15 +1385,18 @@ Func _NetJson_EncodeB64($sData) Local $oJson = _NetJson_CreateParser() If @error Then - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return SetError(@error, @extended, $oJson) + $ERR = @error + $EXT = 1 + $RET = $oJson + Else + Local $vResult = $oJson.EncodeB64($sData) + If @error Then + $ERR = @error + $EXT = 2 + EndIf + $RET = $vResult EndIf - Local $vResult = $oJson.EncodeB64($sData) - If @error Then __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1, $ERR, $EXT) - Return SetError(@error, @extended, $vResult) - - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>_NetJson_EncodeB64 @@ -1323,7 +1425,7 @@ EndFunc ;==>__NetWebView2_Sleep ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __NetWebView2_WaitForReadyState -; Description ...: Polls the browser until the document.readyState reaches 'complete'. +; Description ...: Polls the browser until the document.readyState reaches "complete". ; Syntax ........: __NetWebView2_WaitForReadyState($oWebV2M, $hTimer[, $iTimeOut_ms = 5000]) ; Parameters ....: $oWebV2M - The WebView2 Manager object. ; $hTimer - a handle to a caller TimerInit @@ -1335,44 +1437,53 @@ EndFunc ;==>__NetWebView2_Sleep ; Author ........: ioa747, mLipok ; Modified.......: ; Remarks .......: This function uses JavaScript execution to check the internal state of the page. -; Useful for tasks like PDF printing where 'complete' state is mandatory. +; Useful for tasks like PDF printing where "complete" state is mandatory. ; =============================================================================================================================== Func __NetWebView2_WaitForReadyState($oWebV2M, $hTimer, $iTimeOut_ms = 5000) - Local Const $s_Prefix = ">>>[_NetWebView2_WaitForReadyState]:" + Local Const $s_Prefix = ">>>[__NetWebView2_WaitForReadyState]: TimeOut_ms: " & $iTimeOut_ms Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results - If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(2, 0, False) + If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> "NetWebView2Lib.WebView2Manager" Then ; Error 1: Not an object + $ERR = 1 + $RET = False + $MSG = " Invalid Object Error" & " #SLN=" & @ScriptLineNumber + EndIf Local $sReadyState = "" While 1 ; Execute JS via the Bridge (Mode 2) $sReadyState = _NetWebView2_ExecuteScript($oWebV2M, "document.readyState", $NETWEBVIEW2_EXECUTEJS_MODE2_RESULT) - If @error Then Return SetError(@error, @extended, False) - - ; Check for the 'complete' state - If $sReadyState == "complete" Then - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " SUCCESS: Document is ready. Timeout_ms: " & Round(TimerDiff($hTimer), 0), 0, $ERR, $EXT) - Return True - EndIf - - ; Check for C# Bridge internal errors (Timeout/Init) - If StringLeft($sReadyState, 6) == "ERROR:" Then - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " BRIDGE " & $sReadyState & " Timeout_ms: " & Round(TimerDiff($hTimer), 0), 1, $ERR, $EXT) - Return SetError(3, 0, False) - EndIf - - ; Check for AutoIt-side Timeout - If $iTimeOut_ms > 0 And TimerDiff($hTimer) > $iTimeOut_ms Then - __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " TIMEOUT: Document state is " & $sReadyState & " Timeout_ms: " & Round(TimerDiff($hTimer), 0), 1, $ERR, $EXT) - Return SetError(1, 0, False) + If @error Then + $ERR = @error + $EXT = @extended + $RET = False + ExitLoop + ElseIf $sReadyState == "complete" Then ; Check for the "complete" state + $RET = True + $MSG = " SUCCESS: Document is ready. Timeout_ms: " & Round(TimerDiff($hTimer), 0) & " #SLN=" & @ScriptLineNumber + ExitLoop + ElseIf StringLeft($sReadyState, 6) == "ERROR:" Then ; Check for C# Bridge internal errors (Timeout/Init) + $ERR = 3 + $RET = False + $MSG = " BRIDGE " & $sReadyState & " Timeout_ms: " & Round(TimerDiff($hTimer), 0) & " #SLN=" & @ScriptLineNumber + ExitLoop + ElseIf $iTimeOut_ms > 0 And TimerDiff($hTimer) > $iTimeOut_ms Then ; Check for AutoIt-side Timeout + $ERR = 1 + $RET = False + $MSG = " TIMEOUT: Document state is " & $sReadyState & " Timeout_ms: " & Round(TimerDiff($hTimer), 0) & " #SLN=" & @ScriptLineNumber + ExitLoop + Else + __NetWebView2_Sleep(50) + If @error Then + $ERR = @error + $EXT = @extended + $RET = False + ExitLoop + EndIf EndIf - __NetWebView2_Sleep(50) - If @error Then Return SetError(@error, @extended, '') WEnd - - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>__NetWebView2_WaitForReadyState @@ -1393,7 +1504,7 @@ EndFunc ;==>__NetWebView2_WaitForReadyState ; Example .......: No ; =============================================================================================================================== Func __NetWebView2_LastMessage_KEEPER($oWebV2M, $iMessage = Default, $iError = @error, $iExtended = @extended) - Local Const $s_Prefix = "[__NetWebView2_LastMessage_KEEPER]:" + Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage_KEEPER]: Message: " & $iMessage Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results ; Static Map - The central database of status indexed by Window Handle ; Local COM Error Handler to trap 0x80020009 (Disposed Object) during closure @@ -1402,24 +1513,26 @@ Func __NetWebView2_LastMessage_KEEPER($oWebV2M, $iMessage = Default, $iError = @ Local Static $mLastMessegKeeper[] Local $sKey = "" & $oWebV2M.BrowserWindowHandle - If $iMessage <> Default Then - __NetWebView2_LastMessage__INTERNALL($mLastMessegKeeper, $sKey, $iMessage, $iError = @error, $iExtended = @extended) + If $iMessage = Default Then ; function acts as GET + $RET = $mLastMessegKeeper[$sKey] + Else +;~ __NetWebView2_LastMessage__INTERNALL($mLastMessegKeeper, $sKey, $iMessage, @error, @extended) + #TODO $sKey support int __NetWebView2_LastMessage_onReceived - multi instances __NetWebView2_LastMessage_onReceived($oWebV2M, $iMessage) + #TODO $sKey support int __NetWebView2_LastMessage_Navigation - multi instances __NetWebView2_LastMessage_Navigation($oWebV2M, $iMessage) - Return SetError($iError, $iExtended) - Else - Return SetError($iError, $iExtended, $mLastMessegKeeper[$sKey]) EndIf + $ERR = $iError ; prevent @error changes + $EXT = $iExtended ; prevent @extended changes - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>__NetWebView2_LastMessage_KEEPER Func __NetWebView2_LastMessage_onReceived($oWebV2M, $iMessage = Default, $iError = @error, $iExtended = @extended) - Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage_onReceived]:" + Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage_onReceived]: Message: " & $iMessage Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results ; Static Map - The central database of status indexed by Window Handle ; Local COM Error Handler to trap 0x80020009 (Disposed Object) during closure @@ -1429,20 +1542,22 @@ Func __NetWebView2_LastMessage_onReceived($oWebV2M, $iMessage = Default, $iError Local Static $mLastMessegReceived[] Local $sKey = "" & $oWebV2M.BrowserWindowHandle - If $iMessage <> Default Then - If $_g_bNetWebView2_DebugDev Then ConsoleWrite('! IFNC: __NetWebView2_LastMessage_onReceived ==> ' & $iMessage & ' Key=' & $sKey & ' SLN=' & @ScriptLineNumber & @CRLF) - __NetWebView2_LastMessage__INTERNALL($mLastMessegReceived, $sKey, $iMessage, $iError = @error, $iExtended = @extended) + If $iMessage = Default Then ; function acts as GET + $RET = $mLastMessegReceived[$sKey] + Else + If $_g_bNetWebView2_DebugDev Then ConsoleWrite("! IFNC: DEV: [__NetWebView2_LastMessage_onReceived] ==> " & $iMessage & " Key=" & $sKey & " #SLN=" & @ScriptLineNumber & @CRLF) + __NetWebView2_LastMessage__INTERNALL($mLastMessegReceived, $sKey, $iMessage, @error, @extended) EndIf - Return SetError($iError, $iExtended, $mLastMessegReceived[$sKey]) + $ERR = $iError ; prevent @error changes + $EXT = $iExtended ; prevent @extended changes - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>__NetWebView2_LastMessage_onReceived Func __NetWebView2_LastMessage_Navigation($oWebV2M, $iMessage = Default, $iError = @error, $iExtended = @extended) - Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage_Navigation]:" + Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage_Navigation]: Message: " & $iMessage Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results ; Static Map - The central database of status indexed by Window Handle ; Local COM Error Handler to trap 0x80020009 (Disposed Object) during closure @@ -1451,48 +1566,56 @@ Func __NetWebView2_LastMessage_Navigation($oWebV2M, $iMessage = Default, $iError Local Static $mLastNavigationMessage[] Local $sKey = "" & $oWebV2M.BrowserWindowHandle - If $iMessage <> Default Then + If $iMessage = Default Then ; function acts as GET + $RET = $mLastNavigationMessage[$sKey] + Else If $iMessage >= $NETWEBVIEW2_MESSAGE__NAV_STARTING And $iMessage <= $NETWEBVIEW2_MESSAGE__TITLE_CHANGED Then - If $_g_bNetWebView2_DebugDev Then ConsoleWrite('! IFNC: __NetWebView2_LastMessage_Navigation ==> ' & $iMessage & ' Key=' & $sKey & ' SLN=' & @ScriptLineNumber & @CRLF) - __NetWebView2_LastMessage__INTERNALL($mLastNavigationMessage, $sKey, $iMessage, $iError = @error, $iExtended = @extended) + If $_g_bNetWebView2_DebugDev Then ConsoleWrite("! IFNC: DEV: [__NetWebView2_LastMessage_Navigation] ==> " & $iMessage & " Key=" & $sKey & " #SLN=" & @ScriptLineNumber & @CRLF) + __NetWebView2_LastMessage__INTERNALL($mLastNavigationMessage, $sKey, $iMessage, @error, @extended) EndIf EndIf - Return SetError($iError, $iExtended, $mLastNavigationMessage[$sKey]) - #TODO ENDPOINT REFACTORING + $ERR = $iError ; prevent @error changes + $EXT = $iExtended ; prevent @extended changes + __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>__NetWebView2_LastMessage_Navigation Func __NetWebView2_LastMessage__INTERNALL(ByRef $mStatus, $sKey, $iMessage = Default, $iError = @error, $iExtended = @extended) - Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage__INTERNALL]:" + Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage__INTERNALL]: Key:" & $sKey & " Message: " & $iMessage Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results +;~ $sKey = StringRegExpReplace($sKey, "(?i)(.*?)(\d[\dxa-f]+)(.*)", "$2") ; example: [HANDLE:0x0000000000240C00] >> 0x0000000000240C00 +;~ $sKey = "hwnd" & StringRegExpReplace($sKey, "(?i)(.*?\dx)([\da-f]+)(.*)", "$2") ; example: [HANDLE:0x0000000000240C00] >> 0000000000240C00 - ; If an error occurred while retrieving the Handle (e.g. Object already closed) - If @error Then Return SetError($iError, $iExtended, $NETWEBVIEW2_MESSAGE__NONE) - - ; If the handle is invalid - If $sKey = "0" Or $sKey = "" Then Return SetError($iError, $iExtended, $NETWEBVIEW2_MESSAGE__NONE) - - ; --- SET MODE (Called from Events or Cleanup) --- - If $iMessage <> Default Then - ; Special case: -1 for memory cleanup when the instance is closed - If $iMessage = -1 Then - If MapExists($mStatus, $sKey) Then MapRemove($mStatus, $sKey) - Return SetError($iError, $iExtended, $NETWEBVIEW2_MESSAGE__NONE) - EndIf - - ; Update the status for this specific Handle + If $iError Then ; If an error occurred while retrieving the Handle (e.g. Object already closed) + #TODO REFACTOR: this check should be out of this function + $ERR = 1 + $RET = $NETWEBVIEW2_MESSAGE__NONE + $MSG = " OUTER ERROR" & " #SLN=" & @ScriptLineNumber + ElseIf $sKey = "0" Or $sKey = "" Then ; If the handle is invalid + $ERR = 2 + $RET = $NETWEBVIEW2_MESSAGE__NONE + $MSG = " Invalid KEY value" & " #SLN=" & @ScriptLineNumber + ElseIf ($iMessage = -1 Or $iMessage = Default) And Not MapExists($mStatus, $sKey) Then ; for RESET and GET key must exist + $ERR = 3 + $RET = $NETWEBVIEW2_MESSAGE__NONE + $MSG = " KEY=" & $sKey & " (BrowserWindowHandle) NOT FOUND" & " #SLN=" & @ScriptLineNumber + ElseIf $iMessage = -1 Then ; If -1, performs cleanup ; Special case: -1 for memory cleanup when the instance is closed + MapRemove($mStatus, $sKey) + $RET = $NETWEBVIEW2_MESSAGE__NONE + ElseIf $iMessage = Default Then ; --- GET MODE (Called from LoadWait) --- + $RET = $mStatus[$sKey] + Else ; Update the status for this specific Handle $mStatus[$sKey] = $iMessage - Return SetError($iError, $iExtended, $iMessage) + $RET = $iMessage EndIf - ; --- GET MODE (Called from LoadWait) --- - If Not MapExists($mStatus, $sKey) Then Return SetError($iError, $iExtended, $NETWEBVIEW2_MESSAGE__NONE) - - Return SetError($iError, $iExtended, $mStatus[$sKey]) + If Not $ERR Then + $ERR = $iError ; prevent @error changes + $EXT = $iExtended ; prevent @extended changes + EndIf - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>__NetWebView2_LastMessage__INTERNALL @@ -1518,9 +1641,9 @@ Func __NetWebView2_Log($s_ScriptLineNumber, $sString, $iErrorNoLineNo = 1, $iErr If Not $_g_bNetWebView2_DebugInfo Then Return SetError($iError, $iExtended, 0) If $iErrorNoLineNo = 1 Then If $iError Then - $sString = "! ( NetWebView2Lib UDF : SLN=" & $s_ScriptLineNumber & ", @error=" & $iError & ", @extended=" & $iExtended & " ) :: " & $sString + $sString = "! ( NetWebView2Lib UDF : #SLN=" & $s_ScriptLineNumber & ", @error=" & $iError & ", @extended=" & $iExtended & " ) :: " & $sString Else - $sString = "+> ( NetWebView2Lib UDF : SLN=" & $s_ScriptLineNumber & " ) :: " & $sString + $sString = "+> ( NetWebView2Lib UDF : #SLN=" & $s_ScriptLineNumber & " ) :: " & $sString EndIf EndIf ConsoleWrite($sString & @CRLF) @@ -1541,32 +1664,32 @@ EndFunc ;==>__NetWebView2_Log ; Example .......: No ; =============================================================================================================================== Func __NetWebView2_ObjName_FlagsValue($oObj) - Local $sInfo = '' - $sInfo &= '+>' & @TAB & 'ObjName($oObj,1) {The name of the Object} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_NAME) & @CRLF + Local $sInfo = "" + $sInfo &= "+>" & @TAB & "ObjName($oObj,1) {The name of the Object} =" & @CRLF & @TAB & ObjName($oObj, $OBJ_NAME) & @CRLF ; HELPFILE REMARKS: Not all Objects support flags 2 to 7. Always test for @error in these cases. - $sInfo &= '+>' & @TAB & 'ObjName($oObj,2) {Description string of the Object} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_STRING) - If @error Then $sInfo &= '@error = ' & @error + $sInfo &= "+>" & @TAB & "ObjName($oObj,2) {Description string of the Object} =" & @CRLF & @TAB & ObjName($oObj, $OBJ_STRING) + If @error Then $sInfo &= "@error = " & @error $sInfo &= @CRLF & @CRLF - $sInfo &= '+>' & @TAB & 'ObjName($oObj,3) {The ProgID of the Object} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_PROGID) - If @error Then $sInfo &= '@error = ' & @error + $sInfo &= "+>" & @TAB & "ObjName($oObj,3) {The ProgID of the Object} =" & @CRLF & @TAB & ObjName($oObj, $OBJ_PROGID) + If @error Then $sInfo &= "@error = " & @error $sInfo &= @CRLF & @CRLF - $sInfo &= '+>' & @TAB & 'ObjName($oObj,4) {The file that is associated with the object in the Registry} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_FILE) - If @error Then $sInfo &= '@error = ' & @error + $sInfo &= "+>" & @TAB & "ObjName($oObj,4) {The file that is associated with the object in the Registry} =" & @CRLF & @TAB & ObjName($oObj, $OBJ_FILE) + If @error Then $sInfo &= "@error = " & @error $sInfo &= @CRLF & @CRLF - $sInfo &= '+>' & @TAB & 'ObjName($oObj,5) {Module name in which the object runs (WIN XP And above). Marshaller for non-inproc objects.} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_MODULE) - If @error Then $sInfo &= '@error = ' & @error + $sInfo &= "+>" & @TAB & "ObjName($oObj,5) {Module name in which the object runs (WIN XP And above). Marshaller for non-inproc objects.} =" & @CRLF & @TAB & ObjName($oObj, $OBJ_MODULE) + If @error Then $sInfo &= "@error = " & @error $sInfo &= @CRLF & @CRLF - $sInfo &= '+>' & @TAB & 'ObjName($oObj,6) {CLSID of the object''s coclass} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_CLSID) - If @error Then $sInfo &= '@error = ' & @error + $sInfo &= "+>" & @TAB & "ObjName($oObj,6) {CLSID of the object""s coclass} =" & @CRLF & @TAB & ObjName($oObj, $OBJ_CLSID) + If @error Then $sInfo &= "@error = " & @error $sInfo &= @CRLF & @CRLF - $sInfo &= '+>' & @TAB & 'ObjName($oObj,7) {IID of the object''s interface} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_IID) - If @error Then $sInfo &= '@error = ' & @error + $sInfo &= "+>" & @TAB & "ObjName($oObj,7) {IID of the object""s interface} =" & @CRLF & @TAB & ObjName($oObj, $OBJ_IID) + If @error Then $sInfo &= "@error = " & @error $sInfo &= @CRLF & @CRLF ConsoleWrite($sInfo & @CRLF) @@ -1677,52 +1800,50 @@ EndFunc ;==>__Get_Core_Bridge_JS ; Example .......: No ; =============================================================================================================================== Func __NetWebView2_freezer($oWebV2M, ByRef $idPic) - Local Const $s_Prefix = "[__NetWebView2_freezer]:" + Local Const $s_Prefix = ">>>[__NetWebView2_freezer]:" Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results + Local $hWindow_WebView2 = WinGetHandle($oWebV2M.BrowserWindowHandle) - #Region ; if $idPic is given then it means you already have it and want to delete it - unfreeze - show WebView2 content - If $idPic Then - WinSetState($hWindow_WebView2, '', @SW_SHOW) + + If $idPic Then ; if $idPic is given then it means you already have it and want to delete it - unfreeze - show WebView2 content + WinSetState($hWindow_WebView2, "", @SW_SHOW) GUICtrlDelete($idPic) - $idPic = 0 - Return + $RET = 0 + Else + #Region ; freeze $hWindow_WebView2 + + #Region ; add PIC to parent window + Local $hWindow_Parent = WinGetHandle($oWebV2M.ParentWindowHandle) + Local $aPos = WinGetPos($hWindow_WebView2) + Local $hPrev = GUISwitch($hWindow_Parent) + $idPic = GUICtrlCreatePic("", 0, 0, $aPos[2], $aPos[3]) + Local $hPic = GUICtrlGetHandle($idPic) + GUISwitch($hPrev) + #EndRegion ; add PIC to parent window + + Local $hPictureDC = _WinAPI_GetDC($hPic) + + ; Create Dest bitmap + Local $hDestination_DC = _WinAPI_CreateCompatibleDC($hPictureDC) ; Creates a memory device context compatible with the specified device + Local $hDestination_Bitmap = _WinAPI_CreateCompatibleBitmap($hPictureDC, $aPos[2], $aPos[3]) ; Creates a bitmap compatible with the specified device context + Local $hDestination_Sv = _WinAPI_SelectObject($hDestination_DC, $hDestination_Bitmap) ; Selects an object into the specified device context + + Local Const $PW_RENDERFULLCONTENT = 0x2 ; this will go to where it should =) + _WinAPI_PrintWindow($hWindow_WebView2, $hDestination_DC, $PW_RENDERFULLCONTENT) ; print window to destination Window DC ; https://www.autoitscript.com/forum/topic/153782-help-filedocumentation-issues-discussion-only/page/40/#findComment-1549380 + + _WinAPI_ReleaseDC($hPic, $hPictureDC) + _WinAPI_SelectObject($hDestination_DC, $hDestination_Sv) + _WinAPI_DeleteDC($hDestination_DC) + + ; Set bitmap to control + _SendMessage($hPic, $STM_SETIMAGE, 0, $hDestination_Bitmap) + _WinAPI_DeleteObject($hDestination_Bitmap) + + WinSetState($hWindow_WebView2, "", @SW_HIDE) + $RET = $idPic + #EndRegion ; freeze $hWindow_WebView2 EndIf - #EndRegion ; if $idPic is given then it means you already have it and want to delete it - unfreeze - show WebView2 content - - #Region ; freeze $hWindow_WebView2 - - #Region ; add PIC to parent window - Local $hWindow_Parent = WinGetHandle($oWebV2M.ParentWindowHandle) - Local $aPos = WinGetPos($hWindow_WebView2) - Local $hPrev = GUISwitch($hWindow_Parent) - $idPic = GUICtrlCreatePic('', 0, 0, $aPos[2], $aPos[3]) - Local $hPic = GUICtrlGetHandle($idPic) - GUISwitch($hPrev) - #EndRegion ; add PIC to parent window - - Local $hPictureDC = _WinAPI_GetDC($hPic) - - ; Create Dest bitmap - Local $hDestination_DC = _WinAPI_CreateCompatibleDC($hPictureDC) ; Creates a memory device context compatible with the specified device - Local $hDestination_Bitmap = _WinAPI_CreateCompatibleBitmap($hPictureDC, $aPos[2], $aPos[3]) ; Creates a bitmap compatible with the specified device context - Local $hDestination_Sv = _WinAPI_SelectObject($hDestination_DC, $hDestination_Bitmap) ; Selects an object into the specified device context - - Local Const $PW_RENDERFULLCONTENT = 0x2 ; this will go to where it should =) - _WinAPI_PrintWindow($hWindow_WebView2, $hDestination_DC, $PW_RENDERFULLCONTENT) ; print window to destination Window DC ; https://www.autoitscript.com/forum/topic/153782-help-filedocumentation-issues-discussion-only/page/40/#findComment-1549380 - - _WinAPI_ReleaseDC($hPic, $hPictureDC) - _WinAPI_SelectObject($hDestination_DC, $hDestination_Sv) - _WinAPI_DeleteDC($hDestination_DC) - - ; Set bitmap to control - _SendMessage($hPic, $STM_SETIMAGE, 0, $hDestination_Bitmap) - _WinAPI_DeleteObject($hDestination_Bitmap) - - WinSetState($hWindow_WebView2, '', @SW_HIDE) - Return $idPic - #EndRegion ; freeze $hWindow_WebView2 - #TODO ENDPOINT REFACTORING __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT) Return SetError($ERR, $EXT, $RET) EndFunc ;==>__NetWebView2_freezer @@ -1801,7 +1922,7 @@ EndFunc ;==>__NetWebView2_fake_COMErrFunc ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnMessageReceived($oWebV2M, $hGUI, $sMsg) - Local Const $s_Prefix = "[EVENT: OnMessageReceived]: GUI:" & $hGUI + Local Const $s_Prefix = ">>>[EVENT: OnMessageReceived]: GUI:" & $hGUI #Region ; Message parsing ;~ https://github.com/ioa747/NetWebView2Lib/pull/85#issuecomment-3890305808 @@ -1818,7 +1939,7 @@ Volatile Func __NetWebView2_Events__OnMessageReceived($oWebV2M, $hGUI, $sMsg) Local Static $sCommand_static = "" If $_g_bNetWebView2_DebugDev And $sCommand_static <> $sCommand Then ; show the log - for DEV only -;~ ConsoleWrite("TEST IFNC: " & $s_Prefix & " @SLN=" & @ScriptLineNumber & " " & $sCommand & " Data=" & (StringLen($sData) > 120 ? StringLeft($sData, 120) & "..." : $sData) & @CRLF) ; FOR DEV TESTING ONLY +;~ ConsoleWrite("! IFNC: " & $s_Prefix & " #SLN=" & @ScriptLineNumber & " " & $sCommand & " Data=" & (StringLen($sData) > 120 ? StringLeft($sData, 120) & "..." : $sData) & @CRLF) ; FOR DEV TESTING ONLY $sCommand_static = $sCommand EndIf #EndRegion ; Message parsing @@ -1869,9 +1990,9 @@ Volatile Func __NetWebView2_Events__OnMessageReceived($oWebV2M, $hGUI, $sMsg) EndIf ; 🚧 ******************************************* - If $_g_bNetWebView2_DebugInfo Then - ConsoleWrite("> TEST NAV_ERR: " & $sMsg & @CRLF) - ConsoleWrite("> TEST NAV_ERR: __NetWebView2_LastMessage_KEEPER($oWebV2M)=" & __NetWebView2_LastMessage_KEEPER($oWebV2M) & " SLN=" & @ScriptLineNumber & @CRLF) + If $_g_bNetWebView2_DebugDev Then + ConsoleWrite("! IFNC: DEV: NAV_ERR: " & $sMsg & @CRLF) + ConsoleWrite("! IFNC: DEV: NAV_ERR: __NetWebView2_LastMessage_KEEPER($oWebV2M)=" & __NetWebView2_LastMessage_KEEPER($oWebV2M) & " #SLN=" & @ScriptLineNumber & @CRLF) EndIf Case "NAV_COMPLETED" @@ -2094,7 +2215,7 @@ EndFunc ;==>__NetWebView2_JSEvents__OnMessageReceived ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnBrowserGotFocus($oWebV2M, $hGUI, $iReason) - Local Const $s_Prefix = "[EVENT: OnBrowserGotFocus]: GUI:" & $hGUI & " REASON: " & $iReason + Local Const $s_Prefix = ">>>[EVENT: OnBrowserGotFocus]: GUI:" & $hGUI & " REASON: " & $iReason __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__BROWSER_GOT_FOCUS) EndFunc ;==>__NetWebView2_Events__OnBrowserGotFocus @@ -2115,7 +2236,7 @@ EndFunc ;==>__NetWebView2_Events__OnBrowserGotFocus ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnBrowserLostFocus($oWebV2M, $hGUI, $iReason) - Local Const $s_Prefix = "[EVENT: OnBrowserLostFocus]: GUI:" & $hGUI & " REASON: " & $iReason + Local Const $s_Prefix = ">>>[EVENT: OnBrowserLostFocus]: GUI:" & $hGUI & " REASON: " & $iReason __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__BROWSER_LOST_FOCUS) EndFunc ;==>__NetWebView2_Events__OnBrowserLostFocus @@ -2136,7 +2257,7 @@ EndFunc ;==>__NetWebView2_Events__OnBrowserLostFocus ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnZoomChanged($oWebV2M, $hGUI, $iFactor) - Local Const $s_Prefix = "[EVENT: OnZoomChanged]: GUI:" & $hGUI & " FACTOR: " & $iFactor + Local Const $s_Prefix = ">>>[EVENT: OnZoomChanged]: GUI:" & $hGUI & " FACTOR: " & $iFactor __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__ZOOM_CHANGED) EndFunc ;==>__NetWebView2_Events__OnZoomChanged @@ -2157,7 +2278,7 @@ EndFunc ;==>__NetWebView2_Events__OnZoomChanged ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnURLChanged($oWebV2M, $hGUI, $sURL) - Local Const $s_Prefix = "[EVENT: OnURLChanged]: GUI:" & $hGUI & " URL: " & $sURL + Local Const $s_Prefix = ">>>[EVENT: OnURLChanged]: GUI:" & $hGUI & " URL: " & $sURL __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__URL_CHANGED) EndFunc ;==>__NetWebView2_Events__OnURLChanged @@ -2178,10 +2299,10 @@ EndFunc ;==>__NetWebView2_Events__OnURLChanged ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnTitleChanged($oWebV2M, $hGUI, $sTITLE) - Local Const $s_Prefix = "[EVENT: OnTitleChanged]: GUI:" & $hGUI & " TITLE: " & $sTITLE + Local Const $s_Prefix = ">>>[EVENT: OnTitleChanged]: GUI:" & $hGUI & " TITLE: " & $sTITLE __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__TITLE_CHANGED) - If $_g_bNetWebView2_DebugDev Then ConsoleWrite("> IFNC: TEST LOAD WAIT: __NetWebView2_LastMessage_Navigation($oWebV2M)=" & __NetWebView2_LastMessage_Navigation($oWebV2M) & ' SLN=' & @ScriptLineNumber & @CRLF) + If $_g_bNetWebView2_DebugDev Then ConsoleWrite("! IFNC: DEV: TEST LOAD WAIT: __NetWebView2_LastMessage_Navigation($oWebV2M)=" & __NetWebView2_LastMessage_Navigation($oWebV2M) & " #SLN=" & @ScriptLineNumber & @CRLF) EndFunc ;==>__NetWebView2_Events__OnTitleChanged ; #INTERNAL_USE_ONLY# =========================================================================================================== @@ -2201,7 +2322,7 @@ EndFunc ;==>__NetWebView2_Events__OnTitleChanged ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnNavigationStarting($oWebV2M, $hGUI, $oArgs) Local $sURL = $oArgs.Uri - Local Const $s_Prefix = "[EVENT: OnNavigationStarting]: GUI:" & $hGUI & " URL: " & $sURL + Local Const $s_Prefix = ">>>[EVENT: OnNavigationStarting]: GUI:" & $hGUI & " URL: " & $sURL __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__NAV_STARTING) $oArgs = 0 @@ -2225,7 +2346,7 @@ EndFunc ;==>__NetWebView2_Events__OnNavigationStarting ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnNavigationCompleted($oWebV2M, $hGUI, $bIsSuccess, $iWebErrorStatus) - Local Const $s_Prefix = "[EVENT: OnNavigationCompleted]: GUI:" & $hGUI & " " & ($bIsSuccess ? "SUCCESS" : "ERROR ( WebErrorStatus:" & $iWebErrorStatus & ")") + Local Const $s_Prefix = ">>>[EVENT: OnNavigationCompleted]: GUI:" & $hGUI & " " & ($bIsSuccess ? "SUCCESS" : "ERROR ( WebErrorStatus:" & $iWebErrorStatus & ")") __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__NAV_COMPLETED) EndFunc ;==>__NetWebView2_Events__OnNavigationCompleted @@ -2250,7 +2371,7 @@ EndFunc ;==>__NetWebView2_Events__OnNavigationCompleted ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnContextMenuRequested($oWebV2M, $hGUI, $sLink, $iX, $iY, $sSelection) #forceref $oWebV2M - Local Const $s_Prefix = "[EVENT: OnContextMenuRequested]: GUI:" & $hGUI & " LINK: " & $sLink & " X: " & $iX & " Y: " & $iY & " SELECTION: " & $sSelection + Local Const $s_Prefix = ">>>[EVENT: OnContextMenuRequested]: GUI:" & $hGUI & " LINK: " & $sLink & " X: " & $iX & " Y: " & $iY & " SELECTION: " & $sSelection __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) EndFunc ;==>__NetWebView2_Events__OnContextMenuRequested @@ -2271,7 +2392,7 @@ EndFunc ;==>__NetWebView2_Events__OnContextMenuRequested ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnContextMenu($oWebV2M, $hGUI, $sMenuData) #forceref $oWebV2M - Local Const $s_Prefix = "[EVENT: OnContextMenu]: GUI:" & $hGUI & " MENUDATA: " & $sMenuData + Local Const $s_Prefix = ">>>[EVENT: OnContextMenu]: GUI:" & $hGUI & " MENUDATA: " & $sMenuData __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) EndFunc ;==>__NetWebView2_Events__OnContextMenu @@ -2294,7 +2415,7 @@ EndFunc ;==>__NetWebView2_Events__OnContextMenu ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnWebResourceResponseReceived($oWebV2M, $hGUI, $iStatusCode, $sReasonPhrase, $sRequestUrl) - Local Const $s_Prefix = "[EVENT: OnWebResourceResponseReceived]: GUI:" & $hGUI & " HTTPStatusCode: " & $iStatusCode & " (" & $sReasonPhrase & ") URL: " & $sRequestUrl + Local Const $s_Prefix = ">>>[EVENT: OnWebResourceResponseReceived]: GUI:" & $hGUI & " HTTPStatusCode: " & $iStatusCode & " (" & $sReasonPhrase & ") URL: " & $sRequestUrl __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__RESPONSE_RECEIVED) EndFunc ;==>__NetWebView2_Events__OnWebResourceResponseReceived @@ -2316,7 +2437,7 @@ EndFunc ;==>__NetWebView2_Events__OnWebResourceResponseReceived ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnDownloadStarting($oWebV2M, $hGUI, $sURL, $sDefaultPath) - Local Const $s_Prefix = "[EVENT: OnDownloadStarting]: GUI:" & $hGUI & " URL: " & $sURL & " DEFAULT_PATH: " & $sDefaultPath + Local Const $s_Prefix = ">>>[EVENT: OnDownloadStarting]: GUI:" & $hGUI & " URL: " & $sURL & " DEFAULT_PATH: " & $sDefaultPath __NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__DOWNLOAD_STARTING) EndFunc ;==>__NetWebView2_Events__OnDownloadStarting @@ -2341,7 +2462,7 @@ EndFunc ;==>__NetWebView2_Events__OnDownloadStarting ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnDownloadStateChanged($oWebV2M, $hGUI, $sState, $sURL, $iTotal_Bytes, $iReceived_Bytes) - Local Const $s_Prefix = "[EVENT: OnDownloadStateChanged]: GUI:" & $hGUI & " State: " & $sState & " URL: " & $sURL & " Total_Bytes: " & $iTotal_Bytes & " Received_Bytes: " & $iReceived_Bytes + Local Const $s_Prefix = ">>>[EVENT: OnDownloadStateChanged]: GUI:" & $hGUI & " State: " & $sState & " URL: " & $sURL & " Total_Bytes: " & $iTotal_Bytes & " Received_Bytes: " & $iReceived_Bytes Local $iPercent = 0 If $iTotal_Bytes > 0 Then $iPercent = Round(($iReceived_Bytes / $iTotal_Bytes), 5) * 100 @@ -2381,17 +2502,17 @@ EndFunc ;==>__NetWebView2_Events__OnDownloadStateChanged Volatile Func __NetWebView2_Events__OnAcceleratorKeyPressed($oWebV2M, $hGUI, $oArgs) #forceref $oWebV2M Local Const $sArgsList = _ - '[VirtualKey=' & $oArgs.VirtualKey & _ ; The VK code of the key. - '; KeyEventKind=' & $oArgs.KeyEventKind & _ ; Type of key event (Down, Up, etc.). - '; Handled=' & $oArgs.Handled & _ ; Set to `True` to stop the browser from processing the key. - '; RepeatCount=' & $oArgs.RepeatCount & _ ; The number of times the key has repeated. - '; ScanCode=' & $oArgs.ScanCode & _ ; Hardware scan code. - '; IsExtendedKey=' & $oArgs.IsExtendedKey & _ ; True if it's an extended key (e.g., right Alt). - '; IsMenuKeyDown=' & $oArgs.IsMenuKeyDown & _ ; True if Alt is pressed. - '; WasKeyDown=' & $oArgs.WasKeyDown & _ ; True if the key was already down. - '; IsKeyReleased=' & $oArgs.IsKeyReleased & _ ; True if the event is a key up. - '; KeyEventLParam=' & $oArgs.KeyEventLParam & ']' ; Gets the LPARAM value that accompanied the window message. - Local Const $s_Prefix = "[EVENT: OnAcceleratorKeyPressed]: GUI:" & $hGUI & " $oArgs: " & ((IsObj($oArgs)) ? ($sArgsList) : ('ERROR')) + "[VirtualKey=" & $oArgs.VirtualKey & _ ; The VK code of the key. + "; KeyEventKind=" & $oArgs.KeyEventKind & _ ; Type of key event (Down, Up, etc.). + "; Handled=" & $oArgs.Handled & _ ; Set to `True` to stop the browser from processing the key. + "; RepeatCount=" & $oArgs.RepeatCount & _ ; The number of times the key has repeated. + "; ScanCode=" & $oArgs.ScanCode & _ ; Hardware scan code. + "; IsExtendedKey=" & $oArgs.IsExtendedKey & _ ; True if it"s an extended key (e.g., right Alt). + "; IsMenuKeyDown=" & $oArgs.IsMenuKeyDown & _ ; True if Alt is pressed. + "; WasKeyDown=" & $oArgs.WasKeyDown & _ ; True if the key was already down. + "; IsKeyReleased=" & $oArgs.IsKeyReleased & _ ; True if the event is a key up. + "; KeyEventLParam=" & $oArgs.KeyEventLParam & "]" ; Gets the LPARAM value that accompanied the window message. + Local Const $s_Prefix = ">>>[EVENT: OnAcceleratorKeyPressed]: GUI:" & $hGUI & " $oArgs: " & ((IsObj($oArgs)) ? ($sArgsList) : ("ERROR")) ;~ https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2acceleratorkeypressedeventargs?view=webview2-dotnet-1.0.705.50 If $oArgs.VirtualKey = 27 Then ; ESC 27 1b 033 Escape, next character is not echoed ; https://www.autoitscript.com/autoit3/docs/appendix/ascii.htm @@ -2419,11 +2540,11 @@ EndFunc ;==>__NetWebView2_Events__OnAcceleratorKeyPressed ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnProcessFailed($oWebV2M, $hGUI, $oArgs) Local Const $sArgsList = _ - '[Kind=' & $oArgs.ProcessFailedKind & _ - '; Reason=' & $oArgs.Reason & _ - '; ExitCode=' & $oArgs.ExitCode & _ - '; Description=' & $oArgs.ProcessDescription & ']' - Local Const $s_Prefix = "[EVENT: OnProcessFailed]: GUI:" & $hGUI & " $oArgs: " & $sArgsList + "[Kind=" & $oArgs.ProcessFailedKind & _ + "; Reason=" & $oArgs.Reason & _ + "; ExitCode=" & $oArgs.ExitCode & _ + "; Description=" & $oArgs.ProcessDescription & "]" + Local Const $s_Prefix = ">>>[EVENT: OnProcessFailed]: GUI:" & $hGUI & " $oArgs: " & $sArgsList __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__PROCESS_FAILED) @@ -2448,9 +2569,9 @@ EndFunc ;==>__NetWebView2_Events__OnProcessFailed ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnBasicAuthenticationRequested($oWebV2M, $hGUI, $oArgs) Local Const $sArgsList = _ - '[Uri=' & $oArgs.Uri & _ - '; Challenge=' & $oArgs.Challenge & ']' - Local Const $s_Prefix = "[EVENT: OnBasicAuthenticationRequested]: GUI:" & $hGUI & " $oArgs: " & $sArgsList + "[Uri=" & $oArgs.Uri & _ + "; Challenge=" & $oArgs.Challenge & "]" + Local Const $s_Prefix = ">>>[EVENT: OnBasicAuthenticationRequested]: GUI:" & $hGUI & " $oArgs: " & $sArgsList __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__BASIC_AUTHENTICATION_REQUESTED) @@ -2476,7 +2597,7 @@ EndFunc ;==>__NetWebView2_Events__OnBasicAuthenticationRequested ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnFrameCreated($oWebV2M, $hGUI, $oFrame) - Local Const $s_Prefix = "[EVENT: OnFrameCreated]: WebV2M: " & VarGetType($oWebV2M) & " GUI: " & $hGUI & " Frame: " & VarGetType($oFrame) + Local Const $s_Prefix = ">>>[EVENT: OnFrameCreated]: WebV2M: " & VarGetType($oWebV2M) & " GUI: " & $hGUI & " Frame: " & VarGetType($oFrame) __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) $oFrame = 0 EndFunc ;==>__NetWebView2_Events__OnFrameCreated @@ -2497,7 +2618,7 @@ EndFunc ;==>__NetWebView2_Events__OnFrameCreated ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnFrameDestroyed($oWebV2M, $hGUI, $oFrame) - Local Const $s_Prefix = "[EVENT: OnFrameDestroyed]: WebV2M: " & VarGetType($oWebV2M) & " GUI: " & $hGUI & " Frame: " & VarGetType($oFrame) + Local Const $s_Prefix = ">>>[EVENT: OnFrameDestroyed]: WebV2M: " & VarGetType($oWebV2M) & " GUI: " & $hGUI & " Frame: " & VarGetType($oFrame) __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) $oFrame = 0 EndFunc ;==>__NetWebView2_Events__OnFrameDestroyed @@ -2518,7 +2639,7 @@ EndFunc ;==>__NetWebView2_Events__OnFrameDestroyed ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnFrameNameChanged($oWebV2M, $hGUI, $oFrame) - Local Const $s_Prefix = "[EVENT: OnFrameNameChanged]: WebV2M: " & VarGetType($oWebV2M) & " GUI: " & $hGUI & " Frame: " & VarGetType($oFrame) + Local Const $s_Prefix = ">>>[EVENT: OnFrameNameChanged]: WebV2M: " & VarGetType($oWebV2M) & " GUI: " & $hGUI & " Frame: " & VarGetType($oFrame) __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) $oFrame = 0 EndFunc ;==>__NetWebView2_Events__OnFrameNameChanged @@ -2541,7 +2662,7 @@ EndFunc ;==>__NetWebView2_Events__OnFrameNameChanged ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnFrameNavigationStarting($oWebV2M, $hGUI, $oFrame, $oArgs) Local $sUri = $oArgs.Uri - Local Const $s_Prefix = "[EVENT: OnFrameNavigationStarting]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " Uri:" & $sUri + Local Const $s_Prefix = ">>>[EVENT: OnFrameNavigationStarting]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " Uri:" & $sUri __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) ; __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__FRAME_NAV_STARTING) ; Optional: Update status if needed $oFrame = 0 @@ -2565,7 +2686,7 @@ EndFunc ;==>__NetWebView2_Events__OnFrameNavigationStarting ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnFrameNavigationCompleted($oWebV2M, $hGUI, $oFrame, $bIsSuccess, $iWebErrorStatus) - Local Const $s_Prefix = "[EVENT: OnFrameNavigationCompleted]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " Success:" & $bIsSuccess & " Status:" & $iWebErrorStatus + Local Const $s_Prefix = ">>>[EVENT: OnFrameNavigationCompleted]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " Success:" & $bIsSuccess & " Status:" & $iWebErrorStatus __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) ; __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__FRAME_NAV_COMPLETED) EndFunc ;==>__NetWebView2_Events__OnFrameNavigationCompleted @@ -2587,7 +2708,7 @@ EndFunc ;==>__NetWebView2_Events__OnFrameNavigationCompleted ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnFrameContentLoading($oWebV2M, $hGUI, $oFrame, $iNavigationId) - Local Const $s_Prefix = "[EVENT: OnFrameContentLoading]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " NavID:" & $iNavigationId + Local Const $s_Prefix = ">>>[EVENT: OnFrameContentLoading]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " NavID:" & $iNavigationId __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) ; __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__FRAME_CONTENT_LOADING) $oFrame = 0 @@ -2610,7 +2731,7 @@ EndFunc ;==>__NetWebView2_Events__OnFrameContentLoading ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnFrameDOMContentLoaded($oWebV2M, $hGUI, $oFrame, $iNavigationId) - Local Const $s_Prefix = "[EVENT: OnFrameDOMContentLoaded]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " NavID:" & $iNavigationId + Local Const $s_Prefix = ">>>[EVENT: OnFrameDOMContentLoaded]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " NavID:" & $iNavigationId __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) ; __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__FRAME_DOM_CONTENT_LOADED) $oFrame = 0 @@ -2633,7 +2754,7 @@ EndFunc ;==>__NetWebView2_Events__OnFrameDOMContentLoaded ; Example .......: No ; =============================================================================================================================== Volatile Func __NetWebView2_Events__OnFrameWebMessageReceived($oWebV2M, $hGUI, $oFrame, $sMessage) - Local Const $s_Prefix = "[EVENT: OnFrameWebMessageReceived]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " Message:" & $sMessage + Local Const $s_Prefix = ">>>[EVENT: OnFrameWebMessageReceived]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " Message:" & $sMessage __NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1) ; __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__FRAME_WEB_MESSAGE_RECEIVED) $oFrame = 0