Welcome Guest Search | Active Topics | Sign In | Register

Proper way to obtain actual DOM content? Options
Christian Porzio
Posted: Friday, January 5, 2018 6:11:15 PM
Rank: Advanced Member
Groups: Member

Joined: 10/4/2016
Posts: 104
Hi,

Our pages are written in Angular (Single Page Application) and getting the source using webView.getSource() is useless as it does not reflect the actual content of the page.

Surely when debugging it, one can see the full content in the Elements tab of the debugger and eventually by selecting the html element and Edit as HTML, one can obtain the actual content of the page.

However this is not practical because when our users experience an issue, they are not qualified to proceed to those debug steps and it is quasi impossible for us to reproduce their situation.

I would like to take advantage of all the power of your browser to retrieve automatically the actual HTML content as shown is the debugger.

Would you mind to provide me with some tips on how to get this? I doubt there would be an easy way to do it using the exposed API but instead would need to inject some javaScript but... The catch22 is that we need to trigger that from the page, calling an exposed method of the wrapper.

So if that method call back a javascript method into the page, I'm afraid I will run into a deadlock.

If you have any suggestion on how to go by with this, that would be great.

Ideally having one single method that return the actual HTML content would be even better.

Thanks a lot!

eo_support
Posted: Friday, January 5, 2018 6:36:54 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi,

The recommended way to perform this kind of task is to use EvalScript (or other variant such as QueueScriptCall. Basically whatever you want to do you do it with JavaScript and then use EvalScript to run it. The main benefit of this approach is performance ---- this eliminates all the intermediate roundtrips between the .NET runtime and the browser engine, which is a rather expensive operation. You can find more detailed explanation here:

https://www.essentialobjects.com/doc/webbrowser/advanced/jsdom.aspx

To get your page HTML, you can just do something like this:

Code: C#
webView.EvalScript("document.documentElement.innerHTML");


Thanks!
Christian Porzio
Posted: Friday, January 5, 2018 7:10:18 PM
Rank: Advanced Member
Groups: Member

Joined: 10/4/2016
Posts: 104
That's it! Thanks a lot!!! :-)


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.