@@ -1030,6 +1030,46 @@ Volatile Func _NetWebView2_SilentErrorHandler($oError)
10301030 $oError = 0 ; Explicitly release the COM reference inside the volatile scopeEndFunc
10311031EndFunc ; ==>_NetWebView2_SilentErrorHandler
10321032
1033+ ; #FUNCTION# ====================================================================================================================
1034+ ; Name...........: _WebView2_FrameGetHtmlSource
1035+ ; Description....: Synchronously retrieves the full HTML source of a frame.
1036+ ; Syntax.........: _WebView2_FrameGetHtmlSource($oFrame)
1037+ ; Parameters.....: $oFrame - The WebView2Frame object.
1038+ ; Return values..: Success - Clean HTML string.
1039+ ; Failure - Sets @error and returns empty string.
1040+ ; Author ........: ioa747
1041+ ; Modified ......:
1042+ ; Remarks .......:
1043+ ; Related .......:
1044+ ; Link ..........:
1045+ ; Example .......: No
1046+ ; ===============================================================================================================================
1047+ Func _WebView2_FrameGetHtmlSource($oFrame )
1048+ If Not IsObj ($oFrame ) Then Return SetError (1 , 0 , " " )
1049+
1050+ ; Execute script synchronously
1051+ Local $sRaw = $oFrame .ExecuteScriptWithResult(" document.documentElement.outerHTML" )
1052+
1053+ ; Basic validation
1054+ If $sRaw = " null" Or $sRaw = " " Then Return " "
1055+ If StringLeft ($sRaw , 6 ) = " ERROR:" Then Return SetError (2 , 0 , " " )
1056+
1057+ ; Pre-process: Strip the mandatory JSON quotes BEFORE unescaping.
1058+ ; This prevents the C# Parser from "double-wrapping" the string.
1059+ If StringLeft ($sRaw , 1 ) = ' "' And StringRight ($sRaw , 1 ) = ' "' Then
1060+ $sRaw = StringMid ($sRaw , 2 , StringLen ($sRaw ) - 2 )
1061+ EndIf
1062+
1063+ ; Initialize Parser from the library
1064+ Local $oJson = _NetJson_CreateParser()
1065+ If @error Then Return SetError (3 , 0 , " " )
1066+
1067+ ; Use the Parser's UnescapeString to handle all escapes (\uXXXX, \n, \", etc.)
1068+ Local $sClean = $oJson .UnescapeString($sRaw )
1069+
1070+ Return $sClean
1071+ EndFunc ; ==>_WebView2_FrameGetHtmlSource
1072+
10331073#EndRegion ; New Core Method Wrappers
10341074
10351075#Region ; NetWebView2Lib UDF - _NetJson_* functions
@@ -2354,3 +2394,4 @@ EndFunc ;==>__NetWebView2_Events__OnFrameWebMessageReceived
23542394
23552395#EndRegion ; === NetWebView2Lib UDF === EVENT HANDLERS ===
23562396
2397+
0 commit comments