Skip to content
Open
Show file tree
Hide file tree
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
1,025 changes: 565 additions & 460 deletions NetWebView2Lib.au3

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion examples/002-Html_Gui.au3
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ Func _Create_Form(ByRef $oWebV2M, ByRef $oBridge)
$oBridge = _NetWebView2_GetBridge($oWebV2M, "__USER_Events_Bridge_")
#forceref $oBridge

GUISetState(@SW_SHOW, $hGUI)

Local $sHTML = "<html><head><meta charset='UTF-8'><style>:" & __FormCSS() & "</style></head><body>" & __FormHTML() & "</body></html>"
_NetWebView2_NavigateToString($oWebV2M, $sHTML, $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, "", 5000)
GUISetState(@SW_SHOW, $hGUI)
ConsoleWrite("After: _NetWebView2_NavigateToString()" & @CRLF)

EndFunc ;==>_Create_Form

; Injects a temporary notification box into the web page
Expand Down
11 changes: 3 additions & 8 deletions examples/003-Multi-Basic.au3
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ Func _Main()
Local $hMainGUI = GUICreate("Multi-WebView2 v2.0.0 Standard", 1000, 600, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
GUISetState(@SW_SHOW, $hMainGUI)

ConsoleWrite("! --- BROWSER 1 ---" & @CRLF)
ConsoleWrite("--- BROWSER 1 ---" & @CRLF)
Local $oWeb_1, $oBridge_1, $h_WebWindow_1, $sEventPrfix_1 = "__UserEventHandler_Web1_", $sProfile_1 = @TempDir & "\User_A", $s_AddBrowserArgs_1 = ""
_NetWebView2_BrowserSetupWrapper($hMainGUI, $oWeb_1, $sEventPrfix_1, $sProfile_1, $oBridge_1, $h_WebWindow_1, 10, 10, 480, 500, $s_AddBrowserArgs_1)
ConsoleWrite("! $h_WebWindow_1 = " & $h_WebWindow_1 & @CRLF)
ConsoleWrite("! BrowserWindowHandle = " & $oWeb_1.BrowserWindowHandle & @CRLF)
_NetWebView2_NavigateToString($oWeb_1, _GetDemoHTML("Browser 1 Content"))

ConsoleWrite("! --- BROWSER 2 ---" & @CRLF)
ConsoleWrite("--- BROWSER 2 ---" & @CRLF)
Local $oWeb_2, $oBridge_2, $h_WebWindow_2, $sEventPrfix_2 = "__UserEventHandler_Web2_", $sProfile_2 = @TempDir & "\User_B", $s_AddBrowserArgs_2 = ""
_NetWebView2_BrowserSetupWrapper($hMainGUI, $oWeb_2, $sEventPrfix_2, $sProfile_2, $oBridge_2, $h_WebWindow_2, 510, 10, 480, 500, $s_AddBrowserArgs_2)
ConsoleWrite("! $h_WebWindow_2 = " & $h_WebWindow_2 & @CRLF)
ConsoleWrite("! BrowserWindowHandle = " & $oWeb_2.BrowserWindowHandle & @CRLF)
_NetWebView2_NavigateToString($oWeb_2, _GetDemoHTML("Browser 2 Content"))

__Example_Log(@ScriptLineNumber, "END - close window to exit" & @CRLF)
Expand All @@ -43,7 +39,7 @@ Func _Main()

; CleanUp
_NetWebView2_CleanUp($oWeb_1, $oBridge_1)
;~ _NetWebView2_CleanUp($oWeb_2, $oBridge_2)
_NetWebView2_CleanUp($oWeb_2, $oBridge_2)
EndFunc ;==>_Main

; ==============================================================================
Expand Down Expand Up @@ -146,4 +142,3 @@ Func __Example_Log($s_ScriptLineNumber, $sString, $iError = @error, $iExtended =
ConsoleWrite(@ScriptName & ' SLN=' & $s_ScriptLineNumber & ' [' & $iError & '/' & $iExtended & '] ::: ' & $sString & @CRLF)
Return SetError($iError, $iExtended, '')
EndFunc ;==>__Example_Log

3 changes: 2 additions & 1 deletion examples/006-DownloadDemo.au3
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ Func _Example()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ConsoleWrite('$GUI_EVENT_CLOSE fired' & @CRLF)
ExitLoop
EndSwitch
WEnd

_NetWebView2_CleanUp($oWebV2M, $oJSBridge)
GUIDelete($hGUI)
#EndRegion ; GUI Loop

_NetWebView2_CleanUp($oWebV2M, $oJSBridge)
EndFunc ;==>_Example

; Advise using 'Volatile' for Event Handlers to ensure the WebView2 COM thread can interrupt the main script safely.
Expand Down
7 changes: 5 additions & 2 deletions examples/007-HTTP_StatusCodeTracking.au3
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Func WebEvents_OnMessageReceived($oWebV2M, $hGUI, $sMsg)
ConsoleWrite("- _WinAPI_GetClientWidth($hWnd)=" & _WinAPI_GetClientWidth($hWnd) & @CRLF) ; working
; End part of the $hGUI handle explanation }


ConsoleWrite(">>> [WebEvents]: " & (StringLen($sMsg) > 150 ? StringLeft($sMsg, 150) & "..." : $sMsg) & @CRLF)
Local $iSplitPos = StringInStr($sMsg, "|")
Local $sCommand = $iSplitPos ? StringStripWS(StringLeft($sMsg, $iSplitPos - 1), 3) : $sMsg
Expand Down Expand Up @@ -134,7 +133,7 @@ Func WebEvents_OnWebResourceResponseReceived($oWebV2M, $hGUI, $iStatusCode, $sRe
Local $sLog = StringFormat("! [HTTP %d] | %s | URL: %s", $iStatusCode, $sReasonPhrase, $sRequestUrl)
ConsoleWrite($sLog & @CRLF)

Local $oGuard = ObjEvent("AutoIt.Error", "__NetWebView2_fake_COMErrFunc")
Local $oGuard = ObjEvent("AutoIt.Error", __NetWebView2_fake_COMErrFunc)
#forceref $oGuard

; Management example:
Expand All @@ -157,3 +156,7 @@ EndFunc ;==>WebEvents_OnWebResourceResponseReceived

#EndRegion ; === EVENT HANDLERS ===

Func __Example_Log($s_ScriptLineNumber, $sString, $iError = @error, $iExtended = @extended)
ConsoleWrite(@ScriptName & ' SLN=' & $s_ScriptLineNumber & ' [' & $iError & '/' & $iExtended & '] ::: ' & $sString & @CRLF)
Return SetError($iError, $iExtended, '')
EndFunc ;==>__Example_Log
13 changes: 10 additions & 3 deletions examples/014-pdfJS-Static_PDF_Viewer.au3
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ⚠️ to make this work, download pdfJS library from https://mozilla.github.io/pdf.js/
; for example:
; https://github.com/mozilla/pdf.js/releases/download/v5.4.624/pdfjs-5.4.624-dist.zip
; https://github.com/mozilla/pdf.js/releases/download/v5.6.205/pdfjs-5.6.205-dist.zip
; and unzip to: @ScriptDir & "\JS_Lib\pdfjs\"
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -57,9 +57,10 @@ Func _Example()

; navigate to the page
Local $sFileName = "invoice-plugin-sample.pdf"
Local $sRegExp_Title = "(?i) - " & $sFileName
Local $sRegExp_Title = "(?i).*?" & $sFileName

__SetupStaticPDF($oWeb, @ScriptDir & "\" & $sFileName, $sRegExp_Title, True, False, True)
ConsoleWrite("After __SetupStaticPDF() RegExp_Title=" & $sRegExp_Title & @CRLF)

#Region ; now we can call the script directly from the JavaScript library "NetWebView2Lib_pdfjs_Tools.js" - some pdfjs magic stuff ;)
Local $s_JavaScript_snipp = ''
Expand Down Expand Up @@ -130,15 +131,21 @@ Func _Example()
_NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE0_FIREANDFORGET)
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "After:" & @CRLF & $s_JavaScript_snipp)

$sRegExp_Title = "(?i).*?" & "dummy.pdf"
$s_JavaScript_snipp = 'PDFViewerApplication.open({ url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" });'
_NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE0_FIREANDFORGET)
_NetWebView2_LoadWait($oWeb, $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, $sRegExp_Title, 5000)
ConsoleWrite("After _NetWebView2_LoadWait() RegExp_Title=" & $sRegExp_Title & @CRLF)
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "After:" & @CRLF & $s_JavaScript_snipp)

;~ $s_JavaScript_snipp = FileRead(@ScriptDir & '\JS_Lib\PDFViewerApplicationEvents.js')
;~ _NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE2_RESULT)

$sRegExp_Title = "(?i).*? - " & "PDF32000_2008.pdf"
$s_JavaScript_snipp = 'PDFViewerApplication.open({ url: "https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf" });'
_NetWebView2_ExecuteScript($oWeb, $s_JavaScript_snipp, $NETWEBVIEW2_EXECUTEJS_MODE0_FIREANDFORGET)
_NetWebView2_LoadWait($oWeb, $NETWEBVIEW2_MESSAGE__TITLE_CHANGED, $sRegExp_Title, 5000)
ConsoleWrite("After _NetWebView2_LoadWait() RegExp_Title=" & $sRegExp_Title & @CRLF)
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "After:" & @CRLF & $s_JavaScript_snipp)

#EndRegion ; now we can call the script directly from the JavaScript library "NetWebView2Lib_pdfjs_Tools.js" - some pdfjs magic stuff ;)
Expand All @@ -151,8 +158,8 @@ Func _Example()
EndSwitch
WEnd

GUIDelete($hGUI)
_NetWebView2_CleanUp($oWeb, $oBridge)
GUIDelete($hGUI)
EndFunc ;==>_Example

; Handles custom messages from JavaScript (window.chrome.webview.postMessage)
Expand Down
2 changes: 1 addition & 1 deletion examples/020-NavigationInterception.au3
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Func _MainGUI()
EndSwitch
WEnd

GUIDelete($hGUI)
_NetWebView2_CleanUp($oWebV2M, $hGUI)
GUIDelete($hGUI)
Exit
EndFunc ;==>_MainGUI

Expand Down