Skip to content

Commit f3b494e

Browse files
authored
Merge pull request #124 from ioa747/v2.2.1-alpha1
V2.2.1 alpha1
2 parents e470298 + f753569 commit f3b494e

21 files changed

Lines changed: 500 additions & 139 deletions

NetWebView2Lib.au3

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#Tidy_Parameters=/tcb=-1
88

9-
; NetWebView2Lib.au3 - Script Version: 2.2.1-alpha (2026.03.20.09) 🚩
9+
; NetWebView2Lib.au3 - Script Version: 2.2.1-alpha1 (2026.04.14.10) 🚩
1010

1111
#include <Array.au3>
1212
#include <GUIConstantsEx.au3>
@@ -112,6 +112,7 @@ Global Enum _ ; $NETWEBVIEW2_MESSAGE__* are set by mainly by __NetWebView2_Event
112112
$NETWEBVIEW2_MESSAGE__COOKIE_ADD_ERROR, _
113113
$NETWEBVIEW2_MESSAGE__BLOCKED_AD, _
114114
$NETWEBVIEW2_MESSAGE__DOWNLOAD_STARTING, _
115+
$NETWEBVIEW2_MESSAGE__DOWNLOAD_CANCELLED, _ ; <<--( NEW )--<<
115116
$NETWEBVIEW2_MESSAGE__DOWNLOAD_IN_PROGRESS, _
116117
$NETWEBVIEW2_MESSAGE__DOWNLOAD_INTERRUPTED, _
117118
$NETWEBVIEW2_MESSAGE__DOWNLOAD_COMPLETED, _
@@ -152,12 +153,13 @@ Global Enum _ ; Indicates the reason for the process failure.
152153
; $bVerbose = False]]]])
153154
; Parameters ....: $sUserAgent - [optional] a string value. Default is "".
154155
; $s_fnEventPrefix - [optional] a string value. Default is "".
155-
; $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.
156+
; $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.
156157
; $bVerbose - [optional] True/False - Enable/Disable diagnostic logging. Default is False = Disabled.
157158
; Return values .: None
158159
; Author ........: mLipok, ioa747
159160
; Modified ......:
160-
; Remarks .......: $s_AddBrowserArgs must be set before calling Initialize().
161+
; Remarks .......: $s_AddBrowserArgs must be set before calling _NetWebView2_Initialize().
162+
; Multiple arguments must be separated by a SPACE, not a comma (e.g., "--mute-audio --disable-gpu").
161163
; Related .......:
162164
; Link ..........: https://www.chromium.org/developers/how-tos/run-chromium-with-flags
163165
; Link ..........: https://chromium.googlesource.com/chromium/src/+/main/docs/configuration.md#switches
@@ -2102,6 +2104,10 @@ Volatile Func __NetWebView2_Events__OnMessageReceived($oWebV2M, $hGUI, $sMsg)
21022104
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " COMMAND:" & $sCommand, 1)
21032105
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__DOWNLOAD_STARTING)
21042106

2107+
Case "DOWNLOAD_CANCELLED"
2108+
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " COMMAND:" & $sCommand, 1)
2109+
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__DOWNLOAD_CANCELLED) ; <<--( NEW )--<<
2110+
21052111
Case "BROWSER_GOT_FOCUS"
21062112
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " COMMAND:" & $sCommand, 1)
21072113
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__BROWSER_GOT_FOCUS)
@@ -2405,46 +2411,55 @@ EndFunc ;==>__NetWebView2_Events__OnContextMenu
24052411

24062412
; #INTERNAL_USE_ONLY# ===========================================================================================================
24072413
; Name ..........: __NetWebView2_Events__OnWebResourceResponseReceived
2408-
; Description ...:
2409-
; Syntax ........: __NetWebView2_Events__OnWebResourceResponseReceived($oWebV2M, $hGUI, $iStatusCode, $sReasonPhrase,
2410-
; $sRequestUrl)
2414+
; Description ...: Internal handler for the WebResourceResponseReceived event.
2415+
; Syntax ........: __NetWebView2_Events__OnWebResourceResponseReceived($oWebV2M, $hGUI, $oArgs)
24112416
; Parameters ....: $oWebV2M - WebView2 object that fired the event
2412-
; $hGUI - a handle to Window that fired the event
2413-
; $iStatusCode - HTTP StatusCode
2414-
; $sReasonPhrase - StatusCode rephrased to human resonable string
2415-
; $sRequestUrl - the URL that fired the event
2417+
; $hGUI - A handle to Window that fired the event
2418+
; $oArgs - An Event Arguments Object containing:
2419+
; | .StatusCode (int) [RO]: The HTTP status code (e.g., 200, 404).
2420+
; | .ReasonPhrase (string) [RO]: The HTTP reason phrase (e.g., "OK").
2421+
; | .RequestUri (string) [RO]: The URL of the request.
2422+
; | .IsDocument (bool) [RO]: True if the resource is the main document.
24162423
; Return values .: None
2417-
; Author ........: mLipok
2418-
; Modified ......:
2424+
; Author ........: ioa747, mLipok
2425+
; Modified ......: 2026-04-14 (Refactored to Object-Oriented Event Model)
24192426
; Remarks .......:
24202427
; Related .......:
24212428
; Link ..........: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.webresourceresponsereceived
2422-
; Example .......: No
2429+
; Example .......: 007-HTTP_StatusCodeTracking.au3
24232430
; ===============================================================================================================================
2424-
Volatile Func __NetWebView2_Events__OnWebResourceResponseReceived($oWebV2M, $hGUI, $iStatusCode, $sReasonPhrase, $sRequestUrl)
2425-
Local Const $s_Prefix = ">>>[EVENT: OnWebResourceResponseReceived]: GUI:" & $hGUI & " HTTPStatusCode:" & $iStatusCode & " (" & $sReasonPhrase & ") URL:" & $sRequestUrl
2426-
__NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1)
2431+
Volatile Func __NetWebView2_Events__OnWebResourceResponseReceived($oWebV2M, $hGUI, $oArgs) ; <<--( NEW )--<<
2432+
Local Const $s_Prefix = ">>>[EVENT: OnWebResourceResponseReceived]: GUI:" & $hGUI & _
2433+
" HTTPStatusCode:" & $oArgs.StatusCode & " (" & $oArgs.ReasonPhrase & ") URL:" & $oArgs.RequestUri & " URL:" & $oArgs.IsDocument
2434+
2435+
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1)
24272436
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__RESPONSE_RECEIVED)
24282437
EndFunc ;==>__NetWebView2_Events__OnWebResourceResponseReceived
24292438

24302439
; #INTERNAL_USE_ONLY# ===========================================================================================================
24312440
; Name ..........: __NetWebView2_Events__OnDownloadStarting
2432-
; Description ...:
2433-
; Syntax ........: __NetWebView2_Events__OnDownloadStarting($oWebV2M, $hGUI, $sURL, $sDefaultPath)
2434-
; Parameters ....: $oWebV2M - an object.
2435-
; $hGUI - a handle value.
2436-
; $sURL - a string value.
2437-
; $sDefaultPath - a string value.
2441+
; Description ...: Internal handler for the DownloadStarting event. Dispatches the event to the user's callback with an Args Object.
2442+
; Syntax ........: __NetWebView2_Events__OnDownloadStarting($oWebV2M, $hGUI, $oArgs)
2443+
; Parameters ....: $oWebV2M - The WebView2 Manager object.
2444+
; $hGUI - The handle to the GUI window.
2445+
; $oArgs - An Event Arguments Object containing:
2446+
; | .Uri (String) [RO]: The source URL of the download.
2447+
; | .MimeType (String) [RO]: The MIME type (e.g., "application/pdf").
2448+
; | .ContentDisposition (String) [RO]: The HTTP Content-Disposition header.
2449+
; | .TotalBytesToReceive (Int64) [RO]: Total size in bytes (-1 if unknown).
2450+
; | .ResultFilePath (String) [RW]: Get/Set the full target save path.
2451+
; | .Cancel (Boolean) [RW]: Set to True to abort the download.
2452+
; | .Handled (Boolean) [RW]: Set to True to exit the C# wait loop immediately.
24382453
; Return values .: None
24392454
; Author ........: ioa747, mLipok
2440-
; Modified ......:
2441-
; Remarks .......:
2442-
; Related .......:
2443-
; Link ..........:
2444-
; Example .......: No
2455+
; Modified ......: 2026-04-14 (Refactored to Object-Oriented Event Model)
2456+
; Remarks .......: This event uses a 5000ms synchronization loop in C# to allow for AutoIt interaction (e.g., MsgBox).
2457+
; Related .......: _NetWebView2_CreateManager
2458+
; Link ..........: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2downloadstartingeventargs
2459+
; Example .......: 021 - Handle Unviewable Content (MIME).au3
24452460
; ===============================================================================================================================
2446-
Volatile Func __NetWebView2_Events__OnDownloadStarting($oWebV2M, $hGUI, $sURL, $sDefaultPath)
2447-
Local Const $s_Prefix = ">>>[EVENT: OnDownloadStarting]: GUI:" & $hGUI & " URL:" & $sURL & " DEFAULT_PATH:" & $sDefaultPath
2461+
Volatile Func __NetWebView2_Events__OnDownloadStarting($oWebV2M, $hGUI, $oArgs) ; <<--( NEW )--<<
2462+
Local Const $s_Prefix = "[>>>EVENT: OnDownloadStarting]: GUI:" & $hGUI & " URL: " & $oArgs.Uri & " PATH: " & $oArgs.ResultFilePath & " MIME: " & $oArgs.MimeType
24482463
__NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1)
24492464
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__DOWNLOAD_STARTING)
24502465
EndFunc ;==>__NetWebView2_Events__OnDownloadStarting
@@ -2456,48 +2471,56 @@ EndFunc ;==>__NetWebView2_Events__OnDownloadStarting
24562471
; $iReceived_Bytes)
24572472
; Parameters ....: $oWebV2M - an object.
24582473
; $hGUI - a handle value.
2459-
; $sState - a string value.
2460-
; $sURL - a string value.
2461-
; $iTotal_Bytes - an integer value.
2462-
; $iReceived_Bytes - an integer value.
2474+
; $oArgs - An Event Arguments Object containing:
2475+
; | .Uri (String) [RO]: The source URL of the download.
2476+
; | .State (String) [RO]: The current state ("InProgress", "Completed", "Interrupted").
2477+
; | .TotalBytesToReceive (int) [RO]: Estimated total size.
2478+
; | .BytesReceived (int) [RO]: Number of bytes received so far.
2479+
; | .PercentComplete (int) [RO]: Calculation (0-100) or -1 if unknown.
24632480
; Return values .: None
24642481
; Author ........: ioa747, mLipok
24652482
; Modified ......:
24662483
; Remarks .......:
24672484
; Related .......:
24682485
; Link ..........:
2469-
; Example .......: No
2486+
; Example .......: 006-DownloadDemo.au3
24702487
; ===============================================================================================================================
2471-
Volatile Func __NetWebView2_Events__OnDownloadStateChanged($oWebV2M, $hGUI, $sState, $sURL, $iTotal_Bytes, $iReceived_Bytes)
2472-
Local Const $s_Prefix = ">>>[EVENT: OnDownloadStateChanged]: GUI:" & $hGUI & " State:" & $sState & " URL:" & $sURL & " Total_Bytes:" & $iTotal_Bytes & " Received_Bytes:" & $iReceived_Bytes
2473-
Local $iPercent = 0
2474-
If $iTotal_Bytes > 0 Then $iPercent = Round(($iReceived_Bytes / $iTotal_Bytes), 5) * 100
2488+
Volatile Func __NetWebView2_Events__OnDownloadStateChanged($oWebV2M, $hGUI, $oArgs) ; <<--( NEW )--<<
2489+
Local $iReceived_MB = Round($oArgs.BytesReceived / 1048576, 2) ; 1024*1024
2490+
Local $iTotal_MB = Round($oArgs.TotalBytesToReceive / 1048576, 2)
2491+
2492+
Local Const $s_Prefix = "[>>>EVENT: OnDownloadStateChanged]: GUI:" & $hGUI & " State: " & $oArgs.State & " | " & _
2493+
$oArgs.PercentComplete & "% (" & $iReceived_MB & "/" & $iTotal_MB & " MB) URL: " & $oArgs.Uri
24752494

2476-
; Convert to MB for easy-to-read log
2477-
Local $iReceived_MegaBytes = Round($iReceived_Bytes / 1024 / 1024)
2478-
Local $iTotal_MegaBytes = Round($iTotal_Bytes / 1024 / 1024)
2495+
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1)
24792496

2480-
Local Const $s_Message = " " & $iPercent & "% (" & $iReceived_MegaBytes & " / " & $iTotal_MegaBytes & " Mega Bytes)"
2481-
Switch $sState
2497+
Switch $oArgs.State
24822498
Case "InProgress"
2483-
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $s_Message, 1)
24842499
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__DOWNLOAD_IN_PROGRESS)
24852500
Case "Interrupted"
2486-
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $s_Message, 1)
24872501
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__DOWNLOAD_INTERRUPTED)
24882502
Case "Completed"
2489-
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $s_Message, 1)
24902503
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__DOWNLOAD_COMPLETED)
24912504
EndSwitch
2492-
EndFunc ;==>__NetWebView2_Events__OnDownloadStateChanged
2505+
EndFunc
24932506

24942507
; #INTERNAL_USE_ONLY# ===========================================================================================================
24952508
; Name ..........: __NetWebView2_Events__OnAcceleratorKeyPressed
2496-
; Description ...:
2509+
; Description ...: It allows the application to intercept and handle system keys and keyboard shortcuts (Accelerators) before the WebView2 engine processes them.
24972510
; Syntax ........: __NetWebView2_Events__OnAcceleratorKeyPressed($oWebV2M, $hGUI, $oArgs)
24982511
; Parameters ....: $oWebV2M - an object.
24992512
; $hGUI - a handle value.
2500-
; $oArgs - an object.
2513+
; $oArgs - An Event Arguments Object containing:
2514+
; | .VirtualKey (uint) [RO]: The VK code of the key.
2515+
; | .KeyEventKind (int) [RO]: Type of key event (0:KeyDown, 1:KeyUp, etc.).
2516+
; | .RepeatCount (uint) [RO]: The number of times the key has repeated.
2517+
; | .ScanCode (uint) [RO]: Hardware scan code.
2518+
; | .IsExtendedKey (bool) [RO]: True if it's an extended key (e.g., right Alt).
2519+
; | .IsMenuKeyDown (bool) [RO]: True if Alt is pressed.
2520+
; | .WasKeyDown (bool) [RO]: True if the key was already down.
2521+
; | .IsKeyReleased (bool) [RO]: True if the event is a key up.
2522+
; | .KeyEventLParam (int) [RO]: The native LPARAM window message value.
2523+
; | .Handled (bool) [RW]: Set to True to prevent the browser from executing the default action.
25012524
; Return values .: None
25022525
; Author ........: ioa747, mLipok
25032526
; Modified ......:

0 commit comments

Comments
 (0)