diff --git a/NetWebView2Lib.au3 b/NetWebView2Lib.au3 index 8fee755..fbce92b 100644 --- a/NetWebView2Lib.au3 +++ b/NetWebView2Lib.au3 @@ -181,7 +181,7 @@ EndFunc ;==>_NetWebView2_CreateManager ; $i_ZoomFactor - [optional] an integer value. Default is 1.0. ; $s_BackColor - [optional] a string value. Default is "0x2B2B2B". ; $b_InitConsole - [optional] a boolean value. Default is False. -; Return values .: None +; Return values .: $iInit ; Author ........: mLipok, ioa747 ; Modified ......: ; Remarks .......: @@ -221,7 +221,7 @@ Func _NetWebView2_Initialize($oWebV2M, $hUserGUI, $s_ProfileDirectory, $i_Left = EndIf If TimerDiff($hTimer) >= $iTimeOut_ms Then Return SetError(1, 0, '') Until $oWebV2M.IsReady Or $iMessage = $NETWEBVIEW2_MESSAGE__INIT_READY - If Not __NetWebView2_WaitForReadyState($oWebV2M, $hTimer, $iTimeOut_ms) Then Return SetError(2, 0, '') +;~ If Not __NetWebView2_WaitForReadyState($oWebV2M, $hTimer, $iTimeOut_ms) Then Return SetError(2, 0, '') #EndRegion ; After Initialization wait for the engine to be ready before navigating ; WebView2 Configuration @@ -235,7 +235,7 @@ Func _NetWebView2_Initialize($oWebV2M, $hUserGUI, $s_ProfileDirectory, $i_Left = EndIf If @error Then __NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " !!! Manager Creation ERROR", 1) - Return SetError(@error, $oWebV2M.GetBrowserProcessId(), '') + Return SetError(@error, $oWebV2M.GetBrowserProcessId(), $iInit) EndFunc ;==>_NetWebView2_Initialize ; #INTERNAL_USE_ONLY# =========================================================================================================== @@ -2353,3 +2353,4 @@ EndFunc ;==>__NetWebView2_Events__OnFrameWebMessageReceived #EndRegion ; === NetWebView2Lib UDF === EVENT HANDLERS * #TODO === #EndRegion ; === NetWebView2Lib UDF === EVENT HANDLERS === + diff --git a/examples/000-NetJson.Parser.au3 b/examples/000-NetJson.Parser.au3 index 2289bd3..884aad1 100644 --- a/examples/000-NetJson.Parser.au3 +++ b/examples/000-NetJson.Parser.au3 @@ -15,6 +15,7 @@ _Example() Exit Func _Example() + ConsoleWrite("! MicrosoftEdgeWebview2 : version check: " & _NetWebView2_IsAlreadyInstalled() & ' ERR=' & @error & ' EXT=' & @extended & @CRLF) ConsoleWrite(@CRLF & "=== STARTING NETJSON TUTORIAL ===" & @CRLF) #Region ; 0. Initialize the COM Object diff --git a/examples/001-BasicDemo.au3 b/examples/001-BasicDemo.au3 index 5314083..3fe48b0 100644 --- a/examples/001-BasicDemo.au3 +++ b/examples/001-BasicDemo.au3 @@ -108,7 +108,7 @@ Func _BridgeMyEventsHandler_OnMessageReceived($oWebV2M, $hGUI, $sMessage) If $sMessage = "CLOSE_APP" Then If MsgBox(36, "Confirm", "Exit Application?", 0, $hGUI) = 6 Then Exit Else - MsgBox(64, "JS Notification", "Message from Browser: " & $sMessage) + MsgBox($MB_ICONINFORMATION, "JS Notification", "Message from Browser: " & $sMessage) $iMsgCnt += 1 UpdateWebUI($oWebV2M, "mainTitle", $iMsgCnt & " Hello from AutoIt!") EndIf diff --git a/examples/009-Auditor.au3 b/examples/009-Auditor.au3 index 34ad726..8a3f3aa 100644 --- a/examples/009-Auditor.au3 +++ b/examples/009-Auditor.au3 @@ -140,7 +140,7 @@ Func _Example() ; WebView2 Setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Initialize WebView2 Manager and register events - Local $oWebV2M = _NetWebView2_CreateManager("", "WebView_", "") + Local $oWebV2M = _NetWebView2_CreateManager("", "WebView_", "", False) If @error Then Exit ConsoleWrite("@@(" & @ScriptLineNumber & ") :: @error:" & @error & ", @extended:" & @extended & @CRLF) ; create JavaScript Bridge object @@ -311,7 +311,7 @@ Func _WebView_OnMessageReceived($oWebV2M, $hGUI, $sMessage) EndIf Case "PDF_SUCCESS" - MsgBox(64, "Success", "PDF Report saved successfully!") + MsgBox($MB_ICONINFORMATION, "Success", "PDF Report saved successfully!") Case "PDF_ERROR" MsgBox(16, "Error", "PDF Export failed: " & $sMessage) diff --git a/examples/011-TwinWebView.au3 b/examples/011-TwinWebView.au3 index 179e735..369232f 100644 --- a/examples/011-TwinWebView.au3 +++ b/examples/011-TwinWebView.au3 @@ -19,9 +19,10 @@ #include #include #include +#include "..\NetWebView2Lib.au3" #include "_WV2_ExtensionPicker.au3" -OnAutoItExitRegister("_ExitApp") +OnAutoItExitRegister(_ExitApp) ; Global Objects & Handles Global $oWeb1, $oWeb2 @@ -50,7 +51,7 @@ Func _MainGUI() ; Creates the primary application window and starts the message GUICtrlSetResizing(-1, $GUI_DOCKALL) ; Register the WM_SIZE message to handle window resizing dynamically - GUIRegisterMsg($WM_SIZE, "WM_SIZE") + GUIRegisterMsg($WM_SIZE, WM_SIZE) ; Initialize Browsers and their child window containers _InitBrowsers() @@ -168,32 +169,22 @@ Func _InitBrowsers() ; Creates child window containers and initializes WebView2 ; Instance 1 - "Profile_1" folder $hID1 = GUICreate("", 485, 580, 10, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN), -1, $hMainGUI) $Bar1 = _Web_MakeBar($hID1, $sExtras) - $oWeb1 = ObjCreate("NetWebView2.Manager") - ObjEvent($oWeb1, "Web1_", "IWebViewEvents") - $oBridge1 = $oWeb1.GetBridge() - ObjEvent($oBridge1, "Bridge1_", "IBridgeEvents") + $oWeb1 = _NetWebView2_CreateManager("", "Web1_") + $oBridge1 = _NetWebView2_GetBridge($oWeb1, "Bridge1_") $Bar1.Web_ProfilePath = $sProfileDirectory - $oWeb1.Initialize($hID1, $sProfileDirectory, 0, 25, 485, 555) + _NetWebView2_Initialize($oWeb1, $hID1, $sProfileDirectory, 0, 25, 485, 555, True, True, 1.2, "0x2B2B2B", False) + _NetWebView2_Navigate($oWeb1, "https://www.google.com/search?q=web1") ; Instance 2 - "Profile_2" folder $hID2 = GUICreate("", 485, 580, 505, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN), -1, $hMainGUI) $Bar2 = _Web_MakeBar($hID2, $sExtras) - $oWeb2 = ObjCreate("NetWebView2.Manager") - ObjEvent($oWeb2, "Web2_", "IWebViewEvents") - $oBridge2 = $oWeb2.GetBridge() - ObjEvent($oBridge2, "Bridge2_", "IBridgeEvents") + $oWeb2 = _NetWebView2_CreateManager("", "Web2_") + $oBridge2 = _NetWebView2_GetBridge($oWeb2, "Bridge2_") $Bar2.Web_ProfilePath = @ScriptDir & "\Profile_2" - $oWeb2.Initialize($hID2, @ScriptDir & "\Profile_2", 0, 25, 485, 555) - - ; Wait until both instances are ready - Do - Sleep(10) - Until $oWeb1.IsReady And $oWeb2.IsReady + _NetWebView2_Initialize($oWeb2, $hID2, $sProfileDirectory, 0, 25, 485, 555, True, True, 1.2, "0x2B2B2B", False) + _NetWebView2_Navigate($oWeb2, "https://www.google.com/search?q=web2") - _NetWebView2_Navigate($oWeb1, "https://www.google.com/search?q=web1") GUISetState(@SW_SHOWNOACTIVATE, $hID1) - - $oWeb2.Navigate("https://www.google.com/search?q=web2") GUISetState(@SW_SHOWNOACTIVATE, $hID2) EndFunc ;==>_InitBrowsers diff --git a/examples/012-GetCookies.au3 b/examples/012-GetCookies.au3 index d40d56c..54e1e2f 100644 --- a/examples/012-GetCookies.au3 +++ b/examples/012-GetCookies.au3 @@ -247,7 +247,7 @@ Func WebView_OnMessageReceived($sMessage) EndIf Case "PDF_SUCCESS" - MsgBox(64, "Success", "PDF Report saved successfully!") + MsgBox($MB_ICONINFORMATION, "Success", "PDF Report saved successfully!") Case "ERROR", "NAV_ERROR" diff --git a/examples/014-pdfJS-Static_PDF_Viewer.au3 b/examples/014-pdfJS-Static_PDF_Viewer.au3 index b0f1e32..0a33f5e 100644 --- a/examples/014-pdfJS-Static_PDF_Viewer.au3 +++ b/examples/014-pdfJS-Static_PDF_Viewer.au3 @@ -41,7 +41,7 @@ Func _Example() ; initialize browser - put it on the GUI Local $sProfileDirectory = @ScriptDir & "\NetWebView2Lib-UserDataFolder" - _NetWebView2_Initialize($oWeb, $hGUI, $sProfileDirectory, 0, 0, 0, 0, True, False, False, 0.7) + _NetWebView2_Initialize($oWeb, $hGUI, $sProfileDirectory, 0, 0, 0, 0, True, True, 0.7) ; Get the bridge object and register events Local $oBridge = _NetWebView2_GetBridge($oWeb, "__UserEventHandler__Bridge_") @@ -130,6 +130,17 @@ Func _Example() _NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE0_FIREANDFORGET) MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "After:" & @CRLF & $s_JavaScript_snipp) + $s_JavaScript_snipp = 'PDFViewerApplication.open({ url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" });' + _NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE0_FIREANDFORGET) + MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "After:" & @CRLF & $s_JavaScript_snipp) + +;~ $s_JavaScript_snipp = FileRead(@ScriptDir & '\JS_Lib\PDFViewerApplicationEvents.js') +;~ _NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE2_RESULT) + + $s_JavaScript_snipp = 'PDFViewerApplication.open({ url: "https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf" });' + _NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE0_FIREANDFORGET) + MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "After:" & @CRLF & $s_JavaScript_snipp) + #EndRegion ; now we can call the script directly from the JavaScript library "NetWebView2Lib_pdfjs_Tools.js" - some pdfjs magic stuff ;) ; Main Loop diff --git a/examples/017-MappedFolder.au3 b/examples/017-MappedFolder.au3 index 09e8b3a..fc927db 100644 --- a/examples/017-MappedFolder.au3 +++ b/examples/017-MappedFolder.au3 @@ -13,6 +13,8 @@ _Example() Func _Example() + ConsoleWrite("! MicrosoftEdgeWebview2 : version check: " & _NetWebView2_IsAlreadyInstalled() & ' ERR=' & @error & ' EXT=' & @extended & @CRLF) + Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) #forceref $oMyError diff --git a/examples/018-BasicFramesDemo.au3 b/examples/018-BasicFramesDemo.au3 index 50e2014..16d26cf 100644 --- a/examples/018-BasicFramesDemo.au3 +++ b/examples/018-BasicFramesDemo.au3 @@ -52,12 +52,12 @@ Func Main() #Region - Testing how to manage frames _NetWebView2_Navigate($oWebV2M, 'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe', $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, "", 5000) - MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 1) + MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Wait till all frames are loaded') ;~ _Demo_NavigateCheckBanner($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe", '//*[@id="snigel-cmp-framework" and @class="snigel-cmp-framework"]') If @error Then Return SetError(@error, @extended) - #Region ; Example part 1 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) - ConsoleWrite("+ Example part 1 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF) + #Region ; Example part 1 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) + ConsoleWrite("+ Example part 1 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF) Local $iFrameCount = $oWebV2M.GetFrameCount() ConsoleWrite(@CRLF) @@ -68,17 +68,19 @@ Func Main() ConsoleWrite("- NAME=" & $oWebV2M.GetFrameName($IDX_Frame) & @CRLF) ConsoleWrite(@CRLF) Next - #EndRegion ; Example part 1 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) + MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Example part 1 - testing NetWebView2Lib methodes: ' & @CRLF & '.GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)' & @CRLF & 'End') + #EndRegion ; Example part 1 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) - #Region ; Example part 2 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) - ConsoleWrite("+ Example part 2 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF) + #Region ; Example part 2 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) + ConsoleWrite("+ Example part 2 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameUrls() :" & @CRLF & $oWebV2M.GetFrameUrls() & @CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameNames() :" & @CRLF & $oWebV2M.GetFrameNames() & @CRLF) - #EndRegion ; Example part 2 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) + MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Example part 2 - testing NetWebView2Lib methodes:' & @CRLF & '.GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)' & @CRLF & 'End') + #EndRegion ; Example part 2 - testing NetWebView2Lib methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) - #Region ; Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame) - ConsoleWrite("+ Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame)" & @CRLF) + #Region ; Example part 3 - testing NetWebView2Lib methodes .GetFrameHtmlSource($IDX_Frame) + ConsoleWrite("+ Example part 3 - testing NetWebView2Lib methodes .GetFrameHtmlSource($IDX_Frame)" & @CRLF) For $IDX_Frame = 0 To $iFrameCount - 1 ConsoleWrite(@CRLF & "======================================================" & @CRLF) Local $sHtmlSource = Fire_And_Wait($oWebV2M.GetFrameHtmlSource($IDX_Frame), 5000) ; pair with "FRAME_HTML_SOURCE" @@ -87,8 +89,8 @@ Func Main() ConsoleWrite(@CRLF & "======================================================" & @CRLF) ConsoleWrite(@CRLF) ConsoleWrite(@CRLF) - #EndRegion ; Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame) - + MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Example part 3 - testing NetWebView2Lib methodes : ' & @CRLF & '.GetFrameHtmlSource($IDX_Frame)' & @CRLF & 'End') + #EndRegion ; Example part 3 - testing NetWebView2Lib methodes .GetFrameHtmlSource($IDX_Frame) #Region ; Example part 4 - Direct Frame Interaction @@ -106,6 +108,8 @@ Func Main() ConsoleWrite("VarGetType($oFrame0)=" & VarGetType($oFrame0) & @CRLF) ConsoleWrite("$oFrame0.Name=" & $oFrame0.Name & @CRLF & @CRLF) + ConsoleWrite("$oFrame0.FrameId=" & $oFrame0.FrameId & @CRLF & @CRLF) + ConsoleWrite("$oFrame0.IsDestroyed()=" & $oFrame0.IsDestroyed() & @CRLF & @CRLF) ; Direct script execution in the iframe without involving the central Manager $oFrame0.ExecuteScript("document.body.style.backgroundColor = 'red';") @@ -118,12 +122,19 @@ Func Main() Else ConsoleWrite("! Error: $oFrame0 is not a valid COM Object" & @CRLF) EndIf - + MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'Example part 4 - Direct Frame Interaction: ' & @CRLF & '' & @CRLF & 'End') #EndRegion ; Example part 4 - Direct Frame Interaction + #Region ; Example part 5 - Get all Frames as array + Local $aFrames + Do + $aFrames = _NetWebView2_GetAllFrames_AsArray($oWebV2M) + _ArrayDisplay($aFrames, @ScriptLineNumber & ' $aFrames : Example part 5 - Get all Frames as array') + Until ($IDNO = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", "Check again all frames ?")) - #EndRegion - Testing how to manage frames + #EndRegion ; Example part 5 - Get all Frames as array + #EndRegion - Testing how to manage frames ; Main Loop While 1 @@ -135,46 +146,58 @@ Func Main() GUIDelete($hGUI) - _NetWebView2_CleanUp($oWebV2M, $oJSBridge) EndFunc ;==>Main -; ============================================================================== -; ; Function to update a text element inside the WebView UI -; ============================================================================== -Func UpdateWebUI($oWebV2M, $sElementId, $sNewText) - If Not IsObj($oWebV2M) Then Return '' - - ; Escape backslashes, single quotes and handle new lines for JavaScript safety - Local $sCleanText = StringReplace($sNewText, "\", "\\") - $sCleanText = StringReplace($sCleanText, "'", "\'") - $sCleanText = StringReplace($sCleanText, @CRLF, "\n") - $sCleanText = StringReplace($sCleanText, @LF, "\n") - - Local $sJavaScript = "document.getElementById('" & $sElementId & "').innerText = '" & $sCleanText & "';" - _NetWebView2_ExecuteScript($oWebV2M, $sJavaScript) -EndFunc ;==>UpdateWebUI - -; ============================================================================== -; MY EVENT HANDLER: Bridge (JavaScript Messages) -; ============================================================================== -Func _BridgeMyEventsHandler_OnMessageReceived($oWebV2M, $hGUI, $sMessage) - Local Static $iMsgCnt = 0 +; #FUNCTION# ==================================================================================================================== +; Name ..........: _NetWebView2_GetAllFrames_AsArray +; Description ...: Get all Frames as array +; Syntax ........: _NetWebView2_GetAllFrames_AsArray($oWebV2M) +; Parameters ....: $oWebV2M - an object. +; Return values .: None +; Author ........: mLipok +; Modified ......: +; Remarks .......: +; Related .......: +; Link ..........: +; Example .......: No +; =============================================================================================================================== +Func _NetWebView2_GetAllFrames_AsArray($oWebV2M) + Local Const $s_Prefix = "[_NetWebView2_GetAllFrames_AsArray]:" + Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler + #forceref $oMyError, $s_Prefix + + Local Enum _ + $FRAME_IDX, _ + $FRAME_OBJECT, _ + $FRAME_ID, _ + $FRAME_NAME, _ + $FRAME_URL, _ + $FRAME_DESTROYED, _ + $FRAME_HTML, _ + $FRAME__COUNTER - If $sMessage = "CLOSE_APP" Then - If MsgBox(36, "Confirm", "Exit Application?", 0, $hGUI) = 6 Then Exit - Else - MsgBox(64, "JS Notification", "Message from Browser: " & $sMessage) - $iMsgCnt += 1 - UpdateWebUI($oWebV2M, "mainTitle", $iMsgCnt & " Hello from AutoIt!") - EndIf -EndFunc ;==>_BridgeMyEventsHandler_OnMessageReceived + Local $iFrameCount = $oWebV2M.GetFrameCount() + Local $aFrames[$iFrameCount][$FRAME__COUNTER] + Local $oFrame + For $IDX_Frame = 0 To $iFrameCount - 1 + $oFrame = $oWebV2M.GetFrame($IDX_Frame) + $aFrames[$IDX_Frame][$FRAME_IDX] = $IDX_Frame + $aFrames[$IDX_Frame][$FRAME_OBJECT] = $oFrame + $aFrames[$IDX_Frame][$FRAME_ID] = $oFrame.FrameId + $aFrames[$IDX_Frame][$FRAME_NAME] = $oWebV2M.Name + $aFrames[$IDX_Frame][$FRAME_URL] = $oWebV2M.GetFrameUrl($IDX_Frame) + $aFrames[$IDX_Frame][$FRAME_DESTROYED] = $oFrame.IsDestroyed() + $aFrames[$IDX_Frame][$FRAME_HTML] = $oWebV2M.GetFrameHtmlSource($IDX_Frame) + Next + Return $aFrames +EndFunc ;==>_NetWebView2_GetAllFrames_AsArray ; ============================================================================== ; MyHook_ Events ; ============================================================================== Func MyHook_OnMessageReceived($oWebV2M, $hGUI, $sMsg) - #forceref $oWebV2M, $hGUI, $sMsg + #forceref $oWebV2M, $hGUI ConsoleWrite("> [MyHook] OnMessageReceived: GUI:" & $hGUI & " Msg: " & (StringLen($sMsg) > 30 ? StringLeft($sMsg, 30) & "..." : $sMsg) & @CRLF) Local $iSplitPos = StringInStr($sMsg, "|") Local $sCommand = $iSplitPos ? StringStripWS(StringLeft($sMsg, $iSplitPos - 1), 3) : $sMsg @@ -194,27 +217,6 @@ Func MyHook_OnMessageReceived($oWebV2M, $hGUI, $sMsg) EndSwitch EndFunc ;==>MyHook_OnMessageReceived -; ============================================================================== -; HELPER: Demo HTML Content -; ============================================================================== -Func __GetDemoHTML() - Local $sH = _ - '' & _ - '
' & _ - '

WebView2 + AutoIt .NET Manager

' & _ ; Fixed ID attribute - '

The communication is now 100% Event-Driven (No Sleep needed).

' & _ - ' ' & _ - ' ' & _ - '
' & _ - '' - Return $sH -EndFunc ;==>__GetDemoHTML - Func __Example_Log($s_ScriptLineNumber, $sString, $iError = @error, $iExtended = @extended) ConsoleWrite(@ScriptName & ' SLN=' & $s_ScriptLineNumber & ' [' & $iError & '/' & $iExtended & '] ::: ' & $sString & @CRLF) Return SetError($iError, $iExtended, '') @@ -237,6 +239,7 @@ EndFunc ;==>__Example_Log ; Remarks........: This function uses static variables to bridge the gap between async COM events and sync script execution. ; It effectively pauses the script execution until the WebView2 event fires back with data. ; =============================================================================================================================== + Func Fire_And_Wait($sData = "", $iTimeout = 5000) Local Static $vStoredData = "" Local Static $hJobTimer = 0