Skip to content

Commit e3eb999

Browse files
authored
v1.4.0
## Version 1.4.0 - (2026-01-01) ### Added - **Unified Settings & Permissions (New Property System)** - Implemented a comprehensive set of Read/Write properties to control WebView2 behavior directly from AutoIt. - **Properties** (DispIds 170-179, 183): - `AreDevToolsEnabled` (170): Toggle Developer Tools. - `AreDefaultContextMenusEnabled` (171): Control native context menus. - `AreDefaultScriptDialogsEnabled` (172): Suppress or allow alerts/prompts. - `AreBrowserAcceleratorKeysEnabled` (173): Manage browser shortcuts. - `IsStatusBarEnabled` (174): Toggle the status bar. - ZoomFactor (175): Direct access to zoom level. - `BackColor` (176): Set background color using Hex strings (e.g., "0xFFFFFF"). - `AreHostObjectsAllowed` (177): Control JS bridge access. - `Anchor` (178): Manage control resizing behavior. - `BorderStyle` (179): Placeholder for border style configuration. - `AreBrowserPopupsAllowed` (183): Control new window/popup allowance. - **Methods** (DispIds 180-182, 184): - SetZoomFactor (180): Helper method for zoom. - OpenDevToolsWindow (181): Programmatically open DevTools. - WebViewSetFocus (182): Force focus to the WebView control. - ** AddInitializationScript** (184): Injects and manages persistent JS logic. - **Custom Context Menu System** - Implemented `OnContextMenu` COM event (DispId 6) to intercept user right-clicks. - Added data payload support providing context metadata (**Coordinates, Kind, TagName, Selection, Source URL, Link URL**) via JSON. - Sent as raw JSON string (prefixed with "JSON:") to avoid Base64 overhead. - **Focus Management Overhaul** - `OnBrowserGotFocus` (DispId 11): Native event triggering when WebView gains focus. - `OnBrowserLostFocus` (DispId 12): Native event triggering when focus leaves the WebView hierarchy. - Refactored logic to use `AreDevToolsEnabled` style properties instead of legacy timers for cleaner integration. - **Utilities** - EncodeURI (DispId 165): Native UTF-8 encoding for safe URL parameter generation. - DecodeURI (DispId 166): Native decoding to convert percent-encoded strings. - EncodeB64 (DispId 167): Native encoding (UTF-8) -> Base64. - DecodeB64 (DispId 168): Native decoding Base64 -> String (UTF8). - **Navigation Lifecycle Events** - `OnNavigationStarting` (DispId 2): Intercepts and validates URLs before loading. - `OnNavigationCompleted` (DispId 3): Detailed navigation status and `WebErrorStatus`. - **State Synchronization** - `OnTitleChanged` (DispId 4): Real-time synchronization of document title. - `OnURLChanged` (DispId 13): Real-time tracking of URL changes. - `OnZoomChanged` (DispId 10): Event fired when zoom level changes. - **Property Getters** - GetSource (**DispId 135**) &  GetDocumentTitle (**DispId 134**). - GetCanGoBack (DispId 162) &  GetCanGoForward (DispId 163). - GetBrowserProcessId (DispId 164). - **Permanent JavaScript Injection System** - Implemented  AddInitializationScript (DispId 184): Allows permanent injection of JavaScript libraries (like `bridge.js`) that persist across navigations and page refreshes. - Added automated script lifecycle management using `AddScriptToExecuteOnDocumentCreatedAsync`. - Integrated **Script ID Tracking**: The library now remembers the last injected script ID to allow clean replacement or removal, preventing memory leaks and script duplication. --- ### Fixed - **Focus Bounce Issue** Resolved where internal focus changes triggered false "LostFocus" events. Implemented robust checks using `BeginInvoke` and `GetFocus` with `IsChild` verification. - **CS1061 Compile Error** Corrected `TitleChanged` to standard `DocumentTitleChanged` event mapping. - **Context Menu JSON** Fixed JSON escaping for special characters in selection text and URLs. ### Changed - **Refactored Event Registration** Cleaned up  RegisterEvents to remove legacy AdBlock/Context Menu duplication while preserving functionality. - **DispId Standardization** Re-mapped `OnURLChanged` to DispId 13 to avoid conflicts. - **Extension Management** - AddExtension (DispId 150) now **triggers a notification event** with the internal ID for better lifecycle management via  RemoveExtension (DispId 151).
1 parent 1bc2e43 commit e3eb999

85 files changed

