Bug 54072 - WebView reports incorrect Navigated result after toggling wifi/cell data
Summary: WebView reports incorrect Navigated result after toggling wifi/cell data
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jason Smith [MSFT]
Depends on:
Reported: 2017-03-27 17:30 UTC by Ken Sykora
Modified: 2017-06-19 21:18 UTC (History)
4 users (show)

Tags: bug, android, webview, navigatedstatus, ac
Is this bug a regression?: No
Last known good build:

Minimum reproduction using Visual Studio Cross-Platform App template (193.67 KB, application/x-zip-compressed)
2017-03-27 17:30 UTC, Ken Sykora
Screen Recording showing bug in action (6.29 MB, video/mp4)
2017-03-27 17:32 UTC, Ken Sykora

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 54072 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Ken Sykora 2017-03-27 17:30:45 UTC
Created attachment 20911 [details]
Minimum reproduction using Visual Studio Cross-Platform App template

I'm running into an issue where the WebView.Navigated event is incorrectly reporting the status as Failure when the actual navigation event succeeds. I've attached a minimum reproduction and screen recording of this in practice. This occurs on Android (I haven't thoroughly tested other platforms, but I think the others work fine)

Basically, if you start connected to the internet with your WebView on a cellular connection, load a page, and then turn off Cellular Data on Android, and then reload the page, and then Re-enable cellular data, then reload the page, the last page reload navigates successfully but returns a Navigated event still indicating Failure.

Steps to reproduce:

 0. Start on an Android device with a cellular data connection
 1. Create a ContentPage with a WebView
 2. Navigate to a URL page on that WebView- Callback to Navigated indicates Success (expected)
 3. Disable the cellular data
 4. Navigate to a URL page on that WebView- Callback to Navigated indicates Failure (expected)
 5. Re-enable the cellular data
 6. Navigate to a URL page on that WebView

Expected: Callback to Navigated indicates Success
Actual: Callback to Navigated indicates Failure.
Comment 1 Ken Sykora 2017-03-27 17:32:53 UTC
Created attachment 20912 [details]
Screen Recording showing bug in action
Comment 2 Jimmy [MSFT] 2017-03-28 15:53:35 UTC
I was able to reproduce this issue with the attached project so I am confirming this report so the team can investigate further. 

I tested with an Android 5.0 emulator and 6.0 device, and the issue also occurs after toggling wifi, not just cell data.

### Version Tests
2.3.4-pre6  BAD   BAD   BAD
Comment 3 Mikalai Daronin 2017-04-14 07:21:30 UTC
Hello everyone
Any updates on this?

The reason of the bug is fairly clear: 

The `_navigationResult` variable is being set to `Success` only in the `ShouldOverrideUrlLoading` method; however, this method is not being called when you try to _reload_ the web page: https://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String)

So, even if a page loads successfully, the Xamarin.Forms.WebView still receives the outdated `_navigationResult` variable from `OnPageFinished`.