Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/018-BasicFramesDemo.au3
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ Func _NetWebView2_GetAllFrames_AsArray($oWebV2M)
$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_NAME] = $oFrame.Name
$aFrames[$IDX_Frame][$FRAME_URL] = $oFrame.Source
$aFrames[$IDX_Frame][$FRAME_DESTROYED] = $oFrame.IsDestroyed()
$aFrames[$IDX_Frame][$FRAME_HTML] = $oWebV2M.GetFrameHtmlSource($IDX_Frame)
$aFrames[$IDX_Frame][$FRAME_HTML] = Fire_And_Wait($oWebV2M.GetFrameHtmlSource($IDX_Frame), 5000)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like the Fire_And_Wait() solution
I think I need to find another solution.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to move the logic (WaitAndGetResult) to the C# side and handle the asynchronous delay internally.?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Lets stay with what we have.

Copy link
Copy Markdown
Owner Author

@ioa747 ioa747 Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively

with using the new frame method

⚡ExecuteScriptWithResult

Type: string (Synchronous/Blocking)
Description: Executes JavaScript in the frame and waits for the result (Thread-Safe).
object.ExecuteScriptWithResult(Script As String)

to fire "document.documentElement.outerHTML"

; #FUNCTION# ====================================================================================================================
; Name...........: _WebView2_GetFrameHtmlSource
; Description....: Synchronously retrieves the full HTML source of a frame and unescapes it.
; Syntax.........: _WebView2_GetFrameHtmlSource($oFrame)
; Parameters.....: $oFrame - The WebView2Frame object.
; Return values..: Success - Clean HTML string.
;                  Failure - Sets @error and returns empty string.
; ===============================================================================================================================
Func _WebView2_GetFrameHtmlSource($oFrame)
	If Not IsObj($oFrame) Then Return SetError(1, 0, "$oFrame is not a valid object")

	; Execute script synchronously
	Local $sRaw = $oFrame.ExecuteScriptWithResult("document.documentElement.outerHTML")

	; Basic validation
	If $sRaw = "null" Or $sRaw = "" Then Return ""
	If StringLeft($sRaw, 6) = "ERROR:" Then Return SetError(2, 0, $sRaw)

	; Pre-process: Strip the mandatory JSON quotes BEFORE unescaping.
	; This prevents the C# Parser from "double-wrapping" the string.
	If StringLeft($sRaw, 1) = '"' And StringRight($sRaw, 1) = '"' Then
		$sRaw = StringMid($sRaw, 2, StringLen($sRaw) - 2)
	EndIf

	; Initialize Parser from the library
	Local $oJson = _NetJson_CreateParser()
	If @error Then Return SetError(3, 0, "Failed to create JsonParser")

	; Use the Parser's UnescapeString to handle all escapes (\uXXXX, \n, \", etc.)
	Local $sClean = $oJson.UnescapeString($sRaw)

	Return $sClean
EndFunc   ;==>_WebView2_GetFrameHtmlSource

Next
Return $aFrames
EndFunc ;==>_NetWebView2_GetAllFrames_AsArray
Expand Down