Skip to content

Event object refactoring#118

Merged
ioa747 merged 7 commits intomainfrom
Event-Object-Refactoring
Mar 18, 2026
Merged

Event object refactoring#118
ioa747 merged 7 commits intomainfrom
Event-Object-Refactoring

Conversation

@ioa747
Copy link
Owner

@ioa747 ioa747 commented Mar 17, 2026

Important

Thanks for your effort and interest 💛 in improving the project. It's very appreciated.

Description

Event Object Refactoring (Navigation Interception)
This release refactors key events to use object-based arguments, enabling advanced control like navigation cancellation.

🔗 Linked GitHub Issues

Closes #<number>

📋 What is the current behavior?

🚀 What is the new behavior?


Type of changes

  • 🪲 Bugfix (change which fixes an issue)
  • ⭐ New Feature (change which adds functionality)
  • ⭐ New Example (this PR adds a new example)
  • 🔒 Security fix (change which improves security)
  • 🔮 Code style update (formatting, renaming)
  • 🔨 Refactoring (code optimization without functional change)
  • 📚 Documentation (updates to README or docs)
  • ⚙️ Build or CI related changes
  • 🧿 Other type

Breaking changes 🔥

  • Yes OnNavigationStarting and OnFrameNavigationStarting now pass an Args object instead of a raw URL string.
  • No

How and where was this tested?

🖥️ Describe where you tested your changes

System:

  • Windows 11 (x64)
  • Windows 10 (x64)
  • Windows 10 (x86)
  • Windows Server ......

Context:

  • COM object NetJson.Parser
  • COM object NetWebView2.Manager - WebView2
  • COM object NetWebView2.Manager - Bridge
  • UDF - NetWebView2Lib.au3
  • Examples: 019-MarkdownViewer.au3, 020-NavigationInterception.au3
  • with ...

🔬 Describe how you tested your changes

  • Manually tested in system and context shown above
  • Ran automatic tests (unit tests, integration tests, etc.)
  • Other ways

Checklist

  • I have read and understood the available contributing guidelines.
  • I have ensured my code follows the available code conventions.
  • I have reviewed my changes.
  • I have made corresponding changes to the documentation (if applicable).
  • I have added/updated necessary tests to cover the changes (if applicable).
  • I have checked for potential security implications.

Additional context

Screenshots

Note to reviewers


Version 2.2.0-alpha

Event Object Refactoring (Navigation Interception)

This release refactors key events to use object-based arguments, enabling advanced control like navigation cancellation.

  • Breaking Change: OnNavigationStarting and OnFrameNavigationStarting now pass an Args object instead of a raw URL string.
  • New Event Argument Wrapper:
    • IWebView2NavigationStartingEventArgs:
      • Uri: [Property] The target URL.
      • Cancel: [Property] Get/Set boolean to cancel the navigation.
      • IsUserInitiated: [Property] Indicates if the navigation was user-triggered.
      • IsRedirected: [Property] Indicates if it's a redirect.
      • NavigationId: [Property] Unique identifier for the navigation.
  • AutoIt UDF Sync:
    • NetWebView2Lib.au3 updated to handle the new object structure internally while maintaining logging compatibility.
  • Example: Added examples/020-NavigationInterception.au3 demonstrating how to intercept links and open them in the default browser by canceling internal navigation.

@mlipok
Copy link
Contributor

mlipok commented Mar 17, 2026

please consider to use: $NETWEBVIEW2_MESSAGE__USER_ABORT

@ioa747
Copy link
Owner Author

ioa747 commented Mar 17, 2026

please consider to use: $NETWEBVIEW2_MESSAGE__USER_ABORT

You mean inside NetWebView2_Events OnMessageReceived?

like

Volatile Func __NetWebView2_Events__OnMessageReceived($oWebV2M, $hGUI, $sMsg)
...
...
Case "NAV_ERROR"
			If $sData = "OperationCanceled" Then ; Check if the error is actually a user cancellation
				__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " COMMAND:USER_ABORT (Navigation Canceled)", 1)
				__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__USER_ABORT)
			Else
				__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " COMMAND:" & $sCommand & " Data:" & $sData, 1)
				__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__NAV_ERROR)
				$oWebV2M.Stop() ; We only stop if it is a real error.
			EndIf

			; 🚧 *******************************************
			ConsoleWrite("> TEST NAV_ERR: " & $sMsg & @CRLF)
			ConsoleWrite("> TEST NAV_ERR: __NetWebView2_LastMessage_KEEPER($oWebV2M)=" & __NetWebView2_LastMessage_KEEPER($oWebV2M) & " SLN=" & @ScriptLineNumber & @CRLF)
...
...

@@ -1628,9 +1628,17 @@ Volatile Func __NetWebView2_Events__OnMessageReceived($oWebV2M, $hGUI, $sMsg)
__NetWebView2_LastMessage_KEEPER($oWebV2M, $NETWEBVIEW2_MESSAGE__URL_CHANGED)

Case "NAV_ERROR"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ioa747 ioa747 merged commit 094fbc7 into main Mar 18, 2026
@ioa747 ioa747 deleted the Event-Object-Refactoring branch March 18, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants