How to force a Windows 10 uwp webview app to load a url after suspend / resuming & auto reload when timing out

て烟熏妆下的殇ゞ 提交于 2021-02-10 16:07:47

问题


This (simplified) c# / XAML UWP Webview app displays a blank page after the app is resumed after about 90+ sec. when displaying a local security cam video stream webpage. It appears to timeout after about 90 sec while the app is being suspended and then upon resuming the webview page is blank. To give the sample code below something to display, I randomly picked a site from a web search and landed on http://www.porttampawebcam.com/. The few youtube and webcam pages I've tried didn't reproduce the issue of timing out like my local web cam server does after a min. or so of inactivity.

A button can be used to manually refresh / reload the page, but how can it be coded to ...

A) Force the url to load every time the app gets resumed? B) Detect that the page has timed out and then reload as needed?

I've done a bit of research on this (using the webview control & UWP application lifecyles), browsed uwp apps on GitHub, and have made progress on several other parts of the app, but have yet to figure out a working solution on these two points.

App was built using the Blank App (Universal Windows) template in Visual Studio 2015.

XAML:

Mainpage.xaml

<Page
    x:Class="WVMinimal.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" ></RowDefinition>
        <RowDefinition Height="auto" ></RowDefinition>

    </Grid.RowDefinitions>
    <WebView Name="WV" Source="http://www.porttampawebcam.com"/>
    </Grid>
</Page>

c#:

Mainpage.xaml.cs


using Windows.UI.Xaml.Controls;

    // The Blank Page item template is documented at     https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

    namespace UWPWebviewTest5
    {
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {

        public MainPage()
        {
            this.InitializeComponent();

        }


}

回答1:


I know it's a bit late and maybe not 100% answering your question but maybe you could try to refresh the WebView content like this:

await WebView.ClearTemporaryWebDataAsync();
yourWebView.Navigate(new Uri("https://www.yourUri.com"));


来源:https://stackoverflow.com/questions/42331902/how-to-force-a-windows-10-uwp-webview-app-to-load-a-url-after-suspend-resuming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!