Hi,
I'm having a problem with navigatetostringsync method. The same really simple html content works fine with navigatetostring and shows html content correctly. However, navigatetostringsync returns success = false and TxWebErrorStatus = 0
Just ran your code like below by putting it into the VFP Standard example under the "Render Page" button and it works as expected.
Code:
LOCAL lcHtml
lcHtml = ''
TEXT TO lcHtml NOSHOW PRETEXT 7
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>Hola Mundo</body></html>
ENDTEXT
LOCAL Success
LOCAL Status
Success = .F.
isStatus = 0
So it looks like that we are missing out on some context.
Can you show more code than "just the line".
From where are you calling the NavigateToStringSync method?
PS: I noticed that you tried to post, most likely VFP code (or perhaps that html above), which was rejected by the forum's web application firewall. This hopefully works now as the WAF has been tweaked a bit. Sadly we can't run the forum without a WAF anymore.
Just ran your code like below by putting it into the VFP Standard example under the "Render Page" button and it works as expected.
Code:
LOCAL lcHtml
lcHtml = ''
TEXT TO lcHtml NOSHOW PRETEXT 7
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>Hola Mundo</body></html>
ENDTEXT
LOCAL Success
LOCAL Status
Success = .F.
isStatus = 0
So it looks like that we are missing out on some context.
Can you show more code than "just the line".
From where are you calling the NavigateToStringSync method?
PS: I noticed that you tried to post, most likely VFP code (or perhaps that html above), which was rejected by the forum's web application firewall. This hopefully works now as the WAF has been tweaked a bit. Sadly we can't run the forum without a WAF anymore.
Hi.
I've worked a lot with Antview. But now, don't know whats happening.
Init of form:
Code:
thisform.oantview.synchronousTimeOut = 20000 && 20 segundos
thisform.oantviewdocument = CREATEOBJECT('AntViewAx2.AntViewDocument') && create the AntViewDocument and assign it to a form property
thisform.oantviewdocument.SynchronousTimeOut = 6000 && 6 segundos. Por defecto es solo 1 segundo
thisform.oantview.Init()
thisform.oantview.UnlockControl("MyCompany", "Mykey")
thisform.oantview.EventsUseHexadecimal = .t.
thisform.oantview.ZoomControlEnabled = .t.
thisform.oantview.zoomFactor = cast(25 as double)
thisform.oantviewdocument.CurrentBrowser = thisform.oantview.object && this property shows as "Write-only" in the object browser
Thisform.oantview.WebMessageEnabled = .T.
Thisform.oantview.defaultScriptDialogsEnabled = .T.
Thisform.oantview.statusBarEnabled = .T.
Activate event of form:
Code:
dodefault()
IF !THISFORM.inicializado
*!* thisform.inicializa()
THISFORM.cargar_editor()
THISFORM.inicializado = .T.
ENDIF
cargar_editor method in form:
Code:
LOCAL m.exito, m.TxWebErrorStatus, m.lcHtml
m.exito = .f.
m.TxWebErrorStatus = 0
TEXT TO lcHtml NOSHOW PRETEXT 7
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>Hola Mundo</body></html>
ENDTEXT
thisform.oantview.visible = .t.
thisform.oantView.object.NavigateToStringSync(lcHtml,@m.exito,@m.TxWebErrorStatus)
IF !m.exito
messagebox("No se ha podido navegar." + m.crlf + "Error nº: " + alltrim(str(m.TxWebErrorStatus)), 0 + 48)
endif
Is lasting a lot in NavigateToStringSync sentence and finally m.exito is false and TxWebErrorStatus 0, so message gets fired
The second parameter (IsSuccess in the docs) returns false, so the function correctly returns that it didn't work.
The help is not very clear here. It mostly points you to the 3rd parameter for finding a hint on what was wrong. The value of that parameter is what is returned in the OnNavigationCompleted event if you happened to run the synchronous variant.
But it never reaches this event and that's why that one returns 0. Which leaves you in the dark.
There's also the return status of the function itself and that one actually does return an error (error 22 in this case, a time out) and the help mentions that, but it needs to be rewritten so that it is more clear.
The problem you are having is that during your form activate the control does not yet exist.
The error returns a timeout (which is factually correct), but it would be so much better if it just would have returned an error stating that the control does not yet exist.
There are several ways to address your issue.
As you are using an asynchronous navigate method, let's stay with that for the moment.
The following does work in VFP.
Code:
LOCAL m.exito, m.TxWebErrorStatus, m.lcHtml, hResult, iError
m.exito = .f.
m.TxWebErrorStatus = 0
hResult = 0
TEXT TO lcHtml NOSHOW PRETEXT 7
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>Hola Mundo</body></html>
ENDTEXT
thisform.oantview.visible = .t.
iError = thisform.oantView.object.NavigateToStringSync(lcHtml,@m.exito,@m.TxWebErrorStatus)
IF !m.exito
messagebox("No se ha podido navegar Error nº: " + alltrim(str(iError)), 0 + 48)
ENDIF
IF !thisform.oAntview.WebViewCreated
messagebox("WebView not created yet!")
ENDIF
So the fix is to force a CreateWebViewSync before you navigate.
This is not needed for a normal navigation as those are cached and will be executed after the control is created if those are requested before the control exists.
Sadly this only added to the confusion in this particular scenario as a string navigation is not cached.
The second parameter (IsSuccess in the docs) returns false, so the function correctly returns that it didn't work.
The help is not very clear here. It mostly points you to the 3rd parameter for finding a hint on what was wrong. The value of that parameter is what is returned in the OnNavigationCompleted event if you happened to run the synchronous variant.
But it never reaches this event and that's why that one returns 0. Which leaves you in the dark.
There's also the return status of the function itself and that one actually does return an error (error 22 in this case, a time out) and the help mentions that, but it needs to be rewritten so that it is more clear.
The problem you are having is that during your form activate the control does not yet exist.
The error returns a timeout (which is factually correct), but it would be so much better if it just would have returned an error stating that the control does not yet exist.
There are several ways to address your issue.
As you are using an asynchronous navigate method, let's stay with that for the moment.
The following does work in VFP.
Code:
LOCAL m.exito, m.TxWebErrorStatus, m.lcHtml, hResult, iError
m.exito = .f.
m.TxWebErrorStatus = 0
hResult = 0
TEXT TO lcHtml NOSHOW PRETEXT 7
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>Hola Mundo</body></html>
ENDTEXT
thisform.oantview.visible = .t.
iError = thisform.oantView.object.NavigateToStringSync(lcHtml,@m.exito,@m.TxWebErrorStatus)
IF !m.exito
messagebox("No se ha podido navegar Error nº: " + alltrim(str(iError)), 0 + 48)
ENDIF
IF !thisform.oAntview.WebViewCreated
messagebox("WebView not created yet!")
ENDIF
So the fix is to force a CreateWebViewSync before you navigate.
This is not needed for a normal navigation as those are cached and will be executed after the control is created if those are requested before the control exists.
Sadly this only added to the confusion in this particular scenario as a string navigation is not cached.
Hope this helps,
Wil
After a few tests, no success. I can say that is not the html content because error is fired also with the simple 'Hello World'
With your new code getting ierror, i get error 25
Code:
Local m.codigo_html, m.exito, m.TxWebErrorStatus, m.hResult, m.ierror
m.hResult = 0
m.exito = .F.
m.TxWebErrorStatus = 0
TEXT TO m.codigo_html NOSHOW PRETEXT 7
<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>Hola Mundo</body></html>
ENDTEXT
thisform.oantview.object.CreateWebViewSync(@hResult) && esto me dicen en antview que es importante para evitar errores
m.ierror = Thisform.oAntView.Object.NavigateToStringsync(m.codigo_html, @m.exito, @m.TxWebErrorStatus)
If !m.exito
App.Mess("no se ha podido navegar." + m.crlf + "Error nº: " + Alltrim(Str(m.ierror)), 0 + 48)
Endif
If !Thisform.oAntView.WebViewCreated
App.Mess("WebView not created yet!")
Endif
Thisform.oAntView.Refresh()
Before this, in the form, i've loaded other html files with navigatesync instead of navigatetostringsync with no problems.
I know the whole test will be including in code the rest of operations did before.
Error 25 indicates that the NavigateToStringSync method is called from within an event raised by the AntView control.
Are you sure that the cargar_editor method is only called from within the activate event of the form?
Not for example from the OnActivate event of the AntView control?
If you keep having this issue, then please create a log file at LogMode level 2 and email it to support.
You are right:
Event OnwebMessagereceived calls a method 'generar_pdf' that calls to cargar_editor method.
Don't know other way to do it: i have to wait for a script that returns me some data and then fire code that creates a pdf file with this data.
(2026-03-17, 11:36:08)carlos@agpsoftware.com Wrote: You are right:
Event OnwebMessagereceived calls a method 'generar_pdf' that calls to cargar_editor method.
Don't know other way to do it: i have to wait for a script that returns me some data and then fire code that creates a pdf file with this data.
OK.
The idea behind the "Sync" methods is that it allows you to write code in a more procedural matter whereas the WebView2 control itself is completely event based. Mixing event based code and these "Sync" methods is currently not supported.
The solution here is to use the asynchronous alternative NavigateToString method instead.
But as you say "you have to wait".. the solution to that is to use OnNavigationStarting event to get the NavigationIdHex value via the Args parameter. You can check the Uri and RequestHeaders to verify that this is the correct URL to check.
Then in OnNavigationCompletedHex you can wait for the event with the correct NavigationId to trigger.
That would be the technically correct way.
Alternatively instead of trying to track the NavigationId, you probably also can keep a global boolean to set just before and keep track of "NavigateToString triggered" and then wait for OnNavigationCompletedHex to trigger, do what you need to do and reset the global boolean back to false.
--
Wil
Thanks, Wil.
What i did is to have a second Antview object just for generate pdf purpose. So 'printtopdf' does not interact with other code.
Also, i move to not sync methods and control everything through OnNavigationCompletedHEx event and a form property instead a global variable.
Now, everything is working.
Best regards.
A form property is better than a global variable.
Using non sync methods also give you more flexibility, but sadly it adds some additional complexity.
Either way, glad to hear you got it working now.