Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions NetWebView2Lib.au3
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#Tidy_Parameters=/tcb=-1

; NetWebView2Lib.au3 - Script Version: 2.2.1-alpha1 (2026.04.14.10) ๐Ÿšฉ
; NetWebView2Lib.au3 - Script Version: 2.2.2-alpha (2026.06.27.19) ๐Ÿšฉ

#include <Array.au3>
#include <GUIConstantsEx.au3>
Expand Down Expand Up @@ -150,23 +150,25 @@ Global Enum _ ; Indicates the reason for the process failure.
; Name ..........: _NetWebView2_CreateManager
; Description ...: Create WebView2 object
; Syntax ........: _NetWebView2_CreateManager([$sUserAgent = ""[, $s_fnEventPrefix = ""[, $s_AddBrowserArgs = ""[,
; $bVerbose = False]]]])
; 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.
; $bVerbose = False[, $iThrottlingIntervalMs = 20]]]]])
; 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") to the Chromium engine.
; $bVerbose - [optional] True/False - Enable/Disable diagnostic logging. Default is False = Disabled.
; $iThrottlingIntervalMs - [optional] an integer value. Default is 20.
; Sets the JS-to-AutoIt message throttling interval in ms. Set to 0 to disable throttling.
; Return values .: None
; Author ........: mLipok, ioa747
; Modified ......:
; Remarks .......: $s_AddBrowserArgs must be set before calling _NetWebView2_Initialize().
; Multiple arguments must be separated by a SPACE, not a comma (e.g., "--mute-audio --disable-gpu").
; Remarks .......: $s_AddBrowserArgs must be set before calling Initialize().
; Related .......:
; Link ..........: https://www.chromium.org/developers/how-tos/run-chromium-with-flags
; Link ..........: https://chromium.googlesource.com/chromium/src/+/main/docs/configuration.md#switches
; 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, $iThrottlingIntervalMs = 20)
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
Expand All @@ -184,6 +186,7 @@ Func _NetWebView2_CreateManager($sUserAgent = "", $s_fnEventPrefix = "", $s_AddB
; 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
$oWebV2M.ThrottlingIntervalMs = $iThrottlingIntervalMs
;~ If $_g_bNetWebView2_DebugDev Then __NetWebView2_ObjName_FlagsValue($oWebV2M) ; FOR DEV TESTING ONLY

If $sUserAgent Then $oWebV2M.SetUserAgent($sUserAgent)
Expand Down Expand Up @@ -760,7 +763,7 @@ Func _NetWebView2_NavigateToString($oWebV2M, $s_HTML, $iWaitMessage = $NETWEBVIE
_NetWebView2_LoadWait($oWebV2M, $iWaitMessage, $sExpectedTitle, $iTimeOut_ms)
$ERR = @error
$EXT = @extended
$MSG = " LoadWait internal Error" & " #SLN=" & @ScriptLineNumber
$MSG = ($ERR ? " LoadWait internal Error" : " Success") & " #SLN=" & @ScriptLineNumber
EndIf
$oWebV2M.UnLockWebView()
EndIf
Expand Down Expand Up @@ -1859,7 +1862,7 @@ EndFunc ;==>__NetWebView2_freezer
#EndRegion ; === NetWebView2Lib UDF === #INTERNAL_USE_ONLY#

#Region ; === NetWebView2Lib UDF === EVENT HANDLERS ***** Collection *****

; *******************************************************************************************************************************
#Region ; === NetWebView2Lib UDF === EVENT HANDLERS === Error Handlers ===
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __NetWebView2_SilentErrorHandler
Expand Down Expand Up @@ -2807,5 +2810,5 @@ EndFunc ;==>__NetWebView2_Events__FrameKeeper
;~ https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2frame?view=webview2-winrt-1.0.3595.46#screencapturestarting
;~ EndFunc ;==>__NetWebView2_Events__OnScreenCaptureStarting
#EndRegion ; === NetWebView2Lib UDF === EVENT HANDLERS * #TODO ===

; *******************************************************************************************************************************
#EndRegion ; === NetWebView2Lib UDF === EVENT HANDLERS ***** Collection *****
82 changes: 12 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ A powerful bridge that allows **AutoIt** to use the modern **Microsoft Edge WebV
https://www.autoitscript.com/forum/topic/213375-webview2autoit-autoit-webview2-component-com-interop

---

### ๐Ÿš€ Key Features

* **Chromium Engine**: Leverage the speed and security of modern Microsoft Edge.
Expand All @@ -29,7 +28,6 @@ https://www.autoitscript.com/forum/topic/213375-webview2autoit-autoit-webview2-c
* *The registration script will check for this and provide a download link if missing.*

---

### ๐Ÿ“ฆ Deployment & Installation

1. **Extract** the `NetWebView2Lib` folder to a permanent location.
Expand All @@ -56,7 +54,6 @@ https://www.autoitscript.com/forum/topic/213375-webview2autoit-autoit-webview2-c


---

### โš–๏ธ License

This project is provided "as-is". You are free to use, modify, and distribute it for both personal and commercial projects.
Expand All @@ -66,84 +63,25 @@ This project is provided "as-is". You are free to use, modify, and distribute it
<img src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png" width="100%">
</p>

## ๐Ÿš€ What's New in v2.2.1-alpha1 - UI Responsiveness & Refactoring

This release marks a major architectural milestone for the library by introducing **Event Object Refactoring**. Key events have been transitioned from passing raw data (strings) to passing full **COM-visible objects**, granting developers absolute control over the application's navigation flow.

### โšก Key Features & Enhancements

#### 1. Advanced Navigation Control (`IWebView2NavigationStartingEventArgs`)
Navigation is no longer a passive process.
With the new `Args` object, you can programmatically intervene in the navigation lifecycle before it even begins.

- **`Cancel` [Property]**: The ability to kill a navigation request at its source. Perfect for content filtering, security, and custom protocol handling.

- **`IsUserInitiated`**: Determine whether the navigation was triggered by a physical user click or programmatically via JavaScript.

- **`IsRedirected`**: Automatically detect if the current request is a server-side or client-side redirect.

- **`NavigationId`**: A unique identifier for precise request tracking across complex web sessions.

#### 2. Event Object Refactoring & API Maturity
We are moving away from "Raw Parameter" callbacks toward an **Object-Oriented Event Model**.

- **Breaking Change**: `OnNavigationStarting` and `OnFrameNavigationStarting` now return an **Args Object**. This change is essential to support bi-directional communication (e.g., AutoIt telling C# to `Cancel = True`).

- **Future-Proofing**: Adding new metadata in future WebView2 updates will no longer break existing user code, as new properties will simply be appended to the existing object.

#### 3. UI Responsiveness & Interception-Based Locking (Critical Patch)
Following the initial alpha release, we identified and resolved a critical issue where Developer Tools (F12) and Right-Click menus could become unresponsive after navigation.

- **Interception-Based Locking**: We moved away from toggling engine-level properties (which caused state lag) to a robust **C# Interception Model**. Features are kept "On" at the engine level but are blocked via the `_isLocked` flag in C#, ensuring the "Inspect" menu item never disappears.

- **C# Fast Path**: Common actions like F12 are now handled instantly within the C# layer, bypassing the AutoIt COM overhead for maximum performance.

- **Guaranteed Unlock**: Improved the AutoIt navigation functions (`_NetWebView2_Navigate`) to ensure the browser is always unlocked, even if a navigation times out or fails.

#### 4. Refactored: OnDownloadStarting Event
- **Transitioned from a parameter-based signature to a robust, object-oriented argument model.**
- **New Argument Wrapper**: `IWebView2DownloadStartingEventArgs` provides access to `Uri`, `ResultFilePath`, `Handled`, `Cancel`, `MimeType`, `ContentDisposition`, and `TotalBytesToReceive`.

- **Hybrid Deferral Model**: Implemented a performance-optimized synchronization mechanism using `CoreWebView2Deferral`. The C# core now waits up to 5000ms for AutoIt to set `Handled` or `Cancel` on the argument object, proceeding immediately once a decision is made.

- **MimeType Support (Issue #123)**: Exposed `MimeType` directly in the download arguments, allowing AutoIt scripts to identify "unviewable content" (e.g., PDFs, ZIPs) at the start of the download lifecycle.

- **Improved: Download Logic**: Automatic redirection to `_customDownloadPath` is now applied *before* the event fires, allowing **AutoIt** to see and potentially override the final destination.

#### 5. Refactored: OnDownloadStateChanged Event
- **Transitioned to an object-oriented argument model for consistent event handling.**
- **New Argument Wrapper**: `IWebView2DownloadStateChangedEventArgs`
provides access to `State`, `Uri`, `TotalBytesToReceive`, `BytesReceived`, and a new `PercentComplete` helper.

- **Buffered Property Pattern**: Applied to ensure thread-safe progress updates during rapid download cycles.

#### 6. Fixed: HTTP Status Code Detection
- Resolved a bug where `OnWebResourceResponseReceived` failed to fire due to a missing legacy header hack. Replaced with native `ResourceContext` detection.


## ๐Ÿš€ What's New in v2.2.2-alpha - Configurable Message Throttling

> [!CAUTION]
> **Breaking Change**: If you have custom scripts using `OnWebResourceResponseReceived` or `OnDownloadStateChanged`, please update their signatures to use the new `$oArgs` object as demonstrated in the updated examples.
Provide a configurable throttling mechanism for messages sent from JavaScript to AutoIt via the WebView2 bridge to prevent message loss when throttling is too restrictive for certain use cases, while keeping safety defaults.

### โšก Key Features & Enhancements

### ๐Ÿ—๏ธ Architectural Inheritance & Refactoring

Building on the foundation of v2.1.0, this version further strengthens the **Event Wrapper** hierarchy:

- **Base Inheritance**: All new event objects inherit from `BaseWebViewEventArgs`, ensuring that core properties like `WindowHandle` and the `ManagerInstance` are consistently available.

- **Uniformity**: Whether you are handling a sub-frame or the main browser instance, the parameter logic remains predictable and standardized.


> **Why this matters:** The shift to objects transforms **NetWebView2Lib** from a "simple browser wrapper" into a **Professional-Grade SDK** for AutoIt. It brings low-level controlโ€”previously reserved for languages like C# or C++โ€”directly into the hands of the AutoIt developer.
#### 1. Implement the ThrottlingIntervalMs property on the manager class, forwarding to the bridge object.

- **`ThrottlingIntervalMs` [Property]**: Gets or sets the throttling interval in milliseconds for messages sent from JavaScript to AutoIt.
Set to 0 to disable throttling entirely.
Default is 20 ms.

<p align="center">
<img src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png" width="100%">
</p>


## ๐Ÿ“– NetWebView2Lib Version 2.2.1-alpha (Quick Reference)
## ๐Ÿ“– NetWebView2Lib Version 2.2.2-alpha (Quick Reference)


### ๐ŸŸฆ WebView2Manager (ProgId: NetWebView2Lib.WebView2Manager)
Expand Down Expand Up @@ -202,6 +140,10 @@ Enables or disables custom context menu handling.
Sets additional command-line arguments to be passed to the Chromium engine during initialization. Must be set BEFORE calling Initialize().
`object.AdditionalBrowserArguments = Value`

##### ๐Ÿ”ง ThrottlingIntervalMs
Gets or sets the throttling interval in milliseconds for messages sent from JavaScript to AutoIt. Set to 0 to disable throttling entirely. Default is 20ms.
`object.ThrottlingIntervalMs` = 20

##### ๐Ÿ”ง HiddenPdfToolbarItems
Controls the visibility of buttons in the PDF viewer toolbar using a bitwise combination of CoreWebView2PdfToolbarItems (e.g., 1=Save, 2=Print, 4=Search).
`object.HiddenPdfToolbarItems = Value`
Expand Down
Binary file modified bin/x64/NetWebView2Lib.dll
Binary file not shown.
Binary file modified bin/x64/NetWebView2Lib.tlb
Binary file not shown.
Binary file modified bin/x86/NetWebView2Lib.dll
Binary file not shown.
Binary file modified bin/x86/NetWebView2Lib.tlb
Binary file not shown.
Loading