Skip to content

Commit a10691b

Browse files
authored
Update NetWebView2Lib.au3
1 parent 0c92729 commit a10691b

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

NetWebView2Lib.au3

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Func _NetWebView2_CreateManager($sUserAgent = '', $s_fnEventPrefix = "", $s_AddB
9999
;~ __NetWebView2_ObjName_FlagsValue($oWebV2M)
100100
If @error Then __NetWebView2_Log(@ScriptLineNumber, "! [NetWebView2Lib]: Manager Creation ERROR", 1)
101101
If $sUserAgent Then $oWebV2M.SetUserAgent($sUserAgent)
102-
If $s_AddBrowserArgs Then $oWebV2M.AdditionalBrowserArguments = $s_AddBrowserArgs
102+
If $s_AddBrowserArgs Then $oWebV2M.AdditionalBrowserArguments= $s_AddBrowserArgs
103103
If $s_fnEventPrefix Then $_g_sNetWebView2_User_WebViewEvents = $s_fnEventPrefix
104104
ObjEvent($oWebV2M, "__NetWebView2_WebViewEvents__", "IWebViewEvents")
105105
Return SetError(@error, @extended, $oWebV2M)
@@ -225,7 +225,7 @@ Func _NetWebView2_LoadWait(ByRef $oWebV2M, $iStatus = $WEBVIEW2__NAVSTATUS__READ
225225
; Wait for WebView2 to be ready
226226
While Sleep(10)
227227
If $oWebV2M.IsReady Then
228-
If $iStatus == $WEBVIEW2__NAVSTATUS__READY Or __NetWebView2_NavigationStatus() >= $iStatus Then
228+
If __NetWebView2_NavigationStatus() >= $iStatus Then
229229
ExitLoop
230230
EndIf
231231
EndIf
@@ -287,10 +287,10 @@ EndFunc ;==>_NetWebView2_GetSource
287287
; Example .......: No
288288
; ===============================================================================================================================
289289
Func _NetWebView2_NavigateToString(ByRef $oWebV2M, $s_HTML, $b_LoadWait = True)
290+
Local Const $s_Prefix = "[_NetWebView2_NavigateToString]:" & " HTML Size:" & StringLen($s_HTML) & " LoadWait:" & $b_LoadWait
290291
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler
291292
#forceref $oMyError
292293

293-
Local Const $s_Prefix = "[_NetWebView2_PrintToPdfStream]:" & " HTML Size:" & StringLen($s_HTML) & " LoadWait:" & $b_LoadWait
294294
Local $iNavigation = $oWebV2M.NavigateToString($s_HTML)
295295
If @error Then Return SetError(@error, @extended, $iNavigation)
296296

@@ -302,24 +302,29 @@ EndFunc ;==>_NetWebView2_NavigateToString
302302
; #FUNCTION# ====================================================================================================================
303303
; Name ..........: _NetWebView2_ExportPageData
304304
; Description ...:
305-
; Syntax ........: _NetWebView2_ExportPageData(ByRef $oWebV2M, $sFormat, $sFilePath)
305+
; Syntax ........: _NetWebView2_ExportPageData(ByRef $oWebV2M, $iFormat[, $sFilePath = ''])
306306
; Parameters ....: $oWebV2M - [in/out] an object.
307-
; $sFormat - a string value.
308-
; $sFilePath - a string value.
309-
; Return values .: None
307+
; $iFormat - a string value. 0 HTML only, 1 MHTML Snapshot
308+
; $sFilePath - [optional] a string value. Default is '' which mean make Base64 as a result instead write to file
309+
; Return values .: Success - Depends on $sFilePath String with Base64 encoded binary content of the PDF or "SUCCESS: File saved to ...."
310+
; Failure - string with error description "ERROR: ........." and set @error to 1
310311
; Author ........: mLipok
311312
; Modified ......:
312313
; Remarks .......:
313314
; Related .......:
314315
; Link ..........:
315316
; Example .......: No
316317
; ===============================================================================================================================
317-
Func _NetWebView2_ExportPageData(ByRef $oWebV2M, $sFormat, $sFilePath)
318+
Func _NetWebView2_ExportPageData(ByRef $oWebV2M, $iFormat, $sFilePath = '')
319+
#TODO $sParameters - search for => "name": "captureSnapshot" ; https://github.com/ChromeDevTools/devtools-protocol/blob/master/json/browser_protocol.json
320+
#TODO https://github.com/ioa747/NetWebView2Lib/issues/15
321+
#TODO https://github.com/ioa747/NetWebView2Lib/pull/16
322+
323+
Local Const $s_Prefix = "[_NetWebView2_ExportPageData]:" & " Format:" & $iFormat & " FilePath:" & $sFilePath
318324
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler
319325
#forceref $oMyError
320326

321-
Local Const $s_Prefix = "[_NetWebView2_PrintToPdfStream]:" & " Format:" & $sFormat & " FilePath:" & $sFilePath
322-
Local $s_Result = $oWebV2M.ExportPageData($sFormat, $sFilePath)
327+
Local $s_Result = $oWebV2M.ExportPageData($iFormat, $sFilePath)
323328
If StringInStr($s_Result, 'ERROR:') Then SetError(1)
324329
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " RESULT:" & ((@error) ? ($s_Result) : ("SUCCESS")), 1)
325330
Return SetError(@error, @extended, $s_Result)
@@ -328,26 +333,26 @@ EndFunc ;==>_NetWebView2_ExportPageData
328333
; #FUNCTION# ====================================================================================================================
329334
; Name ..........: _NetWebView2_PrintToPdfStream
330335
; Description ...:
331-
; Syntax ........: _NetWebView2_PrintToPdfStream(ByRef $oWebV2M, $sFormat, $sFilePath)
336+
; Syntax ........: _NetWebView2_PrintToPdfStream(ByRef $oWebV2M)
332337
; Parameters ....: $oWebV2M - [in/out] an object.
333-
; $sFormat - a string value.
334-
; $sFilePath - a string value.
335-
; Return values .: None
338+
; Return values .: Success - String with Base64 encoded binary content of the PDF
339+
; Failure - string with error description "ERROR: ........." and set @error to 1
336340
; Author ........: mLipok
337341
; Modified ......:
338342
; Remarks .......:
339343
; Related .......:
340344
; Link ..........:
341345
; Example .......: No
342346
; ===============================================================================================================================
343-
Func _NetWebView2_PrintToPdfStream(ByRef $oWebV2M, $sFormat, $sFilePath)
347+
Func _NetWebView2_PrintToPdfStream(ByRef $oWebV2M)
348+
Local Const $s_Prefix = "[_NetWebView2_PrintToPdfStream]:"
344349
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler
345350
#forceref $oMyError
346351

347-
Local Const $s_Prefix = "[_NetWebView2_PrintToPdfStream]:" & " Format:" & $sFormat & " FilePath:" & $sFilePath
348-
Local $s_Result = $oWebV2M.PrintToPdfStream($sFormat, $sFilePath)
352+
Local $s_Result = $oWebV2M.PrintToPdfStream()
349353
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1)
350354
If StringInStr($s_Result, 'ERROR:') Then SetError(1)
355+
351356
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " RESULT:" & ((@error) ? ($s_Result) : ("SUCCESS")), 1)
352357
Return SetError(@error, @extended, $s_Result)
353358
EndFunc ;==>_NetWebView2_PrintToPdfStream
@@ -474,14 +479,15 @@ EndFunc ;==>__NetWebView2_COMErrFunc
474479
; Handles native WebView2 events
475480
#TODO => Func __NetWebView2_WebViewEvents__OnMessageReceived(ByRef $oWebV2M, $hGUI, $sMsg)
476481
Func __NetWebView2_WebViewEvents__OnMessageReceived($sMsg)
482+
Local Const $s_Prefix = "[WebViewEvents__OnMessageReceived]:"
477483
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler
478484
#forceref $oMyError
485+
479486
Local $iSplitPos = StringInStr($sMsg, "|")
480487
Local $sCommand = $iSplitPos ? StringStripWS(StringLeft($sMsg, $iSplitPos - 1), 3) : $sMsg
481488
Local $sData = $iSplitPos ? StringTrimLeft($sMsg, $iSplitPos) : ""
482489
Local $aParts
483490

484-
Local Const $s_Prefix = "[WebViewEvents__OnMessageReceived]:" & $sCommand & ": "
485491
Switch $sCommand
486492
Case "INIT_READY"
487493
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & $sData, 1)
@@ -525,10 +531,10 @@ EndFunc ;==>__NetWebView2_WebViewEvents__OnMessageReceived
525531
; Handles custom messages from JavaScript (window.chrome.webview.postMessage)
526532
#TODO => Func __NetWebView2_JSEvents__OnMessageReceived(ByRef $oWebV2M, ByRef $oWebJS, $hGUI, $sMsg)
527533
Func __NetWebView2_JSEvents__OnMessageReceived($sMsg)
534+
Local Const $s_Prefix = "[JSEvents__OnMessageReceived]:"
528535
Local $oMyError = ObjEvent("AutoIt.Error", __NetWebView2_COMErrFunc) ; Local COM Error Handler
529536
#forceref $oMyError
530537

531-
Local Const $s_Prefix = "[JSEvents__OnMessageReceived]:"
532538
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix & " " & (StringLen($sMsg) > 150 ? StringLeft($sMsg, 150) & "..." : $sMsg), 1)
533539
Local $sFirstChar = StringLeft($sMsg, 1)
534540

@@ -637,4 +643,3 @@ Func __NetWebView2_WebViewEvents__OnContextMenu($sMenuData)
637643
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 1)
638644
EndFunc ;==>__NetWebView2_WebViewEvents__OnContextMenu
639645
#EndRegion ; NetWebView2Lib UDF - === EVENT HANDLERS ===
640-

0 commit comments

Comments
 (0)