Skip to content

Commit 8503e9b

Browse files
authored
Merge pull request #110 from mlipok/patch-3
quick update after Alpha 2.1.0
2 parents 00f8f83 + 3aa9819 commit 8503e9b

9 files changed

Lines changed: 102 additions & 93 deletions

NetWebView2Lib.au3

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ EndFunc ;==>_NetWebView2_CreateManager
181181
; $i_ZoomFactor - [optional] an integer value. Default is 1.0.
182182
; $s_BackColor - [optional] a string value. Default is "0x2B2B2B".
183183
; $b_InitConsole - [optional] a boolean value. Default is False.
184-
; Return values .: None
184+
; Return values .: $iInit
185185
; Author ........: mLipok, ioa747
186186
; Modified ......:
187187
; Remarks .......:
@@ -221,7 +221,7 @@ Func _NetWebView2_Initialize($oWebV2M, $hUserGUI, $s_ProfileDirectory, $i_Left =
221221
EndIf
222222
If TimerDiff($hTimer) >= $iTimeOut_ms Then Return SetError(1, 0, '')
223223
Until $oWebV2M.IsReady Or $iMessage = $NETWEBVIEW2_MESSAGE__INIT_READY
224-
If Not __NetWebView2_WaitForReadyState($oWebV2M, $hTimer, $iTimeOut_ms) Then Return SetError(2, 0, '')
224+
;~ If Not __NetWebView2_WaitForReadyState($oWebV2M, $hTimer, $iTimeOut_ms) Then Return SetError(2, 0, '')
225225
#EndRegion ; After Initialization wait for the engine to be ready before navigating
226226

227227
; WebView2 Configuration
@@ -235,7 +235,7 @@ Func _NetWebView2_Initialize($oWebV2M, $hUserGUI, $s_ProfileDirectory, $i_Left =
235235
EndIf
236236

237237
If @error Then __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " !!! Manager Creation ERROR", 1)
238-
Return SetError(@error, $oWebV2M.GetBrowserProcessId(), '')
238+
Return SetError(@error, $oWebV2M.GetBrowserProcessId(), $iInit)
239239
EndFunc ;==>_NetWebView2_Initialize
240240

241241
; #INTERNAL_USE_ONLY# ===========================================================================================================
@@ -2353,3 +2353,4 @@ EndFunc ;==>__NetWebView2_Events__OnFrameWebMessageReceived
23532353
#EndRegion ; === NetWebView2Lib UDF === EVENT HANDLERS * #TODO ===
23542354

23552355
#EndRegion ; === NetWebView2Lib UDF === EVENT HANDLERS ===
2356+

examples/000-NetJson.Parser.au3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ _Example()
1515
Exit
1616

1717
Func _Example()
18+
ConsoleWrite("! MicrosoftEdgeWebview2 : version check: " & _NetWebView2_IsAlreadyInstalled() & ' ERR=' & @error & ' EXT=' & @extended & @CRLF)
1819
ConsoleWrite(@CRLF & "=== STARTING NETJSON TUTORIAL ===" & @CRLF)
1920

2021
#Region ; 0. Initialize the COM Object

examples/001-BasicDemo.au3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Func _BridgeMyEventsHandler_OnMessageReceived($oWebV2M, $hGUI, $sMessage)
108108
If $sMessage = "CLOSE_APP" Then
109109
If MsgBox(36, "Confirm", "Exit Application?", 0, $hGUI) = 6 Then Exit
110110
Else
111-
MsgBox(64, "JS Notification", "Message from Browser: " & $sMessage)
111+
MsgBox($MB_ICONINFORMATION, "JS Notification", "Message from Browser: " & $sMessage)
112112
$iMsgCnt += 1
113113
UpdateWebUI($oWebV2M, "mainTitle", $iMsgCnt & " Hello from AutoIt!")
114114
EndIf

examples/009-Auditor.au3

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Func _Example()
140140
; WebView2 Setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141141

142142
; Initialize WebView2 Manager and register events
143-
Local $oWebV2M = _NetWebView2_CreateManager("", "WebView_", "")
143+
Local $oWebV2M = _NetWebView2_CreateManager("", "WebView_", "", False)
144144
If @error Then Exit ConsoleWrite("@@(" & @ScriptLineNumber & ") :: @error:" & @error & ", @extended:" & @extended & @CRLF)
145145

146146
; create JavaScript Bridge object
@@ -311,7 +311,7 @@ Func _WebView_OnMessageReceived($oWebV2M, $hGUI, $sMessage)
311311
EndIf
312312

313313
Case "PDF_SUCCESS"
314-
MsgBox(64, "Success", "PDF Report saved successfully!")
314+
MsgBox($MB_ICONINFORMATION, "Success", "PDF Report saved successfully!")
315315

316316
Case "PDF_ERROR"
317317
MsgBox(16, "Error", "PDF Export failed: " & $sMessage)

examples/011-TwinWebView.au3

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#include <WindowsConstants.au3>
2020
#include <StaticConstants.au3>
2121
#include <EditConstants.au3>
22+
#include "..\NetWebView2Lib.au3"
2223
#include "_WV2_ExtensionPicker.au3"
2324

24-
OnAutoItExitRegister("_ExitApp")
25+
OnAutoItExitRegister(_ExitApp)
2526

2627
; Global Objects & Handles
2728
Global $oWeb1, $oWeb2
@@ -50,7 +51,7 @@ Func _MainGUI() ; Creates the primary application window and starts the message
5051
GUICtrlSetResizing(-1, $GUI_DOCKALL)
5152

5253
; Register the WM_SIZE message to handle window resizing dynamically
53-
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
54+
GUIRegisterMsg($WM_SIZE, WM_SIZE)
5455

5556
; Initialize Browsers and their child window containers
5657
_InitBrowsers()
@@ -168,32 +169,22 @@ Func _InitBrowsers() ; Creates child window containers and initializes WebView2
168169
; Instance 1 - "Profile_1" folder
169170
$hID1 = GUICreate("", 485, 580, 10, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN), -1, $hMainGUI)
170171
$Bar1 = _Web_MakeBar($hID1, $sExtras)
171-
$oWeb1 = ObjCreate("NetWebView2.Manager")
172-
ObjEvent($oWeb1, "Web1_", "IWebViewEvents")
173-
$oBridge1 = $oWeb1.GetBridge()
174-
ObjEvent($oBridge1, "Bridge1_", "IBridgeEvents")
172+
$oWeb1 = _NetWebView2_CreateManager("", "Web1_")
173+
$oBridge1 = _NetWebView2_GetBridge($oWeb1, "Bridge1_")
175174
$Bar1.Web_ProfilePath = $sProfileDirectory
176-
$oWeb1.Initialize($hID1, $sProfileDirectory, 0, 25, 485, 555)
175+
_NetWebView2_Initialize($oWeb1, $hID1, $sProfileDirectory, 0, 25, 485, 555, True, True, 1.2, "0x2B2B2B", False)
176+
_NetWebView2_Navigate($oWeb1, "https://www.google.com/search?q=web1")
177177

178178
; Instance 2 - "Profile_2" folder
179179
$hID2 = GUICreate("", 485, 580, 505, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN), -1, $hMainGUI)
180180
$Bar2 = _Web_MakeBar($hID2, $sExtras)
181-
$oWeb2 = ObjCreate("NetWebView2.Manager")
182-
ObjEvent($oWeb2, "Web2_", "IWebViewEvents")
183-
$oBridge2 = $oWeb2.GetBridge()
184-
ObjEvent($oBridge2, "Bridge2_", "IBridgeEvents")
181+
$oWeb2 = _NetWebView2_CreateManager("", "Web2_")
182+
$oBridge2 = _NetWebView2_GetBridge($oWeb2, "Bridge2_")
185183
$Bar2.Web_ProfilePath = @ScriptDir & "\Profile_2"
186-
$oWeb2.Initialize($hID2, @ScriptDir & "\Profile_2", 0, 25, 485, 555)
187-
188-
; Wait until both instances are ready
189-
Do
190-
Sleep(10)
191-
Until $oWeb1.IsReady And $oWeb2.IsReady
184+
_NetWebView2_Initialize($oWeb2, $hID2, $sProfileDirectory, 0, 25, 485, 555, True, True, 1.2, "0x2B2B2B", False)
185+
_NetWebView2_Navigate($oWeb2, "https://www.google.com/search?q=web2")
192186

