Debug anonymous javascript functions
One of the powers of the WebView2 control is that you can insert javascript into the loaded document in order to add functionality and interact with your application.
But how do you troubleshoot that?
If you use the RunAnonymousFunction from the AntViewDocument interface then you can debug the anonymous function as follows:
The WebView2 control that the AntView control hosts is a full browser, as such, it does come with a debugger.
As long as the developer tools haven't been disabled, you can use those debugging features for your benefit.
Right click on the rendered html and click "inspect" from the context menu. (Another way to invoke the debugger is to press F12 after clicking on the AntView control)
The next thing you should know is that the anonymous function is executed in the browser as a function "AntAnonymousFunction".
With those 2 tricks on your sleeve, you now have all you need to be able to put a breakpoint.
First make sure the anonymous function was run at least once already (in our case we clicked a button that invoked the RunAnonymousFunction method that we want to debug)
Now type AntAnonymousFunction in the debug console, like so
double click on the function content and it opens a new tab.
This then is the debugger tab and you can put a breakpoint. Put a breakpoint on the "app" line. In this particular problem we noticed that when we stepped over the function - after triggering it from VB6 - that it went into the void on the line "PlayerTime = "
After seeing that we triggered it again and now instead of stepping over the line I went to the console tab and tried it there.
For our problem this means that app.currentTime is not a function, but a variable!
By changing our script in the VB6 anonymous function to take that into account,
we now have it working without having to resort to async await or timers or anything else...
For context, this text was taken from the following thread at our forum:
AntView forum, troubleshooting a javascript error. (You need to login to see the screenshots)
AntView - The MS Edge WebView2 ActiveX control Date last changed: 09/25/2024