1+ #Region ; *** Dynamically added Include files ***
2+ #include < IE.au3> ; added:01/18/26 22:09:02
3+ #EndRegion ; *** Dynamically added Include files ***
14; ~ #AutoIt3Wrapper_UseX64=y
25#AutoIt3Wrapper_UseX64= n
36#AutoIt3Wrapper_Run_AU3Check= Y
@@ -48,26 +51,10 @@ Func _Example()
4851 $_g_oWeb = $oWebV2M
4952 If @error Then Return SetError (@error , @extended , $oWebV2M )
5053
51- ObjEvent ($oWebV2M , " __NetWebView2_WebEvents_" , " IWebViewEvents" )
52-
5354 ; Important: Pass $hGUI in parentheses to maintain Pointer type for COM
5455 Local $sProfileDirectory = @TempDir & " \NetWebView2Lib-UserDataFolder"
55- $oWebV2M .Initialize($hGUI , $sProfileDirectory , 0 , 50 , 500 , 600 )
56-
57- ; Initialize JavaScript Bridge
58- Local $oJS = $oWebV2M .GetBridge()
59- ObjEvent ($oJS , " __NetWebView2_JSEvents_" , " IBridgeEvents" )
60-
61- ; Wait for WebView2 to be ready
62- Do
63- Sleep (50 )
64- Until $oWebV2M .IsReady
6556
66- ; WebView2 Configuration
67- $oWebV2M .SetAutoResize(True ) ; Using SetAutoResize(True) to skip WM_SIZE
68- $oWebV2M .BackColor = " 0x2B2B2B"
69- $oWebV2M .AreDevToolsEnabled = True ; Allow F12
70- $oWebV2M .ZoomFactor = 1.2
57+ _NetWebView2_Initialize($oWebV2M , $hGUI , $sProfileDirectory , 0 , 50 , 0 , 0 , True , True , True , 1.2 , " 0x2B2B2B" )
7158
7259 ; Initial JSON display
7360 Local $sMyJson = ' {"Game": "Witcher 3", "ID": 1, "Meta": {"Developer": "CD Projekt", "Year": 2015 }, "Tags": ["RPG", "Open World"]}'
@@ -78,6 +65,9 @@ Func _Example()
7865
7966 Local $sLastSearch = " "
8067
68+ ; Initialize JavaScript Bridge
69+ Local $oJSBridge = _NetWebView2_GetBridge($oWebV2M )
70+
8171 ; Main Application Loop
8272 While 1
8373 Switch GUIGetMsg ()
@@ -86,11 +76,11 @@ Func _Example()
8676
8777 Case $idExpand
8878 ; Call JavaScript expand method on the global tree object
89- $oWebV2M .ExecuteScript( " if(window.tree) window.tree.expand();" )
79+ _NetWebView2_ExecuteScript( $oWebV2M , " if(window.tree) window.tree.expand();" )
9080
9181 Case $idCollapse
9282 ; Call JavaScript collapse method
93- $oWebV2M .ExecuteScript( " if(window.tree) window.tree.collapse();" )
83+ _NetWebView2_ExecuteScript( $oWebV2M , " if(window.tree) window.tree.collapse();" )
9484
9585 Case $idFind
9686 Local $sInput = InputBox (" JSON Search" , " Enter key or value:" , $sLastSearch , " " , 200 , 130 , Default , Default , Default , $hGUI )
@@ -112,11 +102,7 @@ Func _Example()
112102 EndSwitch
113103 WEnd
114104
115- If IsObj ($oWebV2M ) Then $oWebV2M .Cleanup()
116- $oWebV2M = 0
117- $oJS = 0
118- _NetWebView2_ShutDown()
119-
105+ _NetWebView2_CleanUp($oWebV2M , $oJSBridge )
120106EndFunc ; ==>Main
121107
122108#Region ; === UTILS ===
@@ -127,14 +113,14 @@ EndFunc ;==>Main
127113; Author.........: summerstyle (https://github.com/summerstyle/jsonTreeViewer)
128114; Integration....: Adapted for AutoIt WebView2
129115; ===============================================================================================================================
130- Func _Web_jsonTree(ByRef $oWebV2M , $sJson )
116+ Func _Web_jsonTree(ByRef $oWebV2M , $sJavaScripton )
131117 ; 1. Prepare JSON (Minify to prevent script errors from line breaks)
132- Local $oJSON = _NetJson_CreateParser($sJson )
118+ Local $oJSON = _NetJson_CreateParser($sJavaScripton )
133119; ~ _NetWebView2_ObjName_FlagsValue($oJSON)
134- $sJson = $oJSON .GetMinifiedJson()
120+ $sJavaScripton = $oJSON .GetMinifiedJson()
135121
136122 ; 2. Load local library files
137- Local $sJsLib = FileRead (@ScriptDir & " .\JS_Lib\jsonTree.js" )
123+ Local $sJavaScriptLib = FileRead (@ScriptDir & " .\JS_Lib\jsonTree.js" )
138124 Local $sCssLib = FileRead (@ScriptDir & " .\JS_Lib\jsonTreeDark.css" )
139125
140126 ; 3. Build HTML with embedded Logic
@@ -146,10 +132,10 @@ Func _Web_jsonTree(ByRef $oWebV2M, $sJson)
146132 " Powered by <a href='https://github.com/summerstyle/jsonTreeViewer' style='color:#777; text-decoration:none;'>jsonTree</a>" & _
147133 " </div>" & _
148134 " <script>" & @CRLF & _
149- $sJsLib & @CRLF & _
135+ $sJavaScriptLib & @CRLF & _
150136 " ;" & @CRLF & _ ; Ensure library/code separation
151137 " try {" & @CRLF & _
152- " var data = " & $sJson & " ;" & @CRLF & _
138+ " var data = " & $sJavaScripton & " ;" & @CRLF & _
153139 " var container = document.getElementById('tree-container');" & @CRLF & _
154140 " if (typeof jsonTree !== 'undefined') {" & @CRLF & _
155141 " window.tree = jsonTree.create(data, container);" & @CRLF & _ ; Assign to window for global access
@@ -185,7 +171,7 @@ EndFunc ;==>_Web_jsonTree
185171; Parameters.....: $sSearch - The string to find
186172; ===============================================================================================================================
187173Func _Web_jsonTreeFind(ByRef $oWebV2M , $sSearch , $bNext = False )
188- Local $sJS = _
174+ Local $sJavaScript = _
189175 " var term = '" & $sSearch & " '.toLowerCase();" & _
190176 " if (!window.searchIndices || window.lastTerm !== term) {" & _
191177 " window.searchIndices = [];" & _
@@ -229,9 +215,9 @@ Func _Web_jsonTreeFind(ByRef $oWebV2M, $sSearch, $bNext = False)
229215 " }"
230216
231217 ; Replace the AutoIt variable $bNext with JS boolean
232- ; ~ $sJS = StringReplace($sJS , "$bNext", ($bNext ? "true" : "false"))
233- ConsoleWrite (" $sJS =" & $sJS & @CRLF )
234- $oWebV2M .ExecuteScript( $sJS )
218+ ; ~ $sJavaScript = StringReplace($sJavaScript , "$bNext", ($bNext ? "true" : "false"))
219+ ConsoleWrite (" $sJavaScript =" & $sJavaScript & @CRLF )
220+ _NetWebView2_ExecuteScript( $oWebV2M , $sJavaScript )
235221EndFunc ; ==>_Web_jsonTreeFind
236222#EndRegion ; === UTILS ===
237223#EndRegion ; UDF TESTING EXAMPLE
0 commit comments