Lines changed: 96120 additions & 58 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/README.md

Lines changed: 431 additions & 0 deletions
Large diffs are not rendered by default.

Doc/📋 PROJECT LOGBOOK - NetWebView2Lib.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,81 @@
1-
**Current Version:** 1.3.0 (2025-12-25)
1+
**Current Version:** 1.4.0 - (2026-01-01)
22

33
---
4+
## Version 1.4.0 - (2026-01-01)
5+
### Added
6+
7+
- **Unified Settings & Permissions (New Property System)**
8+
- Implemented a comprehensive set of Read/Write properties to control WebView2 behavior directly from AutoIt.
9+
- **Properties** (DispIds 170-179):
10+
- `AreDevToolsEnabled`: Toggle Developer Tools.
11+
- `AreDefaultContextMenusEnabled`: Control native context menus.
12+
- `AreDefaultScriptDialogsEnabled`: Suppress or allow alerts/prompts.
13+
- `AreBrowserAcceleratorKeysEnabled`: Manage browser shortcuts.
14+
- `IsStatusBarEnabled`: Toggle the status bar.
15+
- `ZoomFactor`: Direct access to zoom level.
16+
- `BackColor`: Set background color using Hex strings (e.g., "0xFFFFFF").
17+
- `AreHostObjectsAllowed`: Control JS bridge access.
18+
- `Anchor`: Manage control resizing behavior.
19+
- **Methods** (DispIds 180-184):
20+
- `SetZoomFactor`: Helper method for zoom.
21+
- `OpenDevToolsWindow`: Programmatically open DevTools.
22+
- `WebViewSetFocus`: Force focus to the WebView control.
23+
- **`AddInitializationScript`**: (New) Injects and manages persistent JS logic.
24+
25+
- **Custom Context Menu System**
26+
- Implemented `OnContextMenu` COM event (DispId 6) to intercept user right-clicks.
27+
- Added data payload support providing context metadata (Coordinates, Kind, Selection, Source URL, Link URL) via JSON.
28+
- Sent as raw JSON string (prefixed with "JSON:") to avoid Base64 overhead.
29+
30+
- **Focus Management Overhaul**
31+
- `OnBrowserGotFocus` (DispId 11): Native event triggering when WebView gains focus.
32+
- `OnBrowserLostFocus` (DispId 12): Native event triggering when focus leaves the WebView hierarchy.
33+
- Refactored logic to use `AreDevToolsEnabled` style properties instead of legacy timers for cleaner integration.
34+
35+
- **Utilities**
36+
- `EncodeURI` (DispId 165): Native UTF-8 encoding for safe URL parameter generation.
37+
- `DecodeURI` (DispId 166): Native decoding to convert percent-encoded strings.
38+
- `EncodeB64` (DispId 167): Native encoding (UTF-8) -> Base64.
39+
- `DecodeB64` (DispId 168): Native decoding Base64 -> String (UTF8).
40+
41+
- **Navigation Lifecycle Events**
42+
- `OnNavigationStarting` (DispId 2): Intercepts and validates URLs before loading.
43+
- `OnNavigationCompleted` (DispId 3): Detailed navigation status and `WebErrorStatus`.
44+
45+
- **State Synchronization**
46+
- `OnTitleChanged` (DispId 4): Real-time synchronization of document title.
47+
- `OnURLChanged` (DispId 13): Real-time tracking of URL changes.
48+
- `OnZoomChanged` (DispId 10): Event fired when zoom level changes.
49+
50+
- **Property Getters**
51+
- `GetSource` (DispId 160) & `GetDocumentTitle` (DispId 161).
52+
- `GetCanGoBack` (DispId 162) & `GetCanGoForward` (DispId 163).
53+
- `GetBrowserProcessId` (DispId 164).
54+
55+
- **Permanent JavaScript Injection System**
56+
57+
- Implemented `AddInitializationScript` (DispId 184): Allows permanent injection of JavaScript libraries (like `bridge.js`) that persist across navigations and page refreshes.
58+
59+
- Added automated script lifecycle management using `AddScriptToExecuteOnDocumentCreatedAsync`.
60+
61+
- Integrated **Script ID Tracking**: The library now remembers the last injected script ID to allow clean replacement or removal, preventing memory leaks and script duplication.
62+
63+
64+
---
65+
### Fixed
466

67+
- **Focus Bounce Issue** Resolved where internal focus changes triggered false "LostFocus" events. Implemented robust checks using `BeginInvoke` and `ContainsFocus`.
68+
- **CS1061 Compile Error** Corrected `TitleChanged` to standard `DocumentTitleChanged` event mapping.
69+
- **Context Menu JSON** Fixed JSON escaping for special characters in selection text and URLs.
70+
71+
### Changed
72+
73+
- **Refactored Event Registration** Cleaned up `RegisterEvents` to remove legacy AdBlock/Context Menu duplication while preserving functionality.
74+
- **DispId Standardization** Re-mapped `OnURLChanged` to DispId 13 to avoid conflicts.
75+
- **Extension Management**
76+
- `AddExtension` (DispId 150) now returns the internal ID for better lifecycle management via `RemoveExtension` (DispId 151).
77+
78+
---
579
## Version 1.3.0 - (2025-12-25)
680

781
### Added
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
2+
With the release of **v1.3.0**, you can now load browser extensions (unpacked) independently for each WebView2 instance. This is perfect for adding Ad-blockers, Dark Mode, or custom developer tools to your automation scripts.
3+
4+
---
5+
6+
#### 1. Prepare your Extension Library
7+
8+
WebView2 requires extensions to be in **Unpacked** format (a folder containing the `manifest.json` file).
9+
10+
1. Create a folder named `Extensions_Lib` in your project directory.
11+
12+
2. Download your desired extension (e.g., **uBlock Origin Lite** or **Dark Reader**).
13+
14+
3. If you have a `.crx` file, extract it using a ZIP tool.
15+
16+
4. Your structure should look like this:
17+
18+
Plaintext
19+
20+
```
21+
YourProject/
22+
├── MyScript.au3
23+
└── Extensions_Lib/
24+
└── DarkReader/
25+
├── manifest.json <-- This must be in the root of the folder
26+
├── background.js
27+
└── ...
28+
```
29+
30+
31+
#### 2. Implementation in AutoIt
32+
33+
Extensions must be loaded **after** the engine is ready (`INIT_READY`) but **before** or during the initial navigation.
34+
35+
AutoIt
36+
37+
```
38+
; Example for Instance 2
39+
Func Web2_OnMessageReceived($sMsg)
40+
Local $aParts = StringSplit($sMsg, "|")
41+
Local $sCommand = StringStripWS($aParts[1], 3)
42+
43+
Switch $sCommand
44+
Case "INIT_READY"
45+
; Define the path to your unpacked extension
46+
Local $sExtPath = @ScriptDir & "\Extensions_Lib\DarkReader"
47+
48+
; Load the extension for this specific instance
49+
$oWeb2.AddExtension($sExtPath)
50+
51+
; Navigate to your target site
52+
$oWeb2.Navigate("https://www.autoitscript.com/forum/")
53+
54+
Case "EXTENSION_LOADED"
55+
ConsoleWrite("+> Success: Extension loaded in Web2!" & @CRLF)
56+
57+
Case "ERROR"
58+
If StringInStr($sMsg, "EXTENSION") Then
59+
ConsoleWrite("!> Error: Failed to load extension." & @CRLF)
60+
EndIf
61+
EndSwitch
62+
EndFunc
63+
```
64+
65+
#### Key Features in v1.3.0:
66+
67+
- **Isolation**: Loading an extension in `Web1` does not affect `Web2`. Each instance stays completely independent.
68+
69+
- **Persistence**: Since v1.3.0 uses dedicated User Profiles, extension settings (like custom filters or dark mode intensity) are saved automatically in the profile folder.
70+
71+
- **Event Tracking**: The new version sends a `EXTENSION_LOADED` message back to AutoIt so you can confirm the injection was successful.
72+
73+
74+
---
75+
76+
### Manual Method: Extracting Extensions from your Browser
77+
78+
If you already have the extension installed in your Chrome or Edge browser, follow these steps to "extract" it for use with this library:
79+
80+
1. **Find the Extension ID:**
81+
82+
- Open your browser and navigate to `chrome://extensions/` or `edge://extensions/`.
83+
84+
- Enable **Developer mode** (toggle switch at the top right).
85+
86+
- Locate your extension (e.g., Dark Reader) and copy its **ID** (a long string of random letters like `eimadpbcbfnmbkopoojfekhnkhdbieeh`).
87+
88+
2. **Locate the Source Folder:**
89+
90+
- Press `Win + R`, paste the following path, and press Enter:
91+
92+
- **For Edge:** `%LocalAppData%\Microsoft\Edge\User Data\Default\Extensions`
93+
94+
- **For Chrome:** `%LocalAppData%\Google\Chrome\User Data\Default\Extensions`
95+
96+
- Find the folder named after the **ID** you copied in Step 1.
97+
98+
3. **Identify the Unpacked Folder:**
99+
100+
- Inside that folder, you will see a sub-folder named after the version number (e.g., `4.9.118_0`).
101+
102+
- **Crucial:** This version folder is your "Unpacked Extension". It contains the `manifest.json` file.
103+
104+
4. **Copy to your Project:**
105+
106+
- Copy the version folder into your project's `Extensions_Lib` directory.
107+
108+
- **Pro Tip:** Rename the folder from `4.9.118_0` to something readable like `DarkReader` to keep your code clean.
109+
110+
111+
---
112+
113+
# How-To: stored in your library
114+
115+
With the `#include "_WV2_ExtensionPicker.au3"`
116+
### 1. The New Folder Architecture (Format: `Name_ID`)
117+
118+
For the automated **Extension Picker** to function properly, extensions must be stored in your library (`Extensions_Lib`) using a specific naming format.
119+
120+
**Syntax:** `[Extension Name]_[32-char ID]`
121+
122+
Example:
123+
124+
`Extensions_Lib\DarkReader_eimadpbcbfnmbkopoojfekhnkhdbieeh`
125+
126+
127+
Your Extensions_Lib/
128+
└── DarkReader_eimadpbcbfnmbkopoojfekhnkhdbieeh/
129+
├── manifest.json <-- This must be in the root of the folder
130+
├── background.js
131+
└── ...
132+
133+
134+
> **Why this format?**
135+
>
136+
> - **Name:** AutoIt uses this to display a user-friendly name for the extension in the list.
137+
>
138+
> - **ID:** AutoIt uses this to check if the extension is already active in the `UserDataPath` and to generate the `extension://ID/` URL.
139+
>
140+
141+
---
142+
143+
### 2. Using the Extension Picker (UI Mode)
144+
145+
Instead of "hardcoding" extensions into your script, you can call the new Native Module:
146+
147+
**AutoIt**
148+
149+
AutoIt
150+
151+
```
152+
#include "_WV2_ExtensionPicker.au3"
153+
154+
; Call the Picker (Modal Window)
155+
_WV2_ShowExtensionPicker($iWidth = 500, $iHeight = 600, $hWND = 0, $sExtSourcePath = "", $sUserDataPath = "")
156+
```
157+
158+
### 3. How to Find the Correct ID
159+
160+
1. Install the extension in your regular Chrome/Edge browser.
161+
162+
2. Navigate to `chrome://extensions`.
163+
164+
3. Enable **Developer Mode** (top right).
165+
166+
4. Click the **Details** button on the extension you want.
167+
168+
5. Copy the **ID** (e.g., `eimadpbcbfnmbkopoojfekhnkhdbieeh`).
169+
170+
6. Rename the extension folder in your library to `DarkReader_eimadpbcbfnmbkopoojfekhnkhdbieeh`.
171+
172+
173+
---
174+
175+
### 5. Technical Note (State Sync)
176+
177+
The Picker performs a real-time check of the following folder:
178+
179+
`UserDataPath\EBWebView\Default\Local Extension Settings`
180+
181+
If the extension ID is found there, the button automatically changes from **"Add Extension"** to **"Launch"**, allowing for the immediate start of the Extension UI.
182+
183+
---
184+
185+
Example:
186+

bin/NetWebView2Lib.dll

15.5 KB
Binary file not shown.

bin/NetWebView2Lib.tlb

6.75 KB
Binary file not shown.

examples/2-Html_Gui.au3

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ EndFunc ;==>ShowWebNotification
183183
; Synchronizes WebView size with the GUI window
184184
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
185185
#forceref $hWnd, $iMsg, $wParam
186-
If $wParam = 1 Then Return $GUI_RUNDEFMSG
186+
If $hWnd <> $hGUI Then Return $GUI_RUNDEFMSG ; critical, to respond only to the $hGUI
187+
If $wParam = 1 Then Return $GUI_RUNDEFMSG ; 1 = SIZE_MINIMIZED
187188
Local $iW = BitAND($lParam, 0xFFFF), $iH = BitShift($lParam, 16) - 50
188189
If IsObj($oManager) Then $oManager.Resize(($iW < 10 ? 10 : $iW), ($iH < 10 ? 10 : $iH))
189190
Return $GUI_RUNDEFMSG

0 commit comments

Comments
 (0)