193-
_NetWebView2_Navigate($oWeb1, "https://www.google.com/search?q=web1")
194187
GUISetState(@SW_SHOWNOACTIVATE, $hID1)
195-
196-
$oWeb2.Navigate("https://www.google.com/search?q=web2")
197188
GUISetState(@SW_SHOWNOACTIVATE, $hID2)
198189

199190
EndFunc ;==>_InitBrowsers

examples/012-GetCookies.au3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Func WebView_OnMessageReceived($sMessage)
247247
EndIf
248248

249249
Case "PDF_SUCCESS"
250-
MsgBox(64, "Success", "PDF Report saved successfully!")
250+
MsgBox($MB_ICONINFORMATION, "Success", "PDF Report saved successfully!")
251251

252252

253253
Case "ERROR", "NAV_ERROR"

examples/014-pdfJS-Static_PDF_Viewer.au3

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Func _Example()
4141

4242
; initialize browser - put it on the GUI
4343
Local $sProfileDirectory = @ScriptDir & "\NetWebView2Lib-UserDataFolder"
44-
_NetWebView2_Initialize($oWeb, $hGUI, $sProfileDirectory, 0, 0, 0, 0, True, False, False, 0.7)
44+
_NetWebView2_Initialize($oWeb, $hGUI, $sProfileDirectory, 0, 0, 0, 0, True, True, 0.7)
4545

4646
; Get the bridge object and register events
4747
Local $oBridge = _NetWebView2_GetBridge($oWeb, "__UserEventHandler__Bridge_")
@@ -130,6 +130,17 @@ Func _Example()
130130
_NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE0_FIREANDFORGET)
131131
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "After:" & @CRLF & $s_JavaScript_snipp)
132132

133+
$s_JavaScript_snipp = 'PDFViewerApplication.open({ url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" });'
134+
_NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE0_FIREANDFORGET)
135+
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "After:" & @CRLF & $s_JavaScript_snipp)
136+
137+
;~ $s_JavaScript_snipp = FileRead(@ScriptDir & '\JS_Lib\PDFViewerApplicationEvents.js')
138+
;~ _NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE2_RESULT)
139+
140+
$s_JavaScript_snipp = 'PDFViewerApplication.open({ url: "https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf" });'
141+
_NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE0_FIREANDFORGET)
142+
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "After:" & @CRLF & $s_JavaScript_snipp)
143+
133144
#EndRegion ; now we can call the script directly from the JavaScript library "NetWebView2Lib_pdfjs_Tools.js" - some pdfjs magic stuff ;)
134145

135146
; Main Loop

examples/017-MappedFolder.au3

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
_Example()
1414

1515
Func _Example()
16+
ConsoleWrite("! MicrosoftEdgeWebview2 : version check: " & _NetWebView2_IsAlreadyInstalled() & ' ERR=' & @error & ' EXT=' & @extended & @CRLF)
17+
1618
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc)
1719
#forceref $oMyError
1820

examples/018-BasicFramesDemo.au3

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ Func Main()
5252
#Region - Testing how to manage frames
5353

5454
_NetWebView2_Navigate($oWebV2M, 'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe', $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, "", 5000)
55-
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 1)
55+
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Wait till all frames are loaded')
5656
;~ _Demo_NavigateCheckBanner($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe", '//*[@id="snigel-cmp-framework" and @class="snigel-cmp-framework"]')
5757
If @error Then Return SetError(@error, @extended)
5858

59-
#Region ; Example part 1 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)
60-
ConsoleWrite("+ Example part 1 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF)
59+
#Region ; Example part 1 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)
60+
ConsoleWrite("+ Example part 1 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF)
6161

6262
Local $iFrameCount = $oWebV2M.GetFrameCount()
6363
ConsoleWrite(@CRLF)
@@ -68,17 +68,19 @@ Func Main()
6868
ConsoleWrite("- NAME=" & $oWebV2M.GetFrameName($IDX_Frame) & @CRLF)
6969
ConsoleWrite(@CRLF)
7070
Next
71-
#EndRegion ; Example part 1 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)
71+
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Example part 1 - testing NetWebView2Lib methodes: ' & @CRLF & '.GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)' & @CRLF & 'End')
72+
#EndRegion ; Example part 1 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)
7273

73-
#Region ; Example part 2 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)
74-
ConsoleWrite("+ Example part 2 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF)
74+
#Region ; Example part 2 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)
75+
ConsoleWrite("+ Example part 2 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF)
7576

7677
ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameUrls() :" & @CRLF & $oWebV2M.GetFrameUrls() & @CRLF)
7778
ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameNames() :" & @CRLF & $oWebV2M.GetFrameNames() & @CRLF)
78-
#EndRegion ; Example part 2 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)
79+
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Example part 2 - testing NetWebView2Lib methodes:' & @CRLF & '.GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)' & @CRLF & 'End')
80+
#EndRegion ; Example part 2 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)
7981

80-
#Region ; Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame)
81-
ConsoleWrite("+ Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame)" & @CRLF)
82+
#Region ; Example part 3 - testing NetWebView2Lib methodes .GetFrameHtmlSource($IDX_Frame)
83+
ConsoleWrite("+ Example part 3 - testing NetWebView2Lib methodes .GetFrameHtmlSource($IDX_Frame)" & @CRLF)
8284
For $IDX_Frame = 0 To $iFrameCount - 1
8385
ConsoleWrite(@CRLF & "======================================================" & @CRLF)
8486
Local $sHtmlSource = Fire_And_Wait($oWebV2M.GetFrameHtmlSource($IDX_Frame), 5000) ; pair with "FRAME_HTML_SOURCE"
@@ -87,8 +89,8 @@ Func Main()
8789
ConsoleWrite(@CRLF & "======================================================" & @CRLF)
8890
ConsoleWrite(@CRLF)
8991
ConsoleWrite(@CRLF)
90-
#EndRegion ; Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame)
91-
92+
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Example part 3 - testing NetWebView2Lib methodes : ' & @CRLF & '.GetFrameHtmlSource($IDX_Frame)' & @CRLF & 'End')
93+
#EndRegion ; Example part 3 - testing NetWebView2Lib methodes .GetFrameHtmlSource($IDX_Frame)
9294

9395
#Region ; Example part 4 - Direct Frame Interaction
9496

@@ -106,6 +108,8 @@ Func Main()
106108

107109
ConsoleWrite("VarGetType($oFrame0)=" & VarGetType($oFrame0) & @CRLF)
108110
ConsoleWrite("$oFrame0.Name=" & $oFrame0.Name & @CRLF & @CRLF)
111+
ConsoleWrite("$oFrame0.FrameId=" & $oFrame0.FrameId & @CRLF & @CRLF)
112+
ConsoleWrite("$oFrame0.IsDestroyed()=" & $oFrame0.IsDestroyed() & @CRLF & @CRLF)
109113

110114
; Direct script execution in the iframe without involving the central Manager
111115
$oFrame0.ExecuteScript("document.body.style.backgroundColor = 'red';")
@@ -118,12 +122,19 @@ Func Main()
118122
Else
119123
ConsoleWrite("! Error: $oFrame0 is not a valid COM Object" & @CRLF)
120124
EndIf
121-
125+
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Example part 4 - Direct Frame Interaction: ' & @CRLF & '' & @CRLF & 'End')
122126
#EndRegion ; Example part 4 - Direct Frame Interaction
123127

128+
#Region ; Example part 5 - Get all Frames as array
129+
Local $aFrames
130+
Do
131+
$aFrames = _NetWebView2_GetAllFrames_AsArray($oWebV2M)
132+
_ArrayDisplay($aFrames, @ScriptLineNumber & ' $aFrames : Example part 5 - Get all Frames as array')
133+
Until ($IDNO = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", "Check again all frames ?"))
124134

125-
#EndRegion - Testing how to manage frames
135+
#EndRegion ; Example part 5 - Get all Frames as array
126136

137+
#EndRegion - Testing how to manage frames
127138

128139
; Main Loop
129140
While 1
@@ -135,46 +146,58 @@ Func Main()
135146

136147
GUIDelete($hGUI)
137148

138-
139149
_NetWebView2_CleanUp($oWebV2M, $oJSBridge)
140150
EndFunc ;==>Main
141151

142-
; ==============================================================================
143-
; ; Function to update a text element inside the WebView UI
144-
; ==============================================================================
145-
Func UpdateWebUI($oWebV2M, $sElementId, $sNewText)
146-
If Not IsObj($oWebV2M) Then Return ''
147-
148-
; Escape backslashes, single quotes and handle new lines for JavaScript safety
149-
Local $sCleanText = StringReplace($sNewText, "\", "\\")
150-
$sCleanText = StringReplace($sCleanText, "'", "\'")
151-
$sCleanText = StringReplace($sCleanText, @CRLF, "\n")
152-
$sCleanText = StringReplace($sCleanText, @LF, "\n")
153-
154-
Local $sJavaScript = "document.getElementById('" & $sElementId & "').innerText = '" & $sCleanText & "';"
155-
_NetWebView2_ExecuteScript($oWebV2M, $sJavaScript)
156-
EndFunc ;==>UpdateWebUI
157-
158-
; ==============================================================================
159-
; MY EVENT HANDLER: Bridge (JavaScript Messages)
160-
; ==============================================================================
161-
Func _BridgeMyEventsHandler_OnMessageReceived($oWebV2M, $hGUI, $sMessage)
162-
Local Static $iMsgCnt = 0
152+
; #FUNCTION# ====================================================================================================================
153+
; Name ..........: _NetWebView2_GetAllFrames_AsArray
154+
; Description ...: Get all Frames as array
155+
; Syntax ........: _NetWebView2_GetAllFrames_AsArray($oWebV2M)
156+
; Parameters ....: $oWebV2M - an object.
157+
; Return values .: None
158+
; Author ........: mLipok
159+
; Modified ......:
160+
; Remarks .......:
161+
; Related .......:
162+
; Link ..........:
163+
; Example .......: No
164+
; ===============================================================================================================================
165+
Func _NetWebView2_GetAllFrames_AsArray($oWebV2M)
166+
Local Const $s_Prefix = "[_NetWebView2_GetAllFrames_AsArray]:"
167+
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler
168+
#forceref $oMyError, $s_Prefix
169+
170+
Local Enum _
171+
$FRAME_IDX, _
172+
$FRAME_OBJECT, _
173+
$FRAME_ID, _
174+
$FRAME_NAME, _
175+
$FRAME_URL, _
176+
$FRAME_DESTROYED, _
177+
$FRAME_HTML, _
178+
$FRAME__COUNTER
163179

164-
If $sMessage = "CLOSE_APP" Then
165-
If MsgBox(36, "Confirm", "Exit Application?", 0, $hGUI) = 6 Then Exit
166-
Else
167-
MsgBox(64, "JS Notification", "Message from Browser: " & $sMessage)
168-
$iMsgCnt += 1
169-
UpdateWebUI($oWebV2M, "mainTitle", $iMsgCnt & " Hello from AutoIt!")
170-
EndIf
171-
EndFunc ;==>_BridgeMyEventsHandler_OnMessageReceived
180+
Local $iFrameCount = $oWebV2M.GetFrameCount()
181+
Local $aFrames[$iFrameCount][$FRAME__COUNTER]
182+
Local $oFrame
183+
For $IDX_Frame = 0 To $iFrameCount - 1
184+
$oFrame = $oWebV2M.GetFrame($IDX_Frame)
185+
$aFrames[$IDX_Frame][$FRAME_IDX] = $IDX_Frame
186+
$aFrames[$IDX_Frame][$FRAME_OBJECT] = $oFrame
187+
$aFrames[$IDX_Frame][$FRAME_ID] = $oFrame.FrameId
188+
$aFrames[$IDX_Frame][$FRAME_NAME] = $oWebV2M.Name
189+
$aFrames[$IDX_Frame][$FRAME_URL] = $oWebV2M.GetFrameUrl($IDX_Frame)
190+
$aFrames[$IDX_Frame][$FRAME_DESTROYED] = $oFrame.IsDestroyed()
191+
$aFrames[$IDX_Frame][$FRAME_HTML] = $oWebV2M.GetFrameHtmlSource($IDX_Frame)
192+
Next
193+
Return $aFrames
194+
EndFunc ;==>_NetWebView2_GetAllFrames_AsArray
172195

173196
; ==============================================================================
174197
; MyHook_ Events
175198
; ==============================================================================
176199
Func MyHook_OnMessageReceived($oWebV2M, $hGUI, $sMsg)
177-
#forceref $oWebV2M, $hGUI, $sMsg
200+
#forceref $oWebV2M, $hGUI
178201
ConsoleWrite("> [MyHook] OnMessageReceived: GUI:" & $hGUI & " Msg: " & (StringLen($sMsg) > 30 ? StringLeft($sMsg, 30) & "..." : $sMsg) & @CRLF)
179202
Local $iSplitPos = StringInStr($sMsg, "|")
180203
Local $sCommand = $iSplitPos ? StringStripWS(StringLeft($sMsg, $iSplitPos - 1), 3) : $sMsg
@@ -194,27 +217,6 @@ Func MyHook_OnMessageReceived($oWebV2M, $hGUI, $sMsg)
194217
EndSwitch
195218
EndFunc ;==>MyHook_OnMessageReceived
196219

197-
; ==============================================================================
198-
; HELPER: Demo HTML Content
199-
; ==============================================================================
200-
Func __GetDemoHTML()
201-
Local $sH = _
202-
'<html><head><style>' & _
203-
'body { font-family: "Segoe UI", sans-serif; background: #202020; color: white; padding: 40px; text-align: center; }' & _
204-
'.card { background: #2d2d2d; padding: 20px; border-radius: 8px; border: 1px solid #444; }' & _
205-
'button { padding: 12px 24px; cursor: pointer; background: #0078d4; color: white; border: none; border-radius: 4px; font-size: 16px; margin: 5px; }' & _
206-
'button:hover { background: #005a9e; }' & _
207-
'</style></head><body>' & _
208-
'<div class="card">' & _
209-
' <h1 id="mainTitle">WebView2 + AutoIt .NET Manager</h1>' & _ ; Fixed ID attribute
210-
' <p id="statusMsg">The communication is now 100% Event-Driven (No Sleep needed).</p>' & _
211-
' <button onclick="window.chrome.webview.postMessage(''Hello from JavaScript!'')">Send Ping</button>' & _
212-
' <button onclick="window.chrome.webview.postMessage(''CLOSE_APP'')">Exit App</button>' & _
213-
'</div>' & _
214-
'</body></html>'
215-
Return $sH
216-
EndFunc ;==>__GetDemoHTML
217-
218220
Func __Example_Log($s_ScriptLineNumber, $sString, $iError = @error, $iExtended = @extended)
219221
ConsoleWrite(@ScriptName & ' SLN=' & $s_ScriptLineNumber & ' [' & $iError & '/' & $iExtended & '] ::: ' & $sString & @CRLF)
220222
Return SetError($iError, $iExtended, '')
@@ -237,6 +239,7 @@ EndFunc ;==>__Example_Log
237239
; Remarks........: This function uses static variables to bridge the gap between async COM events and sync script execution.
238240
; It effectively pauses the script execution until the WebView2 event fires back with data.
239241
; ===============================================================================================================================
242+
240243
Func Fire_And_Wait($sData = "", $iTimeout = 5000)
241244
Local Static $vStoredData = ""
242245
Local Static $hJobTimer = 0

0 commit comments

Comments
 (0)