Skip to content

updating examples#112

Merged
ioa747 merged 1 commit intomainfrom
updating-examples
Feb 25, 2026
Merged

updating examples#112
ioa747 merged 1 commit intomainfrom
updating-examples

Conversation

@ioa747
Copy link
Copy Markdown
Owner

@ioa747 ioa747 commented Feb 24, 2026

018-BasicFramesDemo.au3

Important

Thanks for your effort and interest 💛 in improving the project. It's very appreciated.

Description

adjust the 018-BasicFramesDemo.au3 example

🔗 Linked GitHub Issues

#91

Closes #<number>

📋 What is the current behavior?

🚀 What is the new behavior?


Type of changes

  • 🪲 Bugfix (change which fixes an issue)
  • ⭐ New Feature (change which adds functionality)
  • ⭐ New Example (this PR adds a new example)
  • 🔒 Security fix (change which improves security)
  • 🔮 Code style update (formatting, renaming)
  • 🔨 Refactoring (code optimization without functional change)
  • 📚 Documentation (updates to README or docs)
  • ⚙️ Build or CI related changes
  • 🧿 Other type * appropriate method name

Breaking changes 🔥

  • Yes
  • No

How and where was this tested?

🖥️ Describe where you tested your changes

System:

  • Windows 11 (x64)
  • Windows 10 (x64)
  • Windows 10 (x86)
  • Windows Server ......

Context:

  • COM object NetJson.Parser
  • COM object NetWebView2.Manager - WebView2
  • COM object NetWebView2.Manager - Bridge
  • UDF - NetWebView2Lib.au3
  • Examples: 018-BasicFramesDemo.au3
  • with ...

🔬 Describe how you tested your changes

  • Manually tested in system and context shown above
  • Ran automatic tests (unit tests, integration tests, etc.)
  • Other ways

Checklist

  • I have read and understood the available contributing guidelines.
  • I have ensured my code follows the available code conventions.
  • I have reviewed my changes.
  • I have made corresponding changes to the documentation (if applicable).
  • I have added/updated necessary tests to cover the changes (if applicable).
  • I have checked for potential security implications.

Additional context

Screenshots

Note to reviewers

018-BasicFramesDemo.au3
Copy link
Copy Markdown
Contributor

@mlipok mlipok left a comment

Choose a reason for hiding this comment

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

Ok It works.
Maybe we find better way later

$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

@ioa747 ioa747 merged commit d24323b into main Feb 25, 2026
@ioa747 ioa747 deleted the updating-examples branch February 25, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants