mujno
mujno

Reputation: 121

download html content from a page in webview for windows phone 8.1

I am working on windows phone 8.1 runtime universal app and using webview to go to page. I want to be able to download the HTML on the page into a string so I can use t in my app. I have used these links for help but to no avail:

http://codesnack.com/blog/2012/01/05/metro-webview-source-workarounds/

Retrieve Inner Text from WebView HTML in Windows/Windows Phone 8.1

https://social.msdn.microsoft.com/Forums/windowsapps/en-US/331fa2db-3efa-40e2-af08-ddebe9424869/how-to-get-html-source-information-of-webview-in-windows-phone-81?forum=winappswithcsharp

so I added this line in my NavigationCompleted event handler

      string pageContent = webBrowser1.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" }).ToString();

But when I step through the code all I get is System.__ComObject as the value for pageContent .

Any ideas what is going on here?

Thanks!

Upvotes: 0

Views: 822

Answers (1)

Rob Caplan - MSFT
Rob Caplan - MSFT

Reputation: 21899

InvokeScriptAsync returns a IAsyncOperation not a string. If you call ToString() on it you'll just get the type of the object (System.__ComObject).

You'll almost always want to "await" Async functions like this. That will process the returned operation, wait for it to finish, and then return its type.

If you change your code to the following then pageContent will get the HTML from your evaled function:

string pageContent = await webBrowser1.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });

Upvotes: 1

Related Questions