Skip to content

Commit 3059588

Browse files
authored
v1.4.3
1 parent 41e8692 commit 3059588

7 files changed

Lines changed: 670 additions & 730 deletions

File tree

README.md

Lines changed: 56 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -64,158 +64,45 @@ This project is provided "as-is". You are free to use, modify, and distribute it
6464
<img src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png" width="100%">
6565
</p>
6666

67-
## 🚀 What's New in v1.4.2 - Major Update
67+
## 🚀 What's New in v1.4.3 - Major Update
6868

69-
This major update transforms **NetWebView2Lib** into a high-performance automation framework, bridging the gap between synchronous procedural logic (AutoIt) and asynchronous web environments.
69+
This update introduces critical flexibility for Chromium engine initialization, allowing developers to pass command-line arguments directly to the browser.
7070

7171
### ⚡ Key Features & Enhancements
7272

73-
#### **1. Synchronous Script Execution**
73+
#### **1. Command-Line Argument Support**
7474

75-
The long-awaited `ExecuteScriptWithResult(script)` is here. You can now execute JavaScript and receive the return value directly in a single line of AutoIt code, eliminating the need for complex event-callback chains.
76-
77-
- **Automatic Unescaping:** Results are automatically cleaned from JSON quotes and escaped characters.
78-
79-
- **Safety First:** Built-in 5-second timeout to prevent application hangs during script execution.
80-
81-
82-
#### **2. Persistent Code Injection**
83-
84-
The new `AddInitializationScript(script)` allows you to register JavaScript or CSS that "survives" page reloads and navigations.
85-
86-
- **Persistence:** Scripts are automatically re-injected by the engine the moment a new document is created.
87-
88-
- **Stackable:** Multiple scripts can be registered simultaneously without overwriting previous ones.
89-
90-
91-
#### **3. Unified Context Menu Handling**
92-
93-
A new, streamlined event `OnContextMenuRequested` provides direct access to context data without manual JSON parsing.
94-
95-
- **Direct Access:** Instantly get the `LinkURL`, `X/Y Coordinates`, and `SelectedText`.
96-
97-
- **Legacy Support:** Remains 100% compatible with the previous JSON-based context event for existing projects.
98-
99-
100-
#### **4. Integrated Data Sync & Base64 Support**
101-
102-
- **Direct Data Binding:** The new `SyncInternalData(json, variable)` provides an atomic way to synchronize complex data from AutoIt to the browser window without manual JS execution.
103-
104-
- **Native Base64 Support:** The `NetJson.Parser` now includes built-in Base64 encoding and decoding (including `DecodeB64ToFile`), providing a high-speed path for processing screenshots and binary data.
105-
106-
#### **5. Professional Layout & Diagnostics**
107-
108-
- **Smart Resizing (v1.4.2):** Replaced legacy docking with native OS message interception for pixel-perfect resizing.
109-
110-
- **Global Error Handling:** The standard showcase now implements a global COM error handler for professional debugging.
111-
112-
113-
---
114-
115-
### 📝 Quick Migration Example (AutoIt)
116-
117-
**Before (v1.4.1):**
118-
119-
AutoIt
120-
121-
```
122-
$oWeb.ExecuteScript("document.title")
123-
; ... Wait for WebMessageReceived event ...
124-
; ... Parse JSON ...
125-
```
126-
127-
**Now (v1.4.2):**
128-
129-
AutoIt
130-
131-
```
132-
Local $sTitle = $oWeb.ExecuteScriptWithResult("document.title")
133-
ConsoleWrite("Page Title: " & $sTitle & @CRLF)
134-
```
135-
136-
---
137-
138-
### 📦 Technical Breakdown
139-
140-
|**Method / Property**|**DispId**|**Description**|
141-
|---|---|---|
142-
|`AddInitializationScript`|184|Persistent JS injection across navigations.|
143-
|`ExecuteScriptWithResult`|188|Synchronous JS execution (Returns String).|
144-
|`SetAutoResize`|189|Automated parent-container docking.|
145-
|`OnContextMenuRequested`|190|Parameter-based context menu event.|
146-
|`ExecuteScriptOnPage`|191|Immediate, non-persistent script execution.|
147-
|`ClearCache`|193|Clears Disk Cache & Local Storage.|
148-
149-
---
150-
151-
152-
<p align="center">
153-
<img src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png" width="100%">
154-
</p>
75+
The new `AdditionalBrowserArguments` property allows you to configure the Chromium engine with specialized switches before it starts. This is essential for advanced automation, proxy configuration, and performance tuning.
15576

77+
- **Pre-Initialization:** These arguments are applied during the environment creation phase. You must set this property **before** calling `.Initialize()`.
78+
- **Powerful Switches:** Support for many Chromium flags, including:
79+
- `--disable-gpu`: Disables hardware acceleration (useful for legacy hardware or headless snapshots).
80+
- `--mute-audio`: Starts the browser in complete silence.
81+
- `--proxy-server="http://1.2.3.4:8080"`: Forces all traffic through a specific proxy.
82+
- `--incognito`: Starts in private browsing mode.
83+
- `--user-agent="..."`: A secondary way to override the default identity.
15684

157-
## 🧬 Understanding the GOG Demo Showcase (v1.4.2)
85+
#### **2. Advanced JSON Manipulation (JsonParser)**
15886

159-
The **`examples\GOG_Demo_v1.4.2\gogDemo.au3`** is more than just a browser—it is a showcase of **Hybrid Intelligence**. It demonstrates how AutoIt can seamlessly orchestrate a modern, complex e-commerce environment (GOG.com) by combining native Windows logic with the Edge WebView2 DOM.
87+
The `NetJson.Parser` has received a massive feature upgrade to support production-grade data manipulation directly from AutoIt.
16088

161-
#### 1. Context-Aware Menu (GOG Edition)
89+
- **Smart Typing & Deep Creation:** `SetTokenValue` now automatically creates missing parent objects and intelligently detects data types (Boolean, Null, Numbers) while preserving leading zeros in identifiers.
90+
- **Data Querying:** New `GetTokenCount` and `GetKeys` methods allow for deep inspection of JSON structures without manual parsing.
91+
- **Array Power Tools:** Built-in `SortArray` and `SelectUnique` (deduplication) leverage native LINQ performance to manage large data sets in memory.
16292

163-
The demo intercepts the native browser menu and replaces it with a dynamic AutoIt menu. The library "senses" exactly what is under your cursor:
93+
#### **3. Advanced Export & PDF Management (v1.4.3)**
16494

165-
- **🎮 Game Tile Intelligence**:
166-
167-
- **Action**: Right-click on a game’s thumbnail or title.
168-
169-
- **What happens**: The script extracts the `Game ID` and `Price` directly from the DOM, offering options to open the game in a new tab or add it to a local AutoIt-managed Watchlist.
170-
171-
- **📄 Professional Reporting (PDF & Screenshots)**:
172-
173-
- **Action**: Right-click anywhere on the page.
174-
175-
- **What happens**:
176-
177-
- **Smart PDF Export**: Generates a clean **A4 PDF** report. Before exporting, it uses the new `InjectCss` method to dynamically strip away GOG’s headers, sidebars, and campaign banners for a professional, content-focused document.
178-
179-
- **Full Page Capture**: Leverages the **Chrome DevTools Protocol (CDP)** to capture a high-resolution image of the entire page—even if it exceeds 6,000+ pixels in height—without scrolling artifacts.
180-
95+
- **ExportPageData(format, filePath):** Automate saving pages as HTML or MHTML (Single File) without dialogs.
96+
- **PrintToPdfStream():** Capture the page as a PDF and retrieve it as a Base64 string directly in AutoIt—no temporary files needed.
97+
- **HiddenPdfToolbarItems:** Take full control of the PDF viewer toolbar by hiding specific buttons (Save, Print, Search, etc.) through bitwise flags.
18198

182-
#### 2. Advanced Framework Features
183-
184-
- **⚡ Native CSS Injection (`InjectCss`)**: Move beyond manual JavaScript DOM manipulation. The demo shows how a single line of AutoIt code can override a website’s layout, making it "Print-Friendly" instantly.
185-
186-
- **🔄 Synchronous Data Binding (`SyncInternalData`)**: Effortlessly synchronize complex JSON datasets from AutoIt directly into the browser’s memory. This allows your script to "inject" custom variables that the website’s JavaScript can read in real-time.
187-
188-
- **🛠 Robust Event Handling**: The demo implements a **Global COM Error Handler**. Even if the website encounters JavaScript errors or network lag, the AutoIt host remains stable and responsive.
189-
190-
- **📏 Precision Resizing**: Utilizing native OS message interception, the browser view adapts to GUI changes with pixel-perfect accuracy, eliminating the flickering typical of standard docking.
191-
192-
193-
---
194-
195-
#### ⚙️ How it Works: The v1.4.2 "Direct Path"
196-
197-
Version 1.4.2 simplifies the communication bridge. While previous versions required complex event-callback chains, we now use the **Direct Path**:
198-
199-
1. **Unified Events**: The `OnContextMenuRequested` event now passes 4 clean parameters (Link, X, Y, Selected Text) directly. No more manual JSON parsing for standard context actions.
200-
201-
2. **Instant Execution**: With `ExecuteScriptWithResult`, AutoIt asks JavaScript a question (e.g., "What is the total price in the cart?") and receives the answer **immediately** in the next line of code, just like a native function.
202-
203-
3. **Persistent DNA**: Via `AddInitializationScript`, your custom bridge logic (like PDF cleaning or menu triggers) survives page reloads and site-wide navigation.
204-
205-
206-
---
207-
208-
#### 💡 Pro Tip for Developers:
209-
210-
> "Version 1.4.2 is **GOG-Proof**. Use the `InjectCss` method during PDF Export to target dynamic elements like `.campaign-bar` or `nav`. Using wildcard selectors like `[class*='notification']` allows you to suppress annoying popups and banners automatically, turning any webpage into a clean business report."
21199

212100
---
213101

214102
<p align="center">
215103
<img src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png" width="100%">
216104
</p>
217-
218-
## 📖 NetWebView2Lib Version 1.4.2 (Quick Reference)
105+
## 📖 NetWebView2Lib Version 1.4.3 - (2026-01-20) (Quick Reference)
219106

220107
### NetWebView2Lib (ProgId: NetWebView2.Manager)
221108

@@ -269,6 +156,14 @@ Determines whether new window requests are allowed or redirected to the same win
269156
Enables or disables custom context menu handling.
270157
`object.CustomMenuEnabled[ = Value]`
271158

159+
##### AdditionalBrowserArguments
160+
Sets additional command-line arguments to be passed to the Chromium engine during initialization. Must be set BEFORE calling Initialize().
161+
`object.AdditionalBrowserArguments[ = Value]`
162+
163+
##### HiddenPdfToolbarItems
164+
Controls the visibility of buttons in the PDF viewer toolbar using a bitwise combination of CoreWebView2PdfToolbarItems (e.g., 1=Save, 2=Print, 4=Search).
165+
`object.HiddenPdfToolbarItems[ = Value]`
166+
272167
#### Method
273168

274169
##### Initialize
@@ -424,6 +319,7 @@ Enables or disables the Web Message communication system.
424319
Enables or disables the browser status bar.
425320
`object.SetStatusBarEnabled(Enabled As Boolean)`
426321

322+
427323
##### CapturePreview
428324
Captures a screenshot of the current view to a file.
429325
`object.CapturePreview(FilePath As String, Format As String)`
@@ -532,7 +428,14 @@ Clears the browser cache (DiskCache and LocalStorage).
532428
Asynchronously retrieves the entire visible text content of the document (sent via OnMessageReceived with 'Inner_Text|').
533429
`object.GetInnerText()`
534430

535-
---
431+
##### ExportPageData
432+
Exports the current page data as HTML (0) or MHTML (1). If FilePath is provided, it saves to disk; otherwise, it returns the content as a string.
433+
`object.ExportPageData(Format As Integer, FilePath As String)`
434+
435+
##### PrintToPdfStream
436+
Captures the current page as a PDF and returns the content as a Base64-encoded string.
437+
`object.PrintToPdfStream()`
438+
536439
#### Events
537440

538441
##### OnMessageReceived
@@ -591,11 +494,19 @@ Retrieves a value by JSON path (e.g., "items[0].name").
591494
`string GetTokenValue(Path As String)`
592495

593496
##### GetArrayLength
594-
Returns the count of elements if the JSON is an array.
497+
Returns the count of elements if the JSON is an array (Legacy wrapper for GetTokenCount).
595498
`int GetArrayLength(Path As String)`
596499

500+
##### GetTokenCount
501+
Returns the count of elements (array items or object properties) at the specified path.
502+
`int GetTokenCount(Path As String)`
503+
504+
##### GetKeys
505+
Returns a delimited string of keys for the object at the specified path.
506+
`string GetKeys(Path As String, Delimiter As String)`
507+
597508
##### SetTokenValue
598-
Updates or adds a value at the specified path (only for JObject).
509+
Updates or adds a value at the specified path. Supports **Deep Creation** (automatic path creation) and **Smart Typing** (auto-detection of bool/null/numbers).
599510
`void SetTokenValue(Path As String, Value As String)`
600511

601512
##### LoadFromFile
@@ -678,3 +589,11 @@ Decodes a Base64 string back to plain text.
678589
Decodes a Base64 string and saves the binary content directly to a file.
679590
`bool DecodeB64ToFile(Base64Text As String, FilePath As String)`
680591

592+
##### SortArray
593+
Sorts a JSON array by a specific key.
594+
`bool SortArray(ArrayPath As String, Key As String, Descending As Boolean)`
595+
596+
##### SelectUnique
597+
Removes duplicate objects from a JSON array based on a key's value.
598+
`bool SelectUnique(ArrayPath As String, Key As String)`
599+

bin/NetWebView2Lib.dll

6 KB
Binary file not shown.

bin/NetWebView2Lib.tlb

1.25 KB
Binary file not shown.

0 commit comments

Comments
 (0)