Welcome Guest Search | Active Topics | Sign In | Register

WebView view webpage source Options
Drags
Posted: Thursday, February 23, 2017 12:11:23 AM
Rank: Member
Groups: Member

Joined: 10/4/2015
Posts: 13
Hi

Sorry might be simple thing, but I can't get to bottom of this one.
Web browser control allows to right click and get full page source.

In case of page containing iframe GetHtml will not return iframe code,
is there way to get same as view source functionality?


Thank you!

eo_support
Posted: Thursday, February 23, 2017 3:28:08 PM
Rank: Administration
Groups: Administration

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

You won't be able to do that directly with GetHtml because GetHtml follows DOM tree and in a DOM tree, an iframe element generally has no childNodes (it can have text node that represents the text in between it's open tag and close tag, but it won't have anything to do with the actual document being loaded inside the frame). If you right click to get the full page source from a browser you wouldn't get the iframe contents either.

The contents of the iframe belongs to a different document and has its own DOM tree. So it's possible for you to use EvalScript to get the HTML of each document and then merge them together. You would need to use this overload to pass the frame name in order to get the HTML of that frame:

https://www.essentialobjects.com/doc/eo.webbrowser.webview.evalscript_overload_1.aspx

The code will be something like this:

For main frame:

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


for child frame:

Code: C#
webView.EvalScript("document.documentElement.outerHTML", your_child_frame_namefalse);


You can then merge the result of the child frame HTML into the main frame HTML by locating the matching iframe tag and insert the child frame HTML in between the iframe's open tag and close tag if that's the desired result for you.

Hope this helps.

Thanks!

Drags
Posted: Thursday, February 23, 2017 4:34:03 PM
Rank: Member
Groups: Member

Joined: 10/4/2015
Posts: 13
What if there is iframe within iframe within iframe? I believe there will be issues executing javascript due to security issues.
Why can't view source be exposed as function?

We like to log all things happening, the more in log files the better, having easy way to save html just makes troubleshooting easier.

thnx

eo_support
Posted: Thursday, February 23, 2017 4:51:47 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Unfortunately this is not supported by the core browser engine. The GetHtml method relies on the browser's engine's WebFrameContentDumper class's dumpAsMarkup to do the work. This class does not support the level of nesting iframe output as you described. Generally we do not add extra features to the core browser engine as different users would want different things and it would cause the code base become unmanageable for us if we choose to deviate from Chromium's codebase every time there is a feature request.
Drags
Posted: Thursday, February 23, 2017 4:56:10 PM
Rank: Member
Groups: Member

Joined: 10/4/2015
Posts: 13
Sorry to be pain, why can't "view source", that is accessible via right click, be exposed as function?

thnx
eo_support
Posted: Thursday, February 23, 2017 4:58:24 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Where do you see "View Source" show you the contents of the iframe? What browser do you use? We tested Google Chrome and it only shows the iframe element itself, but not the content of the iframe.
Drags
Posted: Thursday, February 23, 2017 5:22:37 PM
Rank: Member
Groups: Member

Joined: 10/4/2015
Posts: 13
Sorry there are two selections view frame source, must have been looking at that and thought it's all document.



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.