@@ -62,6 +62,9 @@ Global Enum _ ; $NETWEBVIEW2_MESSAGE__* are set by __NetWebView2_WebViewEvents__
6262 $NETWEBVIEW2_MESSAGE__COOKIE_ADD_ERROR , _
6363 $NETWEBVIEW2_MESSAGE__BLOCKED_AD , _
6464 $NETWEBVIEW2_MESSAGE__DOWNLOAD_STARTING , _
65+ $NETWEBVIEW2_MESSAGE__DOWNLOAD_IN_PROGRESS , _
66+ $NETWEBVIEW2_MESSAGE__DOWNLOAD_INTERRUPTED , _
67+ $NETWEBVIEW2_MESSAGE__DOWNLOAD_COMPLETED , _
6568 $NETWEBVIEW2_MESSAGE___FAKE_COUNTER
6669
6770#Region ; NetWebView2Lib UDF - _NetWebView2_* core functions
@@ -742,7 +745,7 @@ EndFunc ;==>__Get_Core_Bridge_JS
742745; Link ..........:
743746; Example .......: No
744747; ===============================================================================================================================
745- Func __NetWebView2_COMErrFunc($oError ) ; COM Error Function used by COM Error Handler
748+ Func __NetWebView2_COMErrFunc(ByRef $oError ) ; COM Error Function used by COM Error Handler
746749 If @Compiled Then Return
747750 ConsoleWrite (" NetWebView2Lib UDF (" & $oError .scriptline & " ) : ==> COM Error intercepted !" & @CRLF & _
748751 @TAB & " err.number is: " & @TAB & @TAB & " 0x" & Hex ($oError .number ) & @CRLF & _
@@ -756,9 +759,8 @@ Func __NetWebView2_COMErrFunc($oError) ; COM Error Function used by COM Error Ha
756759 @TAB & " err.retcode is: " & @TAB & " 0x" & Hex ($oError .retcode) & @CRLF & @CRLF )
757760EndFunc ; ==>__NetWebView2_COMErrFunc
758761
759- ; Handles native WebView2 events
760762#TODO = > Func __NetWebView2_WebViewEvents__OnMessageReceived(ByRef $oWebV2M , $hGUI , $sMsg )
761- Func __NetWebView2_WebViewEvents__OnMessageReceived($sMsg )
763+ Func __NetWebView2_WebViewEvents__OnMessageReceived($sMsg ) ; Handles native WebView2 events
762764 Local Const $s_Prefix = " [WebViewEvents__OnMessageReceived]:"
763765 Local $oMyError = ObjEvent (" AutoIt.Error" , __NetWebView2_COMErrFunc) ; Local COM Error Handler
764766 #forceref $oMyError
@@ -929,9 +931,8 @@ Func __NetWebView2_WebViewEvents__OnMessageReceived($sMsg)
929931
930932EndFunc ; ==>__NetWebView2_WebViewEvents__OnMessageReceived
931933
932- ; Handles custom messages from JavaScript (window.chrome.webview.postMessage)
933- #TODO = > Func __NetWebView2_JSEvents__OnMessageReceived(ByRef $oWebV2M , ByRef $oWebJS , $hGUI , $sMsg )
934- Func __NetWebView2_JSEvents__OnMessageReceived($sMsg )
934+ #TODO = > Func __NetWebView2_JSEvents__OnMessageReceived(ByRef $oWebV2M , $hGUI , ByRef $oWebJS , $hGUI , $sMsg )
935+ Func __NetWebView2_JSEvents__OnMessageReceived($sMsg ) ; Handles custom messages from JavaScript (window.chrome.webview.postMessage)
935936 Local Const $s_Prefix = " [JSEvents__OnMessageReceived]:"
936937 Local $oMyError = ObjEvent (" AutoIt.Error" , __NetWebView2_COMErrFunc) ; Local COM Error Handler
937938 #forceref $oMyError
@@ -998,51 +999,101 @@ Func __NetWebView2_JSEvents__OnMessageReceived($sMsg)
998999
9991000EndFunc ; ==>__NetWebView2_JSEvents__OnMessageReceived
10001001
1002+ #TODO = > Func __NetWebView2_WebViewEvents__OnBrowserGotFocus(ByRef $oWebV2M , $hGUI , $iReason )
10011003Func __NetWebView2_WebViewEvents__OnBrowserGotFocus($iReason )
10021004 Local Const $s_Prefix = " [WebViewEvents__OnBrowserGotFocus]: REASON: " & $iReason
10031005 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
10041006EndFunc ; ==>__NetWebView2_WebViewEvents__OnBrowserGotFocus
10051007
1008+ #TODO = > Func __NetWebView2_WebViewEvents__OnBrowserLostFocus(ByRef $oWebV2M , $hGUI , $iReason )
10061009Func __NetWebView2_WebViewEvents__OnBrowserLostFocus($iReason )
10071010 Local Const $s_Prefix = " [WebViewEvents__OnBrowserLostFocus]: REASON: " & $iReason
10081011 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
10091012EndFunc ; ==>__NetWebView2_WebViewEvents__OnBrowserLostFocus
10101013
1014+ #TODO = > Func __NetWebView2_WebViewEvents__OnZoomChanged(ByRef $oWebV2M , $hGUI , $iFactor )
10111015Func __NetWebView2_WebViewEvents__OnZoomChanged($iFactor )
10121016 Local Const $s_Prefix = " [WebViewEvents__OnZoomChanged]: FACTOR: " & $iFactor
10131017 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
10141018EndFunc ; ==>__NetWebView2_WebViewEvents__OnZoomChanged
10151019
1016- Func __NetWebView2_WebViewEvents__OnURLChanged($sNewUrl )
1017- Local Const $s_Prefix = " [WebViewEvents__OnURLChanged]: URL: " & $sNewUrl
1020+ #TODO = > Func __NetWebView2_WebViewEvents__OnURLChanged(ByRef $oWebV2M , $hGUI , $sURL )
1021+ Func __NetWebView2_WebViewEvents__OnURLChanged($sURL )
1022+ Local Const $s_Prefix = " [WebViewEvents__OnURLChanged]: URL: " & $sURL
10181023 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
10191024EndFunc ; ==>__NetWebView2_WebViewEvents__OnURLChanged
10201025
1021- Func __NetWebView2_WebViewEvents__OnTitleChanged($sNewTitle )
1022- Local Const $s_Prefix = " [WebViewEvents__OnTitleChanged]: TITLE: " & $sNewTitle
1026+ #TODO = > Func __NetWebView2_WebViewEvents__OnTitleChanged(ByRef $oWebV2M , $hGUI , $sTITLE )
1027+ Func __NetWebView2_WebViewEvents__OnTitleChanged($sTITLE )
1028+ Local Const $s_Prefix = " [WebViewEvents__OnTitleChanged]: TITLE: " & $sTITLE
10231029 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
10241030EndFunc ; ==>__NetWebView2_WebViewEvents__OnTitleChanged
10251031
1026- Func __NetWebView2_WebViewEvents__OnNavigationStarting($sNewUrl )
1027- Local Const $s_Prefix = " [WebViewEvents__OnNavigationStarting]: URL: " & $sNewUrl
1032+ #TODO = > Func __NetWebView2_WebViewEvents__OnNavigationStarting(ByRef $oWebV2M , $hGUI , $sURL )
1033+ Func __NetWebView2_WebViewEvents__OnNavigationStarting($sURL )
1034+ Local Const $s_Prefix = " [WebViewEvents__OnNavigationStarting]: URL: " & $sURL
10281035 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
10291036EndFunc ; ==>__NetWebView2_WebViewEvents__OnNavigationStarting
10301037
1038+ #TODO = > Func __NetWebView2_WebViewEvents__OnNavigationCompleted(ByRef $oWebV2M , $hGUI , $bIsSuccess , $iWebErrorStatus )
10311039Func __NetWebView2_WebViewEvents__OnNavigationCompleted($bIsSuccess , $iWebErrorStatus )
10321040 Local Const $s_Prefix = " [WebViewEvents__OnNavigationCompleted]: IsSuccess: " & $bIsSuccess & " WebErrorStatus: " & $iWebErrorStatus
10331041 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
10341042EndFunc ; ==>__NetWebView2_WebViewEvents__OnNavigationCompleted
10351043
1036- #TODO = > Func __NetWebView2_WebViewEvents__OnContextMenuRequested(ByRef $oWebV2M , $sLink , $iX , $iY , $sSelection )
1044+ #TODO = > Func __NetWebView2_WebViewEvents__OnContextMenuRequested(ByRef $oWebV2M , $hGUI , $ sLink , $iX , $iY , $sSelection )
10371045Func __NetWebView2_WebViewEvents__OnContextMenuRequested($sLink , $iX , $iY , $sSelection )
10381046 Local Const $s_Prefix = " [WebViewEvents__OnContextMenuRequested]: LINK: " & $sLink & " X: " & $iX & " Y: " & $iY & " SELECTION: " & $sSelection
10391047 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
10401048EndFunc ; ==>__NetWebView2_WebViewEvents__OnContextMenuRequested
10411049
1050+ #TODO = > Func __NetWebView2_WebViewEvents__OnContextMenu(ByRef $oWebV2M , $hGUI , $sMenuData )
10421051Func __NetWebView2_WebViewEvents__OnContextMenu($sMenuData )
10431052 Local Const $s_Prefix = " [WebViewEvents__OnContextMenu]: MENUDATA: " & $sMenuData
10441053 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 )
10451054EndFunc ; ==>__NetWebView2_WebViewEvents__OnContextMenu
1055+
1056+ #TODO = > Func __NetWebView2_WebViewEvents__OnDownloadStarting(ByRef $oWebV2M , $hGUI , $sUri , $sDefaultPath )
1057+ Func __NetWebView2_WebViewEvents__OnDownloadStarting($sUri , $sDefaultPath ) ; Listen for Manager OnDownloadStarting Events
1058+ ConsoleWrite (" -> [OnDownloadStarting]:: $sUri: " & $sUri & " , $sDefaultPath: " & $sDefaultPath & @CRLF )
1059+
1060+ ; --- STANDARD MODE (EDGE) ---
1061+ ; If you do nothing, Edge will download to the $sDefaultPath.
1062+ ; If you previously set $oWeb.SetDownloadPath("C:\MyFolder"), it will go there.
1063+
1064+ ; --- MANUAL MODE (BYPASS EDGE) ---
1065+ ; If you want to handle the download yourself with InetGet:
1066+ ; $oWeb.IsDownloadHandled = True
1067+ ; InetGet($sUri, @ScriptDir & "\Manual_Download.zip", 1, 1) ; 1 = wait for completion, 1 = force reload
1068+ ; ConsoleWrite("--> Edge download CANCELLED. AutoIt is handling it via InetGet." & @CRLF)
1069+
1070+ ConsoleWrite (" <- OnDownloadStarting event finished. Standard Edge download proceeds unless IsDownloadHandled=True." & @CRLF )
1071+ EndFunc ; ==>__NetWebView2_WebViewEvents__OnDownloadStarting
1072+
1073+ #TODO = > Func __NetWebView2_WebViewEvents__OnDownloadStateChanged(ByRef $oWebV2M , $hGUI , $sState , $sUri , $iTotalBytes , $iReceivedBytes )
1074+ Func __NetWebView2_WebViewEvents__OnDownloadStateChanged($sState , $sUri , $iTotal_Bytes , $iReceived_Bytes ) ; Listen for Manager OnDownloadStateChanged Events
1075+ Local Const $s_Prefix = " [WebViewEvents__OnDownloadStateChanged]: State: " & $sState & " Uri: " & $sUri & " Total_Bytes: " & $iTotal_Bytes & " Received_Bytes: " & $iReceived_Bytes
1076+ Local $iPercent = 0
1077+ If $iTotal_Bytes > 0 Then $iPercent = Round (($iReceived_Bytes / $iTotal_Bytes ) * 100 )
1078+
1079+ ; Convert to MB for easy-to-read log
1080+ Local $iReceived_MegaBytes = Round ($iReceived_Bytes / 1024 / 1024 )
1081+ Local $iTotal_MegaBytes = Round ($iTotal_Bytes / 1024 / 1024 )
1082+
1083+ Local Const $s_Message = " " & $iPercent & " % (" & $iReceived_MegaBytes & " / " & $iTotal_MegaBytes & " Mega Bytes)"
1084+ Switch $sState
1085+ Case " InProgress"
1086+ __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & $s_Message , 1 )
1087+ __NetWebView2_LastMessageReceived($NETWEBVIEW2_MESSAGE__DOWNLOAD_IN_PROGRESS )
1088+ Case " Interrupted"
1089+ __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & $s_Message , 1 )
1090+ __NetWebView2_LastMessageReceived($NETWEBVIEW2_MESSAGE__DOWNLOAD_INTERRUPTED )
1091+ Case " Completed"
1092+ ConsoleWrite (" --> DOWNLOAD_COMPLETED: Finished: " & $sUri & @CRLF )
1093+ __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & $s_Message , 1 )
1094+ __NetWebView2_LastMessageReceived($NETWEBVIEW2_MESSAGE__DOWNLOAD_COMPLETED )
1095+ EndSwitch
1096+ EndFunc ; ==>__NetWebView2_WebViewEvents__OnDownloadStateChanged
10461097#EndRegion ; NetWebView2Lib UDF - === EVENT HANDLERS ===
10471098
10481099
0 commit comments