Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a content from Windows Phone webview control

I am trying to get a DOM model from webview control or just HTML to process it by XML tools. That control does not offer any property which returns what I need. I have found a solution by using JS:

string html = Browser1.InvokeScript("eval", new string[] { "document.documentElement.outerHTML;" });

But I am getting a not implemented exception.

What am I doing wrong? I'm new in WP programming.

like image 653
Jarosław Szczepaniak Avatar asked Oct 13 '14 19:10

Jarosław Szczepaniak


1 Answers

Like Romasz said use InvokeScriptAsync -- but make sure the page is loaded first.

Sample Application:

<Grid>        
    <StackPanel>
        <WebView x:Name="myWebView" Height="300" VerticalAlignment="Top" />
        <Button Content="Read HTML" Click="Button_Click" />
        <TextBlock x:Name="myTextBlock"></TextBlock>
    </StackPanel>
</Grid>
    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        this.myWebView.Navigate(new Uri("http://www.google.com", UriKind.Absolute));
    }

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            string html = await myWebView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
            myTextBlock.Text = html;
        }
        catch (Exception ex)
        {
        }
    }

enter image description here

like image 68
Chubosaurus Software Avatar answered Oct 24 '22 21:10

Chubosaurus Software