Theodoros Chatzigiannakis
Theodoros Chatzigiannakis

Reputation: 29213

Intercepting requests and providing resources to Xamarin.Forms.WebView

I want to show some XHTML documents that reference some resources (style sheets, scripts, images, etc). These resources are local, but they do not exist on the file system - instead, they are generated by my application.

Using Android.Webkit.WebView and Android.Webkit.WebViewClient, I can intercept requests and provide these resources flawlessly, using something like this:

internal class MyWebViewClient : WebViewClient
{           
    public override WebResourceResponse ShouldInterceptRequest (WebView view, string url)
    {
        /* logic to create a resource stream for the requested url */
        return new WebResourceResponse (mimeType, encoding, generatedStream);
    }
}

Can I achieve something similar using Xamarin.Forms.WebView and its related classes? If so, how? I haven't noticed in the API documentation any methods that look like they provide equivalent behavior.

Upvotes: 3

Views: 1921

Answers (1)

Pete
Pete

Reputation: 4746

The Xamarin.Forms WebView control is very basic at present. The class members show that you wouldn't be able achieve what you are wanting to do.

You can load a HTML resource etc here that is quite useful in determining how to reference local files, if you do decide and go down that route.

Do note, however, that in Xamarin.Forms v1.2.2.6243 on Android the Source property is incorrectly set for URLs. For instance, if you navigate to www.yahoo.com and do a few clicks on that site, you will see some query string parameters etc. However, on Android this always comes back as Source property being www.yahoo.com. Xamarin have created a temporary fix for this, however you have to include and implement your own custom renderer at present to overcome this.

Upvotes: 3

Related Questions