Skip to content

Commit 230a2f3

Browse files
authored
v2.2.0-alpha
1 parent 484e3cb commit 230a2f3

11 files changed

Lines changed: 71 additions & 16 deletions

NetWebView2Lib.au3

Lines changed: 9 additions & 7 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: 2026.2.25.11 🚩
9+
; NetWebView2Lib.au3 - Script Version: 2026.3.17.12 🚩
1010

1111
#include <Array.au3>
1212
#include <GUIConstantsEx.au3>
@@ -1948,10 +1948,10 @@ EndFunc ;==>__NetWebView2_Events__OnTitleChanged
19481948
; #INTERNAL_USE_ONLY# ===========================================================================================================
19491949
; Name ..........: __NetWebView2_Events__OnNavigationStarting
19501950
; Description ...:
1951-
; Syntax ........: __NetWebView2_Events__OnNavigationStarting($oWebV2M, $hGUI, $sURL)
1951+
; Syntax ........: __NetWebView2_Events__OnNavigationStarting($oWebV2M, $hGUI, $oArgs)
19521952
; Parameters ....: $oWebV2M - an object.
19531953
; $hGUI - a handle value.
1954-
; $sURL - a string value.
1954+
; $oArgs - an object.
19551955
; Return values .: None
19561956
; Author ........: ioa747, mLipok
19571957
; Modified ......:
@@ -1960,7 +1960,8 @@ EndFunc ;==>__NetWebView2_Events__OnTitleChanged
19601960
; Link ..........:
19611961
; Example .......: No
19621962
; ===============================================================================================================================
1963-
Volatile Func __NetWebView2_Events__OnNavigationStarting($oWebV2M, $hGUI, $sURL)
1963+
Volatile Func __NetWebView2_Events__OnNavigationStarting($oWebV2M, $hGUI, $oArgs)
1964+
Local $sURL = $oArgs.Uri
19641965
Local Const $s_Prefix = "[EVENT: OnNavigationStarting]: GUI:" & $hGUI & " URL: " & $sURL
19651966
__NetWebView2_Log(@ScriptLineNumber, (StringLen($s_Prefix) > 150 ? StringLeft($s_Prefix, 150) & "..." : $s_Prefix), 1)
19661967
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__NAV_STARTING)
@@ -2303,11 +2304,11 @@ EndFunc ;==>__NetWebView2_Events__OnFrameNameChanged
23032304
; #INTERNAL_USE_ONLY# ===========================================================================================================
23042305
; Name ..........: __NetWebView2_Events__OnFrameNavigationStarting
23052306
; Description ...: Handles Frame NavigationStarting event
2306-
; Syntax ........: __NetWebView2_Events__OnFrameNavigationStarting($oWebV2M, $hGUI, $oFrame, $sUri)
2307+
; Syntax ........: __NetWebView2_Events__OnFrameNavigationStarting($oWebV2M, $hGUI, $oFrame, $oArgs)
23072308
; Parameters ....: $oWebV2M - an object.
23082309
; $hGUI - a handle value.
23092310
; $oFrame - an Frame object.
2310-
; $sUri - a string value.
2311+
; $oArgs - an object.
23112312
; Return values .: None
23122313
; Author ........: ioa747
23132314
; Modified ......:
@@ -2316,7 +2317,8 @@ EndFunc ;==>__NetWebView2_Events__OnFrameNameChanged
23162317
; Link ..........: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2frame.navigationstarting
23172318
; Example .......: No
23182319
; ===============================================================================================================================
2319-
Volatile Func __NetWebView2_Events__OnFrameNavigationStarting($oWebV2M, $hGUI, $oFrame, $sUri)
2320+
Volatile Func __NetWebView2_Events__OnFrameNavigationStarting($oWebV2M, $hGUI, $oFrame, $oArgs)
2321+
Local $sUri = $oArgs.Uri
23202322
Local Const $s_Prefix = "[EVENT: OnFrameNavigationStarting]: WebV2M: " & VarGetType($oWebV2M) & " GUI:" & $hGUI & " Frame:" & VarGetType($oFrame) & " Uri:" & $sUri
23212323
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1)
23222324
; __NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__FRAME_NAV_STARTING) ; Optional: Update status if needed

bin/x64/NetWebView2Lib.dll

1 KB
Binary file not shown.

bin/x64/NetWebView2Lib.tlb

1.14 KB
Binary file not shown.

bin/x86/NetWebView2Lib.dll

1 KB
Binary file not shown.

bin/x86/NetWebView2Lib.tlb

1.14 KB
Binary file not shown.

src/Core/WebView2Manager.Events.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public partial class WebView2Manager
1414

1515
/// <summary>Delegate for message events.</summary>
1616
public delegate void OnMessageReceivedDelegate(object sender, string parentHandle, string message);
17-
public delegate void OnNavigationStartingDelegate(object sender, string parentHandle, string url);
17+
public delegate void OnNavigationStartingDelegate(object sender, string parentHandle, object args);
1818
public delegate void OnNavigationCompletedDelegate(object sender, string parentHandle, bool isSuccess, int webErrorStatus);
1919
public delegate void OnTitleChangedDelegate(object sender, string parentHandle, string newTitle);
2020
public delegate void OnURLChangedDelegate(object sender, string parentHandle, string newUrl);
@@ -31,7 +31,7 @@ public partial class WebView2Manager
3131
public delegate void OnBasicAuthenticationRequestedDelegate(object sender, string parentHandle, object args);
3232
public delegate void OnPermissionRequestedDelegate(object sender, string parentHandle, object args);
3333

34-
public delegate void OnFrameNavigationStartingDelegate(object sender, string parentHandle, object frame, string uri);
34+
public delegate void OnFrameNavigationStartingDelegate(object sender, string parentHandle, object frame, object args);
3535
public delegate void OnFrameNavigationCompletedDelegate(object sender, string parentHandle, object frame, bool isSuccess, int webErrorStatus);
3636
public delegate void OnFrameContentLoadingDelegate(object sender, string parentHandle, object frame, long navigationId);
3737
public delegate void OnFrameDOMContentLoadedDelegate(object sender, string parentHandle, object frame, long navigationId);
@@ -165,7 +165,7 @@ private void RegisterEvents()
165165

166166
// Navigation & Content Events
167167
_webView.CoreWebView2.NavigationStarting += (s, e) => {
168-
OnNavigationStarting?.Invoke(this, FormatHandle(_parentHandle), e.Uri);
168+
OnNavigationStarting?.Invoke(this, FormatHandle(_parentHandle), new WebView2NavigationStartingEventArgsWrapper(e, _parentHandle));
169169
OnMessageReceived?.Invoke(this, FormatHandle(_parentHandle), "NAV_STARTING|" + e.Uri);
170170
};
171171

src/Core/WebView2Manager.FrameMgmt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private void RegisterFrame(CoreWebView2Frame frame)
2525
frame.NavigationStarting += (s, e) =>
2626
{
2727
lock (_frameUrls) { _frameUrls[frame] = e.Uri; }
28-
InvokeOnUiThread(() => OnFrameNavigationStarting?.Invoke(this, FormatHandle(_parentHandle), new WebView2Frame(frame, this), e.Uri));
28+
InvokeOnUiThread(() => OnFrameNavigationStarting?.Invoke(this, FormatHandle(_parentHandle), new WebView2Frame(frame, this), new WebView2NavigationStartingEventArgsWrapper(e, _parentHandle)));
2929
};
3030
frame.NavigationCompleted += (s, e) =>
3131
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using Microsoft.Web.WebView2.Core;
4+
5+
namespace NetWebView2Lib
6+
{
7+
[Guid("D2B8A1C4-F5E6-4A5B-9C1D-8E1F2A3B4C5D")]
8+
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
9+
[ComVisible(true)]
10+
public interface IWebView2NavigationStartingEventArgs : IBaseWebViewEventArgs
11+
{
12+
[DispId(1)] string Uri { get; }
13+
[DispId(2)] bool IsUserInitiated { get; }
14+
[DispId(3)] bool IsRedirected { get; }
15+
[DispId(4)] object RequestHeaders { get; }
16+
[DispId(5)] bool Cancel { get; set; }
17+
[DispId(6)] long NavigationId { get; }
18+
[DispId(7)] int NavigationKind { get; }
19+
[DispId(8)] string AdditionalAllowedFrameAncestors { get; set; }
20+
}
21+
22+
[ClassInterface(ClassInterfaceType.None)]
23+
[ComVisible(true)]
24+
[Guid("E3C4D5F6-A7B8-4C9D-0E1F-2A3B4C5D6E7F")] // Unique GUID for this wrapper
25+
public class WebView2NavigationStartingEventArgsWrapper : BaseWebViewEventArgs, IWebView2NavigationStartingEventArgs
26+
{
27+
private readonly CoreWebView2NavigationStartingEventArgs _args;
28+
29+
public WebView2NavigationStartingEventArgsWrapper(CoreWebView2NavigationStartingEventArgs args, IntPtr parentHandle)
30+
{
31+
_args = args;
32+
InitializeSender(parentHandle);
33+
}
34+
35+
public string Uri => _args.Uri;
36+
public bool IsUserInitiated => _args.IsUserInitiated;
37+
public bool IsRedirected => _args.IsRedirected;
38+
public object RequestHeaders => _args.RequestHeaders;
39+
public bool Cancel
40+
{
41+
get => _args.Cancel;
42+
set => _args.Cancel = value;
43+
}
44+
public long NavigationId => (long)_args.NavigationId;
45+
public int NavigationKind => (int)_args.NavigationKind;
46+
public string AdditionalAllowedFrameAncestors
47+
{
48+
get => _args.AdditionalAllowedFrameAncestors;
49+
set => _args.AdditionalAllowedFrameAncestors = value;
50+
}
51+
}
52+
}

src/Interfaces/IWebViewEvents.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IWebViewEvents
1818
/// <param name="parentHandle">The parent window handle.</param>
1919
/// <param name="message">The message content.</param>
2020
[DispId(1)] void OnMessageReceived(object sender, string parentHandle, string message);
21-
[DispId(2)] void OnNavigationStarting(object sender, string parentHandle, string url);
21+
[DispId(2)] void OnNavigationStarting(object sender, string parentHandle, object args);
2222
[DispId(3)] void OnNavigationCompleted(object sender, string parentHandle, bool isSuccess, int webErrorStatus);
2323
[DispId(4)] void OnTitleChanged(object sender, string parentHandle, string newTitle);
2424
[DispId(5)] void OnWebResourceResponseReceived(object sender, string parentHandle, int statusCode, string reasonPhrase, string requestUrl);
@@ -36,7 +36,7 @@ public interface IWebViewEvents
3636
[DispId(239)] void OnPermissionRequested(object sender, string parentHandle, object args);
3737

3838
// --- FRAME EVENTS ---
39-
[DispId(229)] void OnFrameNavigationStarting(object sender, string parentHandle, object frame, string uri);
39+
[DispId(229)] void OnFrameNavigationStarting(object sender, string parentHandle, object frame, object args);
4040
[DispId(230)] void OnFrameNavigationCompleted(object sender, string parentHandle, object frame, bool isSuccess, int webErrorStatus);
4141
[DispId(231)] void OnFrameContentLoading(object sender, string parentHandle, object frame, long navigationId);
4242
[DispId(232)] void OnFrameDOMContentLoaded(object sender, string parentHandle, object frame, long navigationId);

src/NetWebView2Lib.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<Compile Include="Events\ProcessFailedEventArgsWrapper.cs" />
112112
<Compile Include="Events\WebView2PermissionRequestedEventArgsWrapper.cs" />
113113
<Compile Include="Events\WebView2AcceleratorKeyPressedEventArgs.cs" />
114+
<Compile Include="Events\WebView2NavigationStartingEventArgsWrapper.cs" />
114115
<Compile Include="Core\WebView2Bridge.cs" />
115116
<Compile Include="Interfaces\IWebViewEvents.cs" />
116117
<Compile Include="Interfaces\IWebViewActions.cs" />

0 commit comments

Comments
 (0)