From 4cbe66cb09e967dc69872abc81eeb4015a79af6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Tue, 17 Feb 2026 23:34:26 +0100 Subject: [PATCH 1/6] 018-BasicFramesDemo.au3 --- examples/018-BasicFramesDemo.au3 | 286 +++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 examples/018-BasicFramesDemo.au3 diff --git a/examples/018-BasicFramesDemo.au3 b/examples/018-BasicFramesDemo.au3 new file mode 100644 index 0000000..c59ac4f --- /dev/null +++ b/examples/018-BasicFramesDemo.au3 @@ -0,0 +1,286 @@ +#WIP - this Example is imported from 1.5.0 UDF - and is in "WORK IN PROGRESS" state +#AutoIt3Wrapper_UseX64=y +#AutoIt3Wrapper_Run_AU3Check=Y +#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y +;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 + +; 001-BasicDemo.au3 + +#include +#include +#include "..\NetWebView2Lib.au3" + +Main() + +Func Main() + ConsoleWrite("! MicrosoftEdgeWebview2 : version check: " & _NetWebView2_IsAlreadyInstalled() & ' ERR=' & @error & ' EXT=' & @extended & @CRLF) + + Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) + #forceref $oMyError + + ; Create the UI + Local $iHeight = 800 + Local $hGUI = GUICreate("WebView2 .NET Manager - Community Demo", 1100, $iHeight) + GUICtrlSetFont(-1, 9, 400, 0, "Segoe UI") + + WinMove($hGUI, '', Default, Default, 800, 440) + GUISetState(@SW_SHOW, $hGUI) + + ; Initialize WebView2 Manager and register events + Local $oWebV2M = _NetWebView2_CreateManager("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0", "", "--disable-gpu, --mute-audio") + If @error Then Return SetError(@error, @extended, $oWebV2M) + + ; Initialize JavaScript Bridge + Local $oJSBridge = _NetWebView2_GetBridge($oWebV2M, "_BridgeMyEventsHandler_") + If @error Then Return SetError(@error, @extended, $oWebV2M) + + Local $sProfileDirectory = @ScriptDir & "\NetWebView2Lib-UserDataFolder" + _NetWebView2_Initialize($oWebV2M, $hGUI, $sProfileDirectory, 0, 0, 0, 0, True, True, 1.2, "0x2B2B2B", False) + If @error Then Return SetError(@error, @extended, $oWebV2M) + + __Example_Log(@ScriptLineNumber, "After: _NetWebView2_Initialize()" & @CRLF) + + ; navigate to HTML string - full fill the object with your own offline content - without downloading any content + ConsoleWrite(@CRLF) + + __Example_Log(@ScriptLineNumber, "Before: _NetWebView2_NavigateToString()") + GUISetState(@SW_SHOW, $hGUI) + WinMove($hGUI, '', Default, Default, 1100, 800) + + #COMMENT This example is based on ==> ; https://github.com/Danp2/au3WebDriver/blob/1834e95206bd4a6ef6952c47a1f1192042f98c0b/wd_demo.au3#L588-L732 + #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) +;~ _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 ; testing NetWebView2Lib new methodes + Local $iFrameCount = $oWebV2M.GetFrameCount() + ConsoleWrite(@CRLF) + ConsoleWrite("! " & @ScriptLineNumber & " : Frames=" & $iFrameCount & @CRLF) + For $IDX_Frame = 0 To $iFrameCount -1 + ConsoleWrite("- IDX=" & $IDX_Frame & @CRLF) + ConsoleWrite("- URL=" & $oWebV2M.GetFrameUrl($IDX_Frame) & @CRLF) + ConsoleWrite("- NAME=" & $oWebV2M.GetFrameName($IDX_Frame) & @CRLF) + ConsoleWrite(@CRLF) + Next + + ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameUrls() :" & @CRLF & $oWebV2M.GetFrameUrls() & @CRLF) + ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameNames() :" & @CRLF & $oWebV2M.GetFrameNames() & @CRLF) + For $IDX_Frame = 0 To $iFrameCount -1 + ConsoleWrite(@CRLF & "======================================================" & @CRLF) + ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameHtmlSource("&$IDX_Frame&") :" & @CRLF & $oWebV2M.GetFrameHtmlSource($IDX_Frame) & @CRLF) + Next + ConsoleWrite(@CRLF & "======================================================" & @CRLF) + ConsoleWrite(@CRLF) + ConsoleWrite(@CRLF) + #EndRegion ; testing NetWebView2Lib new methodes + +#CS + ; just after navigate current context should be on top level Window + ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : TopWindow = " & $bIsWindowTop & @CRLF) + + $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']") + ; changing context to first frame + _WD_FrameEnter($sSession, $sElement) + If @error Then Return SetError(@error, @extended) + + $bIsWindowTop = _WD_IsWindowTop($sSession) + ; after changing context to first frame the current context is not on top level Window + ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : TopWindow = " & $bIsWindowTop & @CRLF) + + ; changing context to first sub frame using iframe element specified ByXPath + $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe") + _WD_FrameEnter($sSession, $sElement) + If @error Then Return SetError(@error, @extended) + + ; Leaving sub frame + _WD_FrameLeave($sSession) + If @error Then Return SetError(@error, @extended) + + $bIsWindowTop = _WD_IsWindowTop($sSession) + ; after leaving sub frame, the current context is back to first frame but still is not on top level Window + ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : TopWindow = " & $bIsWindowTop & @CRLF) + + ; Leaving first frame + _WD_FrameLeave($sSession) + If @error Then Return SetError(@error, @extended) +#CE + + #EndRegion - Testing how to manage frames + +#CS + + #Region - Testing _WD_FrameList() usage + + #Region - Example 1 ; from 'https://www.w3schools.com' get frame list as string + $bIsWindowTop = _WD_IsWindowTop($sSession) + ; after leaving first frame, the current context should back on top level Window + ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : TopWindow = " & $bIsWindowTop & @CRLF) + + ; now lets try to check frame list and using locations as path 'null/0' + ; firstly go to website + _WD_Navigate($sSession, 'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe') + _WD_LoadWait($sSession) + + Local $sResult = _WD_FrameList($sSession, False) + ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 1" & @CRLF) + ConsoleWrite($sResult & @CRLF) + #EndRegion - Example 1 ; from 'https://www.w3schools.com' get frame list as string + + #Region - Example 2 ; from 'https://www.w3schools.com' get frame list as array + Local $aFrameList = _WD_FrameList($sSession, True) + ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 2" & @CRLF) + _ArrayDisplay($aFrameList, 'Example 2 - w3schools.com - get frame list as array', 0, 0, Default, $sArrayHeader) + + #EndRegion - Example 2 ; from 'https://www.w3schools.com' get frame list as array + + #Region - Example 3 ; from 'https://www.w3schools.com' get frame list as array, while current location is "null/0" + ; check if document context location is Top Window - should be as we are after navigation + ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) + + ; change document context location by path 'null/0' + _WD_FrameEnter($sSession, 'null/0') + + ; check if document context location is Top Window - should not be as we enter to frame 'null/0' + ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) + + $aFrameList = _WD_FrameList($sSession, True) + ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 3" & @CRLF) + _ArrayDisplay($aFrameList, 'Example 3 - w3schools.com - relative to "null/0"', 0, 0, Default, $sArrayHeader) + #EndRegion - Example 3 ; from 'https://www.w3schools.com' get frame list as array, while current location is "null/0" + + #Region - Example 4 ; from 'https://stackoverflow.com' get frame list as string + ; go to another website + _WD_Navigate($sSession, 'https://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom') + _WD_LoadWait($sSession) + + $sResult = _WD_FrameList($sSession, False) + ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 4" & @CRLF) + ConsoleWrite($sResult & @CRLF) + #EndRegion - Example 4 ; from 'https://stackoverflow.com' get frame list as string + + #Region - Example 5 ; from 'https://stackoverflow.com' get frame list as array + $aFrameList = _WD_FrameList($sSession, True) + ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 5" & @CRLF) + _ArrayDisplay($aFrameList, 'Example 5 - stackoverflow.com - get frame list as array', 0, 0, Default, $sArrayHeader) + #EndRegion - Example 5 ; from 'https://stackoverflow.com' get frame list as array + + #Region - Example 6v1 ; from 'https://stackoverflow.com' get frame list as array, while is current location is "null/2" + ; check if document context location is Top Window - should be as we are after navigation + ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) + + ; change document context location by path 'null/2' + _WD_FrameEnter($sSession, 'null/2') + + ; check if document context location is Top Window - should not be as we enter to frame 'null/2' + ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) + + $aFrameList = _WD_FrameList($sSession, True) + ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 6v1" & @CRLF) + _ArrayDisplay($aFrameList, 'Example 6v1 - stackoverflow.com - relative to "null/2"', 0, 0, Default, $sArrayHeader) + #EndRegion - Example 6v1 ; from 'https://stackoverflow.com' get frame list as array, while is current location is "null/2" + + #Region - Example 6v2 ; from 'https://stackoverflow.com' get frame list as array, check if it is still relative to the same location as it was before recent _WD_FrameList() was used - still should be "null/2" + ; check if document context location is Top Window + ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) + + $aFrameList = _WD_FrameList($sSession, True) + ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 6v2" & @CRLF) + _ArrayDisplay($aFrameList, 'Example 6v2 - stackoverflow.com - check if it is still relative to "null/2"', 0, 0, Default, $sArrayHeader) + #EndRegion - Example 6v2 ; from 'https://stackoverflow.com' get frame list as array, check if it is still relative to the same location as it was before recent _WD_FrameList() was used - still should be "null/2" + + #EndRegion - Testing _WD_FrameList() usage + + #Region - Testing element location in frame set and iframe collecion + ; go to website + _WD_Navigate($sSession, 'https://www.tutorialspoint.com/html/html_frames.htm#') + _WD_LoadWait($sSession) + + ; check if document context location is Top Window + ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) + + MsgBox($MB_TOPMOST, "", 'Before checking location of multiple elements on multiple frames' & @CRLF & 'Try the same example with and without waiting about 30 seconds in order to see that many frames should be fully loaded, and to check the differences') + + $aFrameList = _WD_FrameList($sSession, True, 5000, Default) + ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example : Testing element location in frame set - after pre-checking list of frames" & @CRLF) + _ArrayDisplay($aFrameList, @ScriptLineNumber & ' Before _WD_FrameListFindElement - www.tutorialspoint.com - get frame list as array', 0, 0, Default, $sArrayHeader) + + Local $aLocationOfElement = _WD_FrameListFindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "li.nav-item[data-bs-original-title='Home Page'] a.nav-link[href='https://www.tutorialspoint.com/index.htm']") + ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : $aLocationOfElement (" & UBound($aLocationOfElement) & ")=" & @CRLF & _ArrayToString($aLocationOfElement) & @CRLF) + _ArrayDisplay($aLocationOfElement, @ScriptLineNumber & ' $aLocationOfElement', 0, 0, Default, $sArrayHeader) + + #EndRegion - Testing element location in frame set and iframe collecion + +#CE + + ; Main Loop + While 1 + Switch GUIGetMsg() + Case $GUI_EVENT_CLOSE + ExitLoop + EndSwitch + WEnd + + 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 + + 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 + +; ============================================================================== +; 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, '') +EndFunc ;==>__Example_Log From 1d8ad454d2df54686513275c23cde4bf95ff64a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:19:37 +0100 Subject: [PATCH 2/6] Update 018-BasicFramesDemo.au3 --- examples/018-BasicFramesDemo.au3 | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/examples/018-BasicFramesDemo.au3 b/examples/018-BasicFramesDemo.au3 index c59ac4f..6e90af7 100644 --- a/examples/018-BasicFramesDemo.au3 +++ b/examples/018-BasicFramesDemo.au3 @@ -54,27 +54,40 @@ Func Main() ;~ _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 ; testing NetWebView2Lib new methodes + #Region ; Example part 1 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) Local $iFrameCount = $oWebV2M.GetFrameCount() ConsoleWrite(@CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : Frames=" & $iFrameCount & @CRLF) - For $IDX_Frame = 0 To $iFrameCount -1 + For $IDX_Frame = 0 To $iFrameCount - 1 ConsoleWrite("- IDX=" & $IDX_Frame & @CRLF) ConsoleWrite("- URL=" & $oWebV2M.GetFrameUrl($IDX_Frame) & @CRLF) 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) + #Region ; Example part 2 - testing NetWebView2Lib new methodes .GetFrameUrls() .GetFrameNames() ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameUrls() :" & @CRLF & $oWebV2M.GetFrameUrls() & @CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameNames() :" & @CRLF & $oWebV2M.GetFrameNames() & @CRLF) - For $IDX_Frame = 0 To $iFrameCount -1 + #EndRegion ; Example part 2 - testing NetWebView2Lib new methodes .GetFrameUrls() .GetFrameNames() + + #Region ; Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame) + For $IDX_Frame = 0 To $iFrameCount - 1 ConsoleWrite(@CRLF & "======================================================" & @CRLF) - ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameHtmlSource("&$IDX_Frame&") :" & @CRLF & $oWebV2M.GetFrameHtmlSource($IDX_Frame) & @CRLF) + ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameHtmlSource(" & $IDX_Frame & ") :" & @CRLF & $oWebV2M.GetFrameHtmlSource($IDX_Frame) & @CRLF) Next ConsoleWrite(@CRLF & "======================================================" & @CRLF) ConsoleWrite(@CRLF) ConsoleWrite(@CRLF) - #EndRegion ; testing NetWebView2Lib new methodes + #Region ; Example part 1 - testing NetWebView2Lib new methodes + +#cs NOT SUPPORTED YET + Local $oFrame0 = $oWebV2M.GetFrame(0) + Local $oFrame1 = $oWebV2M.GetFrame(1) + Local $oFrame2 = $oWebV2M.GetFrame(2) + Local $oFrame3 = $oWebV2M.GetFrame(3) +#CE NOT SUPPORTED YET + #CS ; just after navigate current context should be on top level Window @@ -107,7 +120,7 @@ Func Main() If @error Then Return SetError(@error, @extended) #CE - #EndRegion - Testing how to manage frames + #EndRegion ; Example part 1 - testing NetWebView2Lib new methodes #CS From 96a5b1a14a621c38fbe92b5831f0e7a9acbd08e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:23:02 +0100 Subject: [PATCH 3/6] Update 018-BasicFramesDemo.au3 --- examples/018-BasicFramesDemo.au3 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/018-BasicFramesDemo.au3 b/examples/018-BasicFramesDemo.au3 index 6e90af7..02ae71d 100644 --- a/examples/018-BasicFramesDemo.au3 +++ b/examples/018-BasicFramesDemo.au3 @@ -55,6 +55,8 @@ Func Main() 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) + Local $iFrameCount = $oWebV2M.GetFrameCount() ConsoleWrite(@CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : Frames=" & $iFrameCount & @CRLF) @@ -66,12 +68,15 @@ Func Main() Next #EndRegion ; Example part 1 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame) - #Region ; Example part 2 - testing NetWebView2Lib new methodes .GetFrameUrls() .GetFrameNames() + #Region ; Example part 2 - 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) + ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameUrls() :" & @CRLF & $oWebV2M.GetFrameUrls() & @CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameNames() :" & @CRLF & $oWebV2M.GetFrameNames() & @CRLF) #EndRegion ; Example part 2 - testing NetWebView2Lib new methodes .GetFrameUrls() .GetFrameNames() #Region ; Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame) + ConsoleWrite("+ Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame)" & @CRLF) For $IDX_Frame = 0 To $iFrameCount - 1 ConsoleWrite(@CRLF & "======================================================" & @CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameHtmlSource(" & $IDX_Frame & ") :" & @CRLF & $oWebV2M.GetFrameHtmlSource($IDX_Frame) & @CRLF) From 72f04d6ecfd169d444e8a3b546d94744b05afd35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:23:34 +0100 Subject: [PATCH 4/6] Update 018-BasicFramesDemo.au3 --- examples/018-BasicFramesDemo.au3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/018-BasicFramesDemo.au3 b/examples/018-BasicFramesDemo.au3 index 02ae71d..fe74b2b 100644 --- a/examples/018-BasicFramesDemo.au3 +++ b/examples/018-BasicFramesDemo.au3 @@ -69,7 +69,7 @@ Func Main() #EndRegion ; Example part 1 - testing NetWebView2Lib new 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 1 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF) + ConsoleWrite("+ Example part 2 - testing NetWebView2Lib new methodes: .GetFrameCount() .GetFrameUrl($IDX_Frame) .GetFrameName($IDX_Frame)" & @CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameUrls() :" & @CRLF & $oWebV2M.GetFrameUrls() & @CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameNames() :" & @CRLF & $oWebV2M.GetFrameNames() & @CRLF) From 8ed88f0e918504dfe7504baee1df0b9ce5add5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:27:28 +0100 Subject: [PATCH 5/6] Update 018-BasicFramesDemo.au3 --- examples/018-BasicFramesDemo.au3 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/018-BasicFramesDemo.au3 b/examples/018-BasicFramesDemo.au3 index fe74b2b..e67de88 100644 --- a/examples/018-BasicFramesDemo.au3 +++ b/examples/018-BasicFramesDemo.au3 @@ -2,9 +2,9 @@ #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Run_AU3Check=Y #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y -;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 +#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 -; 001-BasicDemo.au3 +; 018-BasicFramesDemo.au3 #include #include @@ -49,6 +49,7 @@ Func Main() #COMMENT This example is based on ==> ; https://github.com/Danp2/au3WebDriver/blob/1834e95206bd4a6ef6952c47a1f1192042f98c0b/wd_demo.au3#L588-L732 #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) ;~ _Demo_NavigateCheckBanner($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe", '//*[@id="snigel-cmp-framework" and @class="snigel-cmp-framework"]') @@ -73,7 +74,7 @@ Func Main() ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameUrls() :" & @CRLF & $oWebV2M.GetFrameUrls() & @CRLF) ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameNames() :" & @CRLF & $oWebV2M.GetFrameNames() & @CRLF) - #EndRegion ; Example part 2 - testing NetWebView2Lib new methodes .GetFrameUrls() .GetFrameNames() + #EndRegion ; Example part 2 - testing NetWebView2Lib new 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) @@ -84,7 +85,8 @@ Func Main() ConsoleWrite(@CRLF & "======================================================" & @CRLF) ConsoleWrite(@CRLF) ConsoleWrite(@CRLF) - #Region ; Example part 1 - testing NetWebView2Lib new methodes + #EndRegion ; Example part 3 - testing NetWebView2Lib new methodes .GetFrameHtmlSource($IDX_Frame) + #cs NOT SUPPORTED YET Local $oFrame0 = $oWebV2M.GetFrame(0) @@ -125,7 +127,7 @@ Func Main() If @error Then Return SetError(@error, @extended) #CE - #EndRegion ; Example part 1 - testing NetWebView2Lib new methodes + #EndRegion - Testing how to manage frames #CS From 9622ec43462e92b7e5c3974dc563397e45aadb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipok?= <11089482+mlipok@users.noreply.github.com> Date: Tue, 24 Feb 2026 04:38:18 +0100 Subject: [PATCH 6/6] Update 018-BasicFramesDemo.au3 --- examples/018-BasicFramesDemo.au3 | 356 ++++++++++++++----------------- 1 file changed, 161 insertions(+), 195 deletions(-) diff --git a/examples/018-BasicFramesDemo.au3 b/examples/018-BasicFramesDemo.au3 index e67de88..b03494f 100644 --- a/examples/018-BasicFramesDemo.au3 +++ b/examples/018-BasicFramesDemo.au3 @@ -27,7 +27,8 @@ Func Main() GUISetState(@SW_SHOW, $hGUI) ; Initialize WebView2 Manager and register events - Local $oWebV2M = _NetWebView2_CreateManager("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0", "", "--disable-gpu, --mute-audio") + Local $oWebV2M = _NetWebView2_CreateManager("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0", _ + "MyHook_", "--disable-gpu, --mute-audio") If @error Then Return SetError(@error, @extended, $oWebV2M) ; Initialize JavaScript Bridge @@ -51,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) @@ -67,173 +68,74 @@ 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) - ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameHtmlSource(" & $IDX_Frame & ") :" & @CRLF & $oWebV2M.GetFrameHtmlSource($IDX_Frame) & @CRLF) + Local $sHtmlSource = Fire_And_Wait($oWebV2M.GetFrameHtmlSource($IDX_Frame), 5000) ; pair with "FRAME_HTML_SOURCE" + ConsoleWrite("! " & @ScriptLineNumber & " : GetFrameHtmlSource(" & $IDX_Frame & ") :" & @CRLF & $sHtmlSource & @CRLF) Next 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 -#cs NOT SUPPORTED YET - Local $oFrame0 = $oWebV2M.GetFrame(0) - Local $oFrame1 = $oWebV2M.GetFrame(1) - Local $oFrame2 = $oWebV2M.GetFrame(2) - Local $oFrame3 = $oWebV2M.GetFrame(3) -#CE NOT SUPPORTED YET + #cs NOT SUPPORTED YET + Local $oFrame0 = $oWebV2M.GetFrame(0) + Local $oFrame1 = $oWebV2M.GetFrame(1) + Local $oFrame2 = $oWebV2M.GetFrame(2) + Local $oFrame3 = $oWebV2M.GetFrame(3) + #CE NOT SUPPORTED YET + Local $oFrame0 = $oWebV2M.GetFrame(0) -#CS - ; just after navigate current context should be on top level Window - ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : TopWindow = " & $bIsWindowTop & @CRLF) + ConsoleWrite("+ Example part 4 - Direct Frame Interaction via COM Object" & @CRLF) + If IsObj($oFrame0) Then - $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']") - ; changing context to first frame - _WD_FrameEnter($sSession, $sElement) - If @error Then Return SetError(@error, @extended) + 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) - $bIsWindowTop = _WD_IsWindowTop($sSession) - ; after changing context to first frame the current context is not on top level Window - ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : TopWindow = " & $bIsWindowTop & @CRLF) + ; Direct script execution in the iframe without involving the central Manager + $oFrame0.ExecuteScript("document.body.style.backgroundColor = 'red';") + ConsoleWrite("> Executed background color change on Frame(0)" & @CRLF) - ; changing context to first sub frame using iframe element specified ByXPath - $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe") - _WD_FrameEnter($sSession, $sElement) - If @error Then Return SetError(@error, @extended) + ; Try getting the URL via JS + Local $sUrl = $oFrame0.ExecuteScriptWithResult("window.location.href") + ConsoleWrite("> Frame(0) URL via JS: " & $sUrl & @CRLF) - ; Leaving sub frame - _WD_FrameLeave($sSession) - If @error Then Return SetError(@error, @extended) + 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 - $bIsWindowTop = _WD_IsWindowTop($sSession) - ; after leaving sub frame, the current context is back to first frame but still is not on top level Window - ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : TopWindow = " & $bIsWindowTop & @CRLF) + #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 ?")) - ; Leaving first frame - _WD_FrameLeave($sSession) - If @error Then Return SetError(@error, @extended) -#CE + #EndRegion ; Example part 5 - Get all Frames as array #EndRegion - Testing how to manage frames -#CS - - #Region - Testing _WD_FrameList() usage - - #Region - Example 1 ; from 'https://www.w3schools.com' get frame list as string - $bIsWindowTop = _WD_IsWindowTop($sSession) - ; after leaving first frame, the current context should back on top level Window - ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : TopWindow = " & $bIsWindowTop & @CRLF) - - ; now lets try to check frame list and using locations as path 'null/0' - ; firstly go to website - _WD_Navigate($sSession, 'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe') - _WD_LoadWait($sSession) - - Local $sResult = _WD_FrameList($sSession, False) - ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 1" & @CRLF) - ConsoleWrite($sResult & @CRLF) - #EndRegion - Example 1 ; from 'https://www.w3schools.com' get frame list as string - - #Region - Example 2 ; from 'https://www.w3schools.com' get frame list as array - Local $aFrameList = _WD_FrameList($sSession, True) - ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 2" & @CRLF) - _ArrayDisplay($aFrameList, 'Example 2 - w3schools.com - get frame list as array', 0, 0, Default, $sArrayHeader) - - #EndRegion - Example 2 ; from 'https://www.w3schools.com' get frame list as array - - #Region - Example 3 ; from 'https://www.w3schools.com' get frame list as array, while current location is "null/0" - ; check if document context location is Top Window - should be as we are after navigation - ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) - - ; change document context location by path 'null/0' - _WD_FrameEnter($sSession, 'null/0') - - ; check if document context location is Top Window - should not be as we enter to frame 'null/0' - ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) - - $aFrameList = _WD_FrameList($sSession, True) - ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 3" & @CRLF) - _ArrayDisplay($aFrameList, 'Example 3 - w3schools.com - relative to "null/0"', 0, 0, Default, $sArrayHeader) - #EndRegion - Example 3 ; from 'https://www.w3schools.com' get frame list as array, while current location is "null/0" - - #Region - Example 4 ; from 'https://stackoverflow.com' get frame list as string - ; go to another website - _WD_Navigate($sSession, 'https://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom') - _WD_LoadWait($sSession) - - $sResult = _WD_FrameList($sSession, False) - ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 4" & @CRLF) - ConsoleWrite($sResult & @CRLF) - #EndRegion - Example 4 ; from 'https://stackoverflow.com' get frame list as string - - #Region - Example 5 ; from 'https://stackoverflow.com' get frame list as array - $aFrameList = _WD_FrameList($sSession, True) - ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 5" & @CRLF) - _ArrayDisplay($aFrameList, 'Example 5 - stackoverflow.com - get frame list as array', 0, 0, Default, $sArrayHeader) - #EndRegion - Example 5 ; from 'https://stackoverflow.com' get frame list as array - - #Region - Example 6v1 ; from 'https://stackoverflow.com' get frame list as array, while is current location is "null/2" - ; check if document context location is Top Window - should be as we are after navigation - ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) - - ; change document context location by path 'null/2' - _WD_FrameEnter($sSession, 'null/2') - - ; check if document context location is Top Window - should not be as we enter to frame 'null/2' - ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) - - $aFrameList = _WD_FrameList($sSession, True) - ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 6v1" & @CRLF) - _ArrayDisplay($aFrameList, 'Example 6v1 - stackoverflow.com - relative to "null/2"', 0, 0, Default, $sArrayHeader) - #EndRegion - Example 6v1 ; from 'https://stackoverflow.com' get frame list as array, while is current location is "null/2" - - #Region - Example 6v2 ; from 'https://stackoverflow.com' get frame list as array, check if it is still relative to the same location as it was before recent _WD_FrameList() was used - still should be "null/2" - ; check if document context location is Top Window - ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) - - $aFrameList = _WD_FrameList($sSession, True) - ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example 6v2" & @CRLF) - _ArrayDisplay($aFrameList, 'Example 6v2 - stackoverflow.com - check if it is still relative to "null/2"', 0, 0, Default, $sArrayHeader) - #EndRegion - Example 6v2 ; from 'https://stackoverflow.com' get frame list as array, check if it is still relative to the same location as it was before recent _WD_FrameList() was used - still should be "null/2" - - #EndRegion - Testing _WD_FrameList() usage - - #Region - Testing element location in frame set and iframe collecion - ; go to website - _WD_Navigate($sSession, 'https://www.tutorialspoint.com/html/html_frames.htm#') - _WD_LoadWait($sSession) - - ; check if document context location is Top Window - ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF) - - MsgBox($MB_TOPMOST, "", 'Before checking location of multiple elements on multiple frames' & @CRLF & 'Try the same example with and without waiting about 30 seconds in order to see that many frames should be fully loaded, and to check the differences') - - $aFrameList = _WD_FrameList($sSession, True, 5000, Default) - ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & " : Example : Testing element location in frame set - after pre-checking list of frames" & @CRLF) - _ArrayDisplay($aFrameList, @ScriptLineNumber & ' Before _WD_FrameListFindElement - www.tutorialspoint.com - get frame list as array', 0, 0, Default, $sArrayHeader) - - Local $aLocationOfElement = _WD_FrameListFindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "li.nav-item[data-bs-original-title='Home Page'] a.nav-link[href='https://www.tutorialspoint.com/index.htm']") - ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : $aLocationOfElement (" & UBound($aLocationOfElement) & ")=" & @CRLF & _ArrayToString($aLocationOfElement) & @CRLF) - _ArrayDisplay($aLocationOfElement, @ScriptLineNumber & ' $aLocationOfElement', 0, 0, Default, $sArrayHeader) - - #EndRegion - Testing element location in frame set and iframe collecion - -#CE - ; Main Loop While 1 Switch GUIGetMsg() @@ -244,63 +146,127 @@ 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 ; ============================================================================== -; HELPER: Demo HTML Content +; MyHook_ Events ; ============================================================================== -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 MyHook_OnMessageReceived($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 + Local $sData = $iSplitPos ? StringTrimLeft($sMsg, $iSplitPos) : "" +;~ Local $aParts + + Switch $sCommand + Case "INIT_READY" + + Case "FRAME_HTML_SOURCE" + $iSplitPos = StringInStr($sData, "|") + Local $sIDX = StringLeft($sData, $iSplitPos - 1) + ConsoleWrite(" >> $sIDX=" & $sIDX & @CRLF) + Local $sHtmlSource = StringTrimLeft($sData, $iSplitPos) + If $sHtmlSource = "null" Then $sHtmlSource = "!! " + Fire_And_Wait($sHtmlSource) + EndSwitch +EndFunc ;==>MyHook_OnMessageReceived Func __Example_Log($s_ScriptLineNumber, $sString, $iError = @error, $iExtended = @extended) ConsoleWrite(@ScriptName & ' SLN=' & $s_ScriptLineNumber & ' [' & $iError & '/' & $iExtended & '] ::: ' & $sString & @CRLF) Return SetError($iError, $iExtended, '') EndFunc ;==>__Example_Log + +; #FUNCTION# ==================================================================================================================== +; Name...........: Fire_And_Wait +; Description....: Synchronizes asynchronous events by waiting for a response or a timeout. +; Syntax.........: Fire_And_Wait([$sData = "" [, $iTimeout = 5000]]) +; Parameters.....: $sData - [Optional] Data string. +; If provided: Acts as a "Signal" (setter) from the Event Handler. +; If empty: Acts as a "Listener" (getter) from the Main Script. +; $iTimeout - [Optional] Maximum wait time in milliseconds (Default is 5000ms). +; Return values..: Success - Returns the stored data string. +; Sets @extended to the duration of the wait in ms. +; Failure - Returns an empty string and sets @error: +; |1 - Timeout reached. +; Author.........: YourName +; Modified.......: 2026-02-23 +; 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 + + ; === Part A: Response (From Event Handler) === + If $sData <> "" Then + $vStoredData = $sData + Return True + EndIf + + ; === Part B: Fire and Wait (From Main Script) === + $vStoredData = "" + $hJobTimer = TimerInit() + + While $vStoredData = "" + If TimerDiff($hJobTimer) > $iTimeout Then + ConsoleWrite("! Fire_And_Wait | TIMEOUT after " & Round(TimerDiff($hJobTimer), 2) & " ms" & @CRLF) + Return SetError(1, 0, "") + EndIf + Sleep(10) + WEnd + + Local $fDuration = TimerDiff($hJobTimer) + Local $vResult = $vStoredData + $vStoredData = "" ; Reset for next use + + ConsoleWrite("> Fire_And_Wait | Duration: " & Round($fDuration, 0) & " ms | Status: SUCCESS" & @CRLF) + + Return SetError(0, Int($fDuration), $vResult) +EndFunc ;==>Fire_And_Wait