@@ -786,12 +786,14 @@ Func _NetWebView2_ExportPageData($oWebV2M, $iFormat, $sFilePath = '')
786786 #forceref $oMyError
787787 #TODO $sParameters - search for = > " name" : " captureSnapshot" ; https://github.com/ChromeDevTools/devtools-protocol/blob/master/json/browser_protocol.json
788788
789- Local $s_Result = $oWebV2M .ExportPageData($iFormat , $sFilePath )
790- If StringLeft ($s_Result , 6 ) = ' ERROR:' Then SetError (1 )
791- __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & " RESULT:" & ((@error ) ? ($s_Result ) : (" SUCCESS" )), 1 , $ERR , $EXT )
792- Return SetError (@error , @extended , $s_Result )
789+ Local $RET = $oWebV2M .ExportPageData($iFormat , $sFilePath )
790+ If StringLeft ($RET , 6 ) = " ERROR:" Then
791+ $MSG = " RESULT:" & $RET
792+ $ERR = 1
793+ Else
794+ $MSG = " RESULT: SUCCESS"
795+ EndIf
793796
794- #TODO ENDPOINT REFACTORING
795797 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & $MSG , 1 , $ERR , $EXT )
796798 Return SetError ($ERR , $EXT , $RET )
797799EndFunc ; ==>_NetWebView2_ExportPageData
@@ -815,11 +817,9 @@ Func _NetWebView2_GetSource($oWebV2M)
815817 Local $oMyError = ObjEvent (" AutoIt.Error" , __NetWebView2_COMErrFunc) ; Local COM Error Handler
816818 #forceref $oMyError
817819
818- Local $sSource = $oWebV2M .GetSource()
819- If @error Then __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 , $ERR , $EXT )
820- Return SetError (@error , @extended , $sSource )
820+ Local $RET = $oWebV2M .GetSource()
821+ $ERR = @error
821822
822- #TODO ENDPOINT REFACTORING
823823 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & $MSG , 1 , $ERR , $EXT )
824824 Return SetError ($ERR , $EXT , $RET )
825825EndFunc ; ==>_NetWebView2_GetSource
@@ -850,44 +850,47 @@ Func _NetWebView2_NavigateToPDF($oWebV2M, $s_URL_or_FilePath, Const $s_Parameter
850850 Local Const $s_Prefix = " [_NetWebView2_NavigateToPDF]: URL_or_File:" & $s_URL_or_FilePath
851851 Local $ERR = 0 , $EXT = 0 , $RET = False , $MSG = " " ; predefined endpoint results
852852
853- If (Not IsObj ($oWebV2M )) Or ObjName ($oWebV2M , $OBJ_PROGID ) <> ' NetWebView2Lib.WebView2Manager' Then Return SetError (1 , 0 , " ERROR: Invalid Object" )
854-
855- If $sExpectedTitle = Default Then
856- Local $aFilePath = StringSplit ($s_URL_or_FilePath , " \" )
857- If @error Then
858- $sExpectedTitle = ' '
859- Else
860- $sExpectedTitle = $aFilePath [$aFilePath [0 ]]
861- $sExpectedTitle = StringReplace ($sExpectedTitle , ' (' , ' \(' )
862- $sExpectedTitle = StringReplace ($sExpectedTitle , ' )' , ' \)' )
863- $sExpectedTitle = StringReplace ($sExpectedTitle , ' .' , ' \.' )
853+ If (Not IsObj ($oWebV2M )) Or ObjName ($oWebV2M , $OBJ_PROGID ) <> ' NetWebView2Lib.WebView2Manager' Then
854+ $ERR = 1
855+ $MSG = " ERROR: Invalid Object"
856+ Else
857+ If $sExpectedTitle = Default Then
858+ Local $aFilePath = StringSplit ($s_URL_or_FilePath , " \" )
859+ If @error Then
860+ $sExpectedTitle = ' '
861+ Else
862+ $sExpectedTitle = $aFilePath [$aFilePath [0 ]]
863+ $sExpectedTitle = StringReplace ($sExpectedTitle , ' (' , ' \(' )
864+ $sExpectedTitle = StringReplace ($sExpectedTitle , ' )' , ' \)' )
865+ $sExpectedTitle = StringReplace ($sExpectedTitle , ' .' , ' \.' )
866+ EndIf
864867 EndIf
865- EndIf
866868
867- If FileExists ($s_URL_or_FilePath ) Then
868- $s_URL_or_FilePath = StringReplace ($s_URL_or_FilePath , ' \' , ' /' )
869- $s_URL_or_FilePath = StringReplace ($s_URL_or_FilePath , ' ' , ' %20' )
870- $s_URL_or_FilePath = " file:///" & $s_URL_or_FilePath
871- EndIf
869+ If FileExists ($s_URL_or_FilePath ) Then ; check if it is local path - yes=change path - otherwise treat as url
870+ $s_URL_or_FilePath = StringReplace ($s_URL_or_FilePath , ' \' , ' /' )
871+ $s_URL_or_FilePath = StringReplace ($s_URL_or_FilePath , ' ' , ' %20' )
872+ $s_URL_or_FilePath = " file:///" & $s_URL_or_FilePath
873+ EndIf
872874
873- If $s_Parameters Then
874- $s_URL_or_FilePath &= $s_Parameters
875- #TIP: FitToPage: https:// stackoverflow.com/ questions/ 78820187 / how- to - change- webview2- fit- to - page- button- on- pdf- toolbar- default - to - fit- to - width#comment138971950_78821231
876- #TIP: Open desired PAGE: https:// stackoverflow.com/ questions/ 68500164 / cycle- pdf- pages- in - wpf- webview2#comment135402565_68566860
877- EndIf
875+ If $s_Parameters Then
876+ $s_URL_or_FilePath &= $s_Parameters
877+ #TIP: FitToPage: https:// stackoverflow.com/ questions/ 78820187 / how- to - change- webview2- fit- to - page- button- on- pdf- toolbar- default - to - fit- to - width#comment138971950_78821231
878+ #TIP: Open desired PAGE: https:// stackoverflow.com/ questions/ 68500164 / cycle- pdf- pages- in - wpf- webview2#comment135402565_68566860
879+ EndIf
878880
879- Local $idPic = 0
880- $oWebV2M .LockWebView()
881- If $bFreeze Then __NetWebView2_freezer($oWebV2M , $idPic )
882- _NetWebView2_Navigate($oWebV2M , $s_URL_or_FilePath , $iWaitMessage , $sExpectedTitle , $iTimeOut_ms )
883- If Not @error Then __NetWebView2_Sleep($iSleepAfter_ms )
884- If @error Then Return SetError (@error , @extended , ' ' )
881+ Local $idPic = 0
882+ $oWebV2M .LockWebView()
883+ If $bFreeze Then __NetWebView2_freezer($oWebV2M , $idPic )
884+ _NetWebView2_Navigate($oWebV2M , $s_URL_or_FilePath , $iWaitMessage , $sExpectedTitle , $iTimeOut_ms )
885+ $ERR = @error
886+ $EXT = @extended
887+ If Not @error Then __NetWebView2_Sleep($iSleepAfter_ms )
885888
886- __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 , $ERR , $EXT )
887- If $bFreeze And $idPic Then __NetWebView2_freezer($oWebV2M , $idPic )
888- $oWebV2M .UnLockWebView()
889+ If $bFreeze And $idPic Then __NetWebView2_freezer($oWebV2M , $idPic )
890+ $oWebV2M .UnLockWebView()
891+ $RET = True
892+ EndIf
889893
890- #TODO ENDPOINT REFACTORING
891894 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & $MSG , 1 , $ERR , $EXT )
892895 Return SetError ($ERR , $EXT , $RET )
893896EndFunc ; ==>_NetWebView2_NavigateToPDF
@@ -913,19 +916,23 @@ Func _NetWebView2_PrintToPdfStream($oWebV2M, $b_TBinary_FBase64)
913916 Local $oMyError = ObjEvent (" AutoIt.Error" , __NetWebView2_COMErrFunc) ; Local COM Error Handler
914917 #forceref $oMyError
915918
916- Local $s_Result = $oWebV2M .PrintToPdfStream()
917- __NetWebView2_Log(@ScriptLineNumber , $s_Prefix , 1 , $ERR , $EXT )
918- If StringInStr ($s_Result , ' ERROR:' ) Then SetError (1 )
919-
920- If $b_TBinary_FBase64 Then
921- ; decode Base64 encoded data do Binary
922- $s_Result = _NetWebView2_DecodeB64ToBinary($oWebV2M , $s_Result )
919+ Local $RET = $oWebV2M .PrintToPdfStream()
920+ If StringInStr ($RET , ' ERROR:' ) Then
921+ $ERR = 1
922+ $MSG = " RESULT: " & $RET
923+ Else
924+ If $b_TBinary_FBase64 Then
925+ ; decode Base64 encoded data do Binary
926+ $s_Result = _NetWebView2_DecodeB64ToBinary($oWebV2M , $s_Result )
927+ $ERR = 2
928+ EndIf
929+ EndIf
930+ If $ERR Then
931+ $RET = " "
932+ Else
933+ $MSG = " RESULT: SUCCESS"
923934 EndIf
924935
925- __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & " RESULT:" & ((@error ) ? ($s_Result ) : (" SUCCESS" )), 1 , $ERR , $EXT )
926- Return SetError (@error , @extended , $s_Result )
927-
928- #TODO ENDPOINT REFACTORING
929936 __NetWebView2_Log(@ScriptLineNumber , $s_Prefix & $MSG , 1 , $ERR , $EXT )
930937 Return SetError ($ERR , $EXT , $RET )
931938EndFunc ; ==>_NetWebView2_PrintToPdfStream
0 commit comments