Skip to content

Commit 2935e61

Browse files
authored
Update NetWebView2Lib.au3
1 parent e95313b commit 2935e61

1 file changed

Lines changed: 44 additions & 67 deletions

File tree

NetWebView2Lib.au3

Lines changed: 44 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ Func _NetWebView2_CreateManager($sUserAgent = '', $s_fnEventPrefix = "", $s_AddB
147147
#forceref $oMyError
148148

149149
Local $oWebV2M = ObjCreate("NetWebView2Lib.WebView2Manager") ; REGISTERED VERSION
150+
$RET = $oWebV2M
150151
If @error Then
151152
$ERR = @error
152153
$EXT = @extended
@@ -624,37 +625,32 @@ Func _NetWebView2_Navigate($oWebV2M, $s_URL, $iWaitMessage = $NETWEBVIEW2_MESSAG
624625
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler
625626
#forceref $oMyError
626627

627-
If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then Return SetError(1, 0, "ERROR: Invalid Object")
628-
629-
; 1. Parameter Validation
630-
If $iWaitMessage < $NETWEBVIEW2_MESSAGE__INIT_READY Or $iWaitMessage > $NETWEBVIEW2_MESSAGE__TITLE_CHANGED Then ; higher messsages are not for NAVIGATION thus not checking in _NetWebView2_LoadWait()
631-
Return SetError(1, 0, False)
632-
EndIf
633-
634-
; 2. Execute Navigation
635-
; The Local Error Handler catches potential "Disposed Object" crashes here
636-
$oWebV2M.LockWebView()
637-
$oWebV2M.Navigate($s_URL)
638-
If @error Then
628+
If (Not IsObj($oWebV2M)) Or ObjName($oWebV2M, $OBJ_PROGID) <> 'NetWebView2Lib.WebView2Manager' Then
629+
$ERR = 1
630+
$MSG = "ERROR: Invalid Object"
631+
ELseif $iWaitMessage < $NETWEBVIEW2_MESSAGE__INIT_READY Or $iWaitMessage > $NETWEBVIEW2_MESSAGE__TITLE_CHANGED Then
632+
; Parameter Validation - higher messsages are not for NAVIGATION thus not checking in _NetWebView2_LoadWait()
633+
$ERR = 2
634+
$MSG = "ERROR: $iWaitMessage not valid"
635+
Else
636+
; Execute Navigation
637+
; The Local Error Handler catches potential "Disposed Object" crashes here
638+
$oWebV2M.LockWebView()
639+
$oWebV2M.Navigate($s_URL)
640+
$ERR = @error
641+
$EXT = @extended
642+
If Not @error Then
643+
; Wait for status using the BulletProof LoadWait logic
644+
$RET = _NetWebView2_LoadWait($oWebV2M, $iWaitMessage, $sExpectedTitle, $iTimeOut_ms)
645+
$ERR = @error
646+
$EXT = @extended
647+
If @error Then ; If an error occurred (3: Nav Error, 4: Timeout), log the failure
648+
$MSG = " -> LOAD WAIT FAILED"
649+
EndIf
650+
EndIf
639651
$oWebV2M.UnLockWebView()
640-
Return SetError(2, @error, False)
641-
EndIf
642-
643-
; 3. Wait for status using the Bulletproof LoadWait logic
644-
Local $bResult = _NetWebView2_LoadWait($oWebV2M, $iWaitMessage, $sExpectedTitle, $iTimeOut_ms)
645-
$ERR = @error
646-
$EXT = @extended
647-
648-
649-
; If an error occurred (3: Nav Error, 4: Timeout), log the failure
650-
If @error Then
651-
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " -> LOAD WAIT FAILED (Err:" & $ERR & " Ext:" & $EXT & ")", 1, $ERR, $EXT)
652652
EndIf
653653

654-
$oWebV2M.UnLockWebView()
655-
Return SetError($ERR, $EXT, $bResult)
656-
657-
#TODO ENDPOINT REFACTORING
658654
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT)
659655
Return SetError($ERR, $EXT, $RET)
660656
EndFunc ;==>_NetWebView2_Navigate
@@ -1123,7 +1119,7 @@ Func _NetWebView2_SetBuiltInErrorPageEnabled($oWebV2M, $bEnabled)
11231119
Return SetError($ERR, $EXT, $RET)
11241120
EndFunc ;==>_NetWebView2_SetBuiltInErrorPageEnabled
11251121

1126-
; #INTERNAL_USE_ONLY# ===========================================================================================================
1122+
; #FUNCTION# ====================================================================================================================
11271123
; Name ..........: _NetWebView2_GetFrame
11281124
; Description ...: Returns a Frame Object (IWebView2Frame) for the specified index.
11291125
; Syntax ........: _NetWebView2_GetFrame($oWebV2M, $iIndex)
@@ -1195,25 +1191,6 @@ Func _WebView2_FrameGetHtmlSource($oFrame)
11951191
Return SetError($ERR, $EXT, $RET)
11961192
EndFunc ;==>_WebView2_FrameGetHtmlSource
11971193

1198-
; #INTERNAL_USE_ONLY# ===========================================================================================================
1199-
; Name ..........: _NetWebView2_GetFrame
1200-
; Description ...: Returns a Frame Object (IWebView2Frame) for the specified index.
1201-
; Syntax ........: _NetWebView2_GetFrame($oWebV2M, $iIndex)
1202-
; Parameters ....: $oWebV2M - an object.
1203-
; $iIndex - an int value.
1204-
; Return values .: Frame Object or Null
1205-
; Author ........: ioa747
1206-
; Modified ......:
1207-
; Remarks .......:
1208-
; Related .......:
1209-
; Link ..........:
1210-
; Example .......: Yes
1211-
; ===============================================================================================================================
1212-
Func _NetWebView2_GetFrame($oWebV2M, $iIndex)
1213-
Local $oFrame = $oWebV2M.GetFrame($iIndex)
1214-
Return SetError(@error, @extended, $oFrame)
1215-
EndFunc ;==>_NetWebView2_GetFrame
1216-
12171194
#EndRegion ; === NetWebView2Lib UDF === New Core Method Wrappers
12181195

12191196
#Region ; === NetWebView2Lib UDF === _NetJson_* functions
@@ -1403,16 +1380,16 @@ EndFunc ;==>__NetWebView2_WaitForReadyState
14031380
; Syntax ........: __NetWebView2_LastMessage_KEEPER($oWebV2M[, $iMessage = Default[, $iError = @error[, $iExtended = @extended]]])
14041381
; Parameters ....: $oWebV2M - The NetWebView2 Manager object.
14051382
; $iMessage - [optional] Message to SET. If Default, function acts as GET. If -1, performs cleanup.
1406-
; $ERRor - [optional] an integer value. Default is @error.
1407-
; $EXTended - [optional] an integer value. Default is @extended.
1383+
; $iError - [optional] an integer value. Default is @error.
1384+
; $iExtended - [optional] an integer value. Default is @extended.
14081385
; Author.........: mLipok, ioa747
14091386
; Modified ......:
14101387
; Remarks........: Uses a Local COM Error Handler to silently handle "Disposed Object" errors during shutdown.
14111388
; Related .......:
14121389
; Link ..........:
14131390
; Example .......: No
14141391
; ===============================================================================================================================
1415-
Func __NetWebView2_LastMessage_KEEPER($oWebV2M, $iMessage = Default, $ERRor = @error, $EXTended = @extended)
1392+
Func __NetWebView2_LastMessage_KEEPER($oWebV2M, $iMessage = Default, $iError = @error, $iExtended = @extended)
14161393
Local Const $s_Prefix = "[__NetWebView2_LastMessage_KEEPER]:"
14171394
Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results
14181395
; Static Map - The central database of status indexed by Window Handle
@@ -1423,13 +1400,13 @@ Func __NetWebView2_LastMessage_KEEPER($oWebV2M, $iMessage = Default, $ERRor = @e
14231400
Local Static $mLastMessegKeeper[]
14241401
Local $sKey = "" & $oWebV2M.BrowserWindowHandle
14251402
If $iMessage <> Default Then
1426-
__NetWebView2_LastMessage__INTERNALL($mLastMessegKeeper, $sKey, $iMessage, $ERRor = @error, $EXTended = @extended)
1403+
__NetWebView2_LastMessage__INTERNALL($mLastMessegKeeper, $sKey, $iMessage, $iError = @error, $iExtended = @extended)
14271404

14281405
__NetWebView2_LastMessage_onReceived($oWebV2M, $iMessage)
14291406
__NetWebView2_LastMessage_Navigation($oWebV2M, $iMessage)
1430-
Return SetError($ERRor, $EXTended)
1407+
Return SetError($iError, $iExtended)
14311408
Else
1432-
Return SetError($ERRor, $EXTended, $mLastMessegKeeper[$sKey])
1409+
Return SetError($iError, $iExtended, $mLastMessegKeeper[$sKey])
14331410
EndIf
14341411

14351412

@@ -1438,7 +1415,7 @@ Func __NetWebView2_LastMessage_KEEPER($oWebV2M, $iMessage = Default, $ERRor = @e
14381415
Return SetError($ERR, $EXT, $RET)
14391416
EndFunc ;==>__NetWebView2_LastMessage_KEEPER
14401417

1441-
Func __NetWebView2_LastMessage_onReceived($oWebV2M, $iMessage = Default, $ERRor = @error, $EXTended = @extended)
1418+
Func __NetWebView2_LastMessage_onReceived($oWebV2M, $iMessage = Default, $iError = @error, $iExtended = @extended)
14421419
Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage_onReceived]:"
14431420
Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results
14441421
; Static Map - The central database of status indexed by Window Handle
@@ -1451,17 +1428,17 @@ Func __NetWebView2_LastMessage_onReceived($oWebV2M, $iMessage = Default, $ERRor
14511428

14521429
If $iMessage <> Default Then
14531430
If $_g_bNetWebView2_DebugDev Then ConsoleWrite('! IFNC: __NetWebView2_LastMessage_onReceived ==> ' & $iMessage & ' Key=' & $sKey & ' SLN=' & @ScriptLineNumber & @CRLF)
1454-
__NetWebView2_LastMessage__INTERNALL($mLastMessegReceived, $sKey, $iMessage, $ERRor = @error, $EXTended = @extended)
1431+
__NetWebView2_LastMessage__INTERNALL($mLastMessegReceived, $sKey, $iMessage, $iError = @error, $iExtended = @extended)
14551432
EndIf
14561433

1457-
Return SetError($ERRor, $EXTended, $mLastMessegReceived[$sKey])
1434+
Return SetError($iError, $iExtended, $mLastMessegReceived[$sKey])
14581435

14591436
#TODO ENDPOINT REFACTORING
14601437
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT)
14611438
Return SetError($ERR, $EXT, $RET)
14621439
EndFunc ;==>__NetWebView2_LastMessage_onReceived
14631440

1464-
Func __NetWebView2_LastMessage_Navigation($oWebV2M, $iMessage = Default, $ERRor = @error, $EXTended = @extended)
1441+
Func __NetWebView2_LastMessage_Navigation($oWebV2M, $iMessage = Default, $iError = @error, $iExtended = @extended)
14651442
Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage_Navigation]:"
14661443
Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results
14671444
; Static Map - The central database of status indexed by Window Handle
@@ -1474,43 +1451,43 @@ Func __NetWebView2_LastMessage_Navigation($oWebV2M, $iMessage = Default, $ERRor
14741451
If $iMessage <> Default Then
14751452
If $iMessage >= $NETWEBVIEW2_MESSAGE__NAV_STARTING And $iMessage <= $NETWEBVIEW2_MESSAGE__TITLE_CHANGED Then
14761453
If $_g_bNetWebView2_DebugDev Then ConsoleWrite('! IFNC: __NetWebView2_LastMessage_Navigation ==> ' & $iMessage & ' Key=' & $sKey & ' SLN=' & @ScriptLineNumber & @CRLF)
1477-
__NetWebView2_LastMessage__INTERNALL($mLastNavigationMessage, $sKey, $iMessage, $ERRor = @error, $EXTended = @extended)
1454+
__NetWebView2_LastMessage__INTERNALL($mLastNavigationMessage, $sKey, $iMessage, $iError = @error, $iExtended = @extended)
14781455
EndIf
14791456
EndIf
1480-
Return SetError($ERRor, $EXTended, $mLastNavigationMessage[$sKey])
1457+
Return SetError($iError, $iExtended, $mLastNavigationMessage[$sKey])
14811458

14821459
#TODO ENDPOINT REFACTORING
14831460
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT)
14841461
Return SetError($ERR, $EXT, $RET)
14851462
EndFunc ;==>__NetWebView2_LastMessage_Navigation
14861463

1487-
Func __NetWebView2_LastMessage__INTERNALL(ByRef $mStatus, $sKey, $iMessage = Default, $ERRor = @error, $EXTended = @extended)
1464+
Func __NetWebView2_LastMessage__INTERNALL(ByRef $mStatus, $sKey, $iMessage = Default, $iError = @error, $iExtended = @extended)
14881465
Local Const $s_Prefix = ">>>[__NetWebView2_LastMessage__INTERNALL]:"
14891466
Local $ERR = 0, $EXT = 0, $RET = False, $MSG = "" ; predefined endpoint results
14901467

14911468
; If an error occurred while retrieving the Handle (e.g. Object already closed)
1492-
If @error Then Return SetError($ERRor, $EXTended, $NETWEBVIEW2_MESSAGE__NONE)
1469+
If @error Then Return SetError($iError, $iExtended, $NETWEBVIEW2_MESSAGE__NONE)
14931470

14941471
; If the handle is invalid
1495-
If $sKey = "0" Or $sKey = "" Then Return SetError($ERRor, $EXTended, $NETWEBVIEW2_MESSAGE__NONE)
1472+
If $sKey = "0" Or $sKey = "" Then Return SetError($iError, $iExtended, $NETWEBVIEW2_MESSAGE__NONE)
14961473

14971474
; --- SET MODE (Called from Events or Cleanup) ---
14981475
If $iMessage <> Default Then
14991476
; Special case: -1 for memory cleanup when the instance is closed
15001477
If $iMessage = -1 Then
15011478
If MapExists($mStatus, $sKey) Then MapRemove($mStatus, $sKey)
1502-
Return SetError($ERRor, $EXTended, $NETWEBVIEW2_MESSAGE__NONE)
1479+
Return SetError($iError, $iExtended, $NETWEBVIEW2_MESSAGE__NONE)
15031480
EndIf
15041481

15051482
; Update the status for this specific Handle
15061483
$mStatus[$sKey] = $iMessage
1507-
Return SetError($ERRor, $EXTended, $iMessage)
1484+
Return SetError($iError, $iExtended, $iMessage)
15081485
EndIf
15091486

15101487
; --- GET MODE (Called from LoadWait) ---
1511-
If Not MapExists($mStatus, $sKey) Then Return SetError($ERRor, $EXTended, $NETWEBVIEW2_MESSAGE__NONE)
1488+
If Not MapExists($mStatus, $sKey) Then Return SetError($iError, $iExtended, $NETWEBVIEW2_MESSAGE__NONE)
15121489

1513-
Return SetError($ERRor, $EXTended, $mStatus[$sKey])
1490+
Return SetError($iError, $iExtended, $mStatus[$sKey])
15141491

15151492
#TODO ENDPOINT REFACTORING
15161493
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $MSG, 1, $ERR, $EXT)

0 commit comments

Comments
 (0)