Skip to content

Commit 9857ff9

Browse files
authored
Update
1 parent 502bb46 commit 9857ff9

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

NetWebView2Lib.au3

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,11 @@ EndFunc ;==>_NetWebView2_SetBuiltInErrorPageEnabled
773773
; while an event or a method call is still in progress.
774774
; Author ........: ioa747
775775
; ===============================================================================================================================
776-
Func _NetWebView2_SilentErrorHandler($oError)
776+
Volatile Func _NetWebView2_SilentErrorHandler($oError)
777+
#forceref $oError
777778
; We do nothing, effectively "swallowing" the COM error.
778779
; This prevents the "Object Disposed" fatal crash.
779-
#forceref $oError
780+
$oError = 0 ; Explicitly release the COM reference inside the volatile scopeEndFunc
780781
EndFunc ;==>_NetWebView2_SilentErrorHandler
781782

782783
#EndRegion ; New Core Method Wrappers
@@ -1095,7 +1096,7 @@ EndFunc ;==>__Get_Core_Bridge_JS
10951096
; Link ..........:
10961097
; Example .......: No
10971098
; ===============================================================================================================================
1098-
Func __NetWebView2_COMErrFunc($oError) ; COM Error Function used by COM Error Handler
1099+
Volatile Func __NetWebView2_COMErrFunc($oError) ; COM Error Function used by COM Error Handler
10991100
If @Compiled Then Return
11001101
Local $s_INFO = _
11011102
"COM Error intercepted !" & @CRLF & _
@@ -1109,15 +1110,17 @@ Func __NetWebView2_COMErrFunc($oError) ; COM Error Function used by COM Error Ha
11091110
@TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
11101111
@TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF
11111112
__NetWebView2_Log($oError.scriptline, $s_INFO, 1)
1113+
$oError = 0 ; Explicitly release the COM reference inside the volatile scopeEndFunc
11121114
EndFunc ;==>__NetWebView2_COMErrFunc
11131115

1114-
Func __NetWebView2_fake_COMErrFunc($oError) ; COM Error Function used by COM Error Handler
1116+
Volatile Func __NetWebView2_fake_COMErrFunc($oError) ; COM Error Function used by COM Error Handler
11151117
#forceref $oError
11161118
; this is only to silently handle _NetWebView2_IsRegisteredCOMObject()
1119+
$oError = 0 ; Explicitly release the COM reference inside the volatile scopeEndFunc
11171120
EndFunc ;==>__NetWebView2_fake_COMErrFunc
11181121

11191122
; Handles native WebView2 events
1120-
Func __NetWebView2_Events__OnMessageReceived($oWebV2M, $hGUI, $sMsg)
1123+
Volatile Func __NetWebView2_Events__OnMessageReceived($oWebV2M, $hGUI, $sMsg)
11211124
$hGUI = HWnd("0x" & Hex($hGUI, 16))
11221125
Local Const $s_Prefix = "[NetWebView2Lib:EVENT: OnMessageReceived]: GUI:" & $hGUI
11231126

@@ -1284,7 +1287,7 @@ Func __NetWebView2_Events__OnMessageReceived($oWebV2M, $hGUI, $sMsg)
12841287
EndFunc ;==>__NetWebView2_Events__OnMessageReceived
12851288

12861289
; Handles custom messages from JavaScript (window.chrome.webview.postMessage)
1287-
Func __NetWebView2_JSEvents__OnMessageReceived($oWebV2M, $hGUI, $sMsg)
1290+
Volatile Func __NetWebView2_JSEvents__OnMessageReceived($oWebV2M, $hGUI, $sMsg)
12881291
#forceref $oWebV2M
12891292

12901293
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1349,7 +1352,7 @@ Func __NetWebView2_JSEvents__OnMessageReceived($oWebV2M, $hGUI, $sMsg)
13491352

13501353
EndFunc ;==>__NetWebView2_JSEvents__OnMessageReceived
13511354

1352-
Func __NetWebView2_Events__OnBrowserGotFocus($oWebV2M, $hGUI, $iReason)
1355+
Volatile Func __NetWebView2_Events__OnBrowserGotFocus($oWebV2M, $hGUI, $iReason)
13531356
#forceref $oWebV2M
13541357

13551358
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1358,7 +1361,7 @@ Func __NetWebView2_Events__OnBrowserGotFocus($oWebV2M, $hGUI, $iReason)
13581361
__NetWebView2_LastMessageReceived($oWebV2M, $NETWEBVIEW2_MESSAGE__BROWSER_GOT_FOCUS)
13591362
EndFunc ;==>__NetWebView2_Events__OnBrowserGotFocus
13601363

1361-
Func __NetWebView2_Events__OnBrowserLostFocus($oWebV2M, $hGUI, $iReason)
1364+
Volatile Func __NetWebView2_Events__OnBrowserLostFocus($oWebV2M, $hGUI, $iReason)
13621365
#forceref $oWebV2M
13631366

13641367
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1367,7 +1370,7 @@ Func __NetWebView2_Events__OnBrowserLostFocus($oWebV2M, $hGUI, $iReason)
13671370
__NetWebView2_LastMessageReceived($oWebV2M, $NETWEBVIEW2_MESSAGE__BROWSER_LOST_FOCUS)
13681371
EndFunc ;==>__NetWebView2_Events__OnBrowserLostFocus
13691372

1370-
Func __NetWebView2_Events__OnZoomChanged($oWebV2M, $hGUI, $iFactor)
1373+
Volatile Func __NetWebView2_Events__OnZoomChanged($oWebV2M, $hGUI, $iFactor)
13711374
#forceref $oWebV2M
13721375

13731376
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1376,7 +1379,7 @@ Func __NetWebView2_Events__OnZoomChanged($oWebV2M, $hGUI, $iFactor)
13761379
__NetWebView2_LastMessageReceived($oWebV2M, $NETWEBVIEW2_MESSAGE__ZOOM_CHANGED)
13771380
EndFunc ;==>__NetWebView2_Events__OnZoomChanged
13781381

1379-
Func __NetWebView2_Events__OnURLChanged($oWebV2M, $hGUI, $sURL)
1382+
Volatile Func __NetWebView2_Events__OnURLChanged($oWebV2M, $hGUI, $sURL)
13801383
#forceref $oWebV2M
13811384

13821385
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1385,7 +1388,7 @@ Func __NetWebView2_Events__OnURLChanged($oWebV2M, $hGUI, $sURL)
13851388
__NetWebView2_LastMessageReceived($oWebV2M, $NETWEBVIEW2_MESSAGE__URL_CHANGED)
13861389
EndFunc ;==>__NetWebView2_Events__OnURLChanged
13871390

1388-
Func __NetWebView2_Events__OnTitleChanged($oWebV2M, $hGUI, $sTITLE)
1391+
Volatile Func __NetWebView2_Events__OnTitleChanged($oWebV2M, $hGUI, $sTITLE)
13891392
#forceref $oWebV2M
13901393

13911394
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1394,7 +1397,7 @@ Func __NetWebView2_Events__OnTitleChanged($oWebV2M, $hGUI, $sTITLE)
13941397
__NetWebView2_LastMessageReceived($oWebV2M, $NETWEBVIEW2_MESSAGE__TITLE_CHANGED)
13951398
EndFunc ;==>__NetWebView2_Events__OnTitleChanged
13961399

1397-
Func __NetWebView2_Events__OnNavigationStarting($oWebV2M, $hGUI, $sURL)
1400+
Volatile Func __NetWebView2_Events__OnNavigationStarting($oWebV2M, $hGUI, $sURL)
13981401
#forceref $oWebV2M
13991402

14001403
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1403,7 +1406,7 @@ Func __NetWebView2_Events__OnNavigationStarting($oWebV2M, $hGUI, $sURL)
14031406
__NetWebView2_LastMessageReceived($oWebV2M, $NETWEBVIEW2_MESSAGE__NAV_STARTING)
14041407
EndFunc ;==>__NetWebView2_Events__OnNavigationStarting
14051408

1406-
Func __NetWebView2_Events__OnNavigationCompleted($oWebV2M, $hGUI, $bIsSuccess, $iWebErrorStatus)
1409+
Volatile Func __NetWebView2_Events__OnNavigationCompleted($oWebV2M, $hGUI, $bIsSuccess, $iWebErrorStatus)
14071410
#forceref $oWebV2M
14081411

14091412
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1412,15 +1415,15 @@ Func __NetWebView2_Events__OnNavigationCompleted($oWebV2M, $hGUI, $bIsSuccess, $
14121415
__NetWebView2_LastMessageReceived($oWebV2M, $NETWEBVIEW2_MESSAGE__NAVIGATION_COMPLETED)
14131416
EndFunc ;==>__NetWebView2_Events__OnNavigationCompleted
14141417

1415-
Func __NetWebView2_Events__OnContextMenuRequested($oWebV2M, $hGUI, $sLink, $iX, $iY, $sSelection)
1418+
Volatile Func __NetWebView2_Events__OnContextMenuRequested($oWebV2M, $hGUI, $sLink, $iX, $iY, $sSelection)
14161419
#forceref $oWebV2M
14171420

14181421
$hGUI = HWnd("0x" & Hex($hGUI, 16))
14191422
Local Const $s_Prefix = "[NetWebView2Lib:EVENT: OnContextMenuRequested]: GUI:" & $hGUI & " LINK: " & $sLink & " X: " & $iX & " Y: " & $iY & " SELECTION: " & $sSelection
14201423
__NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1)
14211424
EndFunc ;==>__NetWebView2_Events__OnContextMenuRequested
14221425

1423-
Func __NetWebView2_Events__OnContextMenu($oWebV2M, $hGUI, $sMenuData)
1426+
Volatile Func __NetWebView2_Events__OnContextMenu($oWebV2M, $hGUI, $sMenuData)
14241427
#forceref $oWebV2M
14251428

14261429
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1446,7 +1449,7 @@ EndFunc ;==>__NetWebView2_Events__OnContextMenu
14461449
; Link ..........: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.webresourceresponsereceived?view=webview2-dotnet-1.0.2849.39
14471450
; Example .......: No
14481451
; ===============================================================================================================================
1449-
Func __NetWebView2_Events__OnWebResourceResponseReceived($oWebV2M, $hGUI, $iStatusCode, $sReasonPhrase, $sRequestUrl)
1452+
Volatile Func __NetWebView2_Events__OnWebResourceResponseReceived($oWebV2M, $hGUI, $iStatusCode, $sReasonPhrase, $sRequestUrl)
14501453
#forceref $oWebV2M
14511454

14521455
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1455,7 +1458,7 @@ Func __NetWebView2_Events__OnWebResourceResponseReceived($oWebV2M, $hGUI, $iStat
14551458
__NetWebView2_LastMessageReceived($oWebV2M, $NETWEBVIEW2_MESSAGE__RESPONSE_RECEIVED)
14561459
EndFunc ;==>__NetWebView2_Events__OnWebResourceResponseReceived
14571460

1458-
Func __NetWebView2_Events__OnDownloadStarting($oWebV2M, $hGUI, $sURL, $sDefaultPath)
1461+
Volatile Func __NetWebView2_Events__OnDownloadStarting($oWebV2M, $hGUI, $sURL, $sDefaultPath)
14591462
#forceref $oWebV2M
14601463

14611464
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1464,7 +1467,7 @@ Func __NetWebView2_Events__OnDownloadStarting($oWebV2M, $hGUI, $sURL, $sDefaultP
14641467
__NetWebView2_LastMessageReceived($oWebV2M, $NETWEBVIEW2_MESSAGE__DOWNLOAD_STARTING)
14651468
EndFunc ;==>__NetWebView2_Events__OnDownloadStarting
14661469

1467-
Func __NetWebView2_Events__OnDownloadStateChanged($oWebV2M, $hGUI, $sState, $sURL, $iTotal_Bytes, $iReceived_Bytes)
1470+
Volatile Func __NetWebView2_Events__OnDownloadStateChanged($oWebV2M, $hGUI, $sState, $sURL, $iTotal_Bytes, $iReceived_Bytes)
14681471
#forceref $oWebV2M
14691472

14701473
$hGUI = HWnd("0x" & Hex($hGUI, 16))
@@ -1490,7 +1493,7 @@ Func __NetWebView2_Events__OnDownloadStateChanged($oWebV2M, $hGUI, $sState, $sUR
14901493
EndSwitch
14911494
EndFunc ;==>__NetWebView2_Events__OnDownloadStateChanged
14921495

1493-
Func __NetWebView2_Events__OnAcceleratorKeyPressed($oWebV2M, $hGUI, $oArgs)
1496+
Volatile Func __NetWebView2_Events__OnAcceleratorKeyPressed($oWebV2M, $hGUI, $oArgs)
14941497
$hGUI = HWnd("0x" & Hex($hGUI, 16))
14951498
Local Const $sArgsList = '[Handled=' & $oArgs.Handled & '; KeyEventKind=' & $oArgs.KeyEventKind & '; KeyEventLParam=' & $oArgs.KeyEventLParam & '; VirtualKey=' & $oArgs.VirtualKey & ']'
14961499
Local Const $s_Prefix = "[NetWebView2Lib:EVENT: OnAcceleratorKeyPressed]: GUI:" & $hGUI & " ARGS: " & ((IsObj($oArgs)) ? ($sArgsList) : ('ERRROR'))
@@ -1507,6 +1510,7 @@ Func __NetWebView2_Events__OnAcceleratorKeyPressed($oWebV2M, $hGUI, $oArgs)
15071510
EndIf
15081511

15091512
__NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1)
1513+
$oArgs = 0 ; Explicitly release the COM reference inside the volatile scopeEndFunc
15101514
EndFunc ;==>__NetWebView2_Events__OnAcceleratorKeyPressed
15111515
#EndRegion ; NetWebView2Lib UDF - === EVENT HANDLERS ===
15121516

0 commit comments

Comments
 (0)