Skip to content

Commit 1b5685b

Browse files
authored
Merge pull request #111 from ioa747/011-TwinWebView.au3
011-TwinWebView.au3
2 parents 1784fbf + 904af74 commit 1b5685b

3 files changed

Lines changed: 113 additions & 211 deletions

File tree

examples/011-TwinWebView.au3

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
#WIP - this Example is imported from 1.5.0 UDF - and is in "WORK IN PROGRESS" state
2-
31
;----------------------------------------------------------------------------------------
4-
; Title...........: Active_Help.au3
5-
; Description.....: Multi-WebView2 interface for synchronized side-by-side search.
6-
; AutoIt Version..: 3.3.18.0 Author: ioa747 Script Version: 0.1
7-
; Note............: Tested in Windows 11 Pro 25H2 Date: 25/12/2025
8-
;
92
; USAGE INSTRUCTIONS:
10-
; 1. The Right Browser (Web2) loads the AutoIt Forum.
11-
; 2. Use your mouse to select (highlight) any text or keyword on the Right Browser.
12-
; 3. A floating button "🔍 Search Google" will appear near your selection.
13-
; 4. Click the button to automatically perform a Google Search on the Left Browser (Web1).
14-
; 5. The search is automatically restricted to the current domain (site:domain.com).
3+
; 1. In the Right Browser (Web2) Use your mouse to select (highlight) any text or keyword on the Right Browser.
4+
; 2. A floating button "🔍 Search Google" will appear near your selection.
5+
; 3. Click the button to automatically perform a Google Search on the Left Browser (Web1).
6+
; 4. The search is automatically restricted to the current domain (site:domain.com).
157
;----------------------------------------------------------------------------------------
168
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
179
#AutoIt3Wrapper_UseX64=y
@@ -22,6 +14,8 @@
2214
#include "..\NetWebView2Lib.au3"
2315
#include "_WV2_ExtensionPicker.au3"
2416

17+
; 011-TwinWebView.au3
18+
2519
OnAutoItExitRegister(_ExitApp)
2620

2721
; Global Objects & Handles
@@ -67,7 +61,7 @@ Func _MainGUI() ; Creates the primary application window and starts the message
6761
Case $GUI_EVENT_CLOSE
6862
Exit
6963

70-
; ~~~ Web1 Controls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64+
; ~~~ Web1 Controls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7165
Case $Bar1.ClearBrowserData
7266
If MsgBox(36, "Confirm", "Do you want to clear your browsing data for Web1?") = 6 Then
7367
If IsObj($oWeb1) Then $oWeb1.ClearBrowserData()
@@ -107,7 +101,7 @@ Func _MainGUI() ; Creates the primary application window and starts the message
107101
Case $Bar1.ctx_About
108102
_Web_Status($oWeb1)
109103

110-
; ~~~ Web2 Controls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104+
; ~~~ Web2 Controls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111105
Case $Bar2.ClearBrowserData
112106
If MsgBox(36, "Confirm", "Do you want to clear your browsing data for Web2?") = 6 Then
113107
If IsObj($oWeb2) Then $oWeb2.ClearBrowserData()
@@ -147,7 +141,7 @@ Func _MainGUI() ; Creates the primary application window and starts the message
147141
Case $Bar2.ctx_About
148142
_Web_Status($oWeb2)
149143

150-
; ~~~ Dragging Handler ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144+
; ~~~ Dragging Handler ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151145
Case $GUI_EVENT_PRIMARYDOWN
152146
_DragAdjust()
153147

@@ -192,15 +186,16 @@ EndFunc ;==>_InitBrowsers
192186
;--------------------------------------------------------------------------------------------------------------------------------
193187
; BROWSER 1 EVENTS (Search Results Engine)
194188
;--------------------------------------------------------------------------------------------------------------------------------
195-
Func Web1_OnMessageReceived($sMsg) ; [Web1]
196-
ConsoleWrite("+> [Web1]: " & $sMsg & @CRLF)
189+
Func Web1_OnMessageReceived($oWebV2M, $hGUI, $sMsg) ; [Web1]
190+
#forceref $oWebV2M, $hGUI
191+
ConsoleWrite("> [Web1]: " & $sMsg & @CRLF)
197192
Local $aParts = StringSplit($sMsg, "|")
198193
Local $sCommand = StringStripWS($aParts[1], 3)
199194
Switch $sCommand
200195
Case "INIT_READY"
201-
$oWeb1.SetContextMenuEnabled(True)
196+
$oWebV2M.SetContextMenuEnabled(True)
202197
;COM_TEST
203-
$oWeb1.ExecuteScript('window.chrome.webview.postMessage(JSON.stringify({ "type": "COM_TEST", "status": "OK" }));')
198+
$oWebV2M.ExecuteScript('window.chrome.webview.postMessage(JSON.stringify({ "type": "COM_TEST", "status": "OK" }));')
204199

205200
Case "NAV_COMPLETED"
206201
; Responsive tweaks could be applied here if needed
@@ -209,21 +204,23 @@ Func Web1_OnMessageReceived($sMsg) ; [Web1]
209204
If $aParts[0] > 1 Then
210205
GUICtrlSetData($Bar1.Address, $aParts[2])
211206
GUICtrlSendMsg($Bar1.Address, $EM_SETSEL, 0, 0)
212-
$oWeb1.WebViewSetFocus() ; We give focus to the browser
207+
$oWebV2M.WebViewSetFocus() ; We give focus to the browser
213208
EndIf
214209

215210
EndSwitch
216211
EndFunc ;==>Web1_OnMessageReceived
217212

218-
Func Bridge1_OnMessageReceived($sMsg) ; [Bridge1 JS]
219-
ConsoleWrite("+> [Bridge1 JS]: " & $sMsg & @CRLF)
213+
Func Bridge1_OnMessageReceived($oWebV2M, $hGUI, $sMsg) ; [Bridge1 JS]
214+
#forceref $oWebV2M, $hGUI
215+
ConsoleWrite("> [Bridge1 JS]: " & $sMsg & @CRLF)
220216
EndFunc ;==>Bridge1_OnMessageReceived
221217

222218
;--------------------------------------------------------------------------------------------------------------------------------
223219
; BROWSER 2 EVENTS (Main Navigation & Selection Source)
224220
;--------------------------------------------------------------------------------------------------------------------------------
225-
Func Web2_OnMessageReceived($sMsg) ; [Web2]
226-
ConsoleWrite("+> [Web2]: " & $sMsg & @CRLF)
221+
Func Web2_OnMessageReceived($oWebV2M, $hGUI, $sMsg) ; [Web2]
222+
#forceref $oWebV2M, $hGUI
223+
ConsoleWrite("> [Web2]: " & $sMsg & @CRLF)
227224
Local $aParts = StringSplit($sMsg, "|")
228225
Local $sCommand = StringStripWS($aParts[1], 3)
229226
Switch $sCommand
@@ -234,7 +231,7 @@ Func Web2_OnMessageReceived($sMsg) ; [Web2]
234231

235232
Case "NAV_COMPLETED"
236233
; Re-inject the selection script every time a new page is loaded
237-
ConsoleWrite("> Web2 Navigation Completed. Injecting Selection Script..." & @CRLF)
234+
ConsoleWrite(">>> Web2 Navigation Completed. Injecting Selection Script..." & @CRLF)
238235
$oWeb2.ExecuteScript(JS_getSelection())
239236

240237
Case "URL_CHANGED"
@@ -246,8 +243,9 @@ Func Web2_OnMessageReceived($sMsg) ; [Web2]
246243
EndSwitch
247244
EndFunc ;==>Web2_OnMessageReceived
248245

249-
Func Bridge2_OnMessageReceived($sMsg) ; [Bridge2 JS]
250-
ConsoleWrite("+> [Bridge2 JS]: " & $sMsg & @CRLF)
246+
Func Bridge2_OnMessageReceived($oWebV2M, $hGUI, $sMsg) ; [Bridge2 JS]
247+
#forceref $oWebV2M, $hGUI
248+
ConsoleWrite("> [Bridge2 JS]: " & $sMsg & @CRLF)
251249

252250
Local $aParts = StringSplit($sMsg, "|")
253251
If $aParts[0] < 2 Then Return
@@ -259,7 +257,7 @@ Func Bridge2_OnMessageReceived($sMsg) ; [Bridge2 JS]
259257
If IsObj($oWeb1) Then
260258
Local $sSearchText = StringReplace(StringStripWS($aParts[2], 3), " ", "+")
261259
Local $sDomain2 = StringStripWS($aParts[3], 3)
262-
ConsoleWrite("!> Performing search on Web1: " & $sSearchText & " @ " & $sDomain2 & @CRLF)
260+
ConsoleWrite(">>> Performing search on Web1: " & $sSearchText & " @ " & $sDomain2 & @CRLF)
263261

264262
; Construct Google search URL with 'site:' operator
265263
Local $sURL = "https://www.google.com/search?q=" & $sSearchText & "+site:" & $sDomain2

0 commit comments

Comments
 (0)