Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] WebView.Navigated event not fired when no internet available on iOS. #12312

Closed
aaRopi opened this issue Sep 30, 2020 · 6 comments
Closed
Labels
a/webview e/4 🕓 4 in-progress This issue has an associated pull request that may resolve it! p/iOS 🍎 t/bug 🐛
Milestone

Comments

@aaRopi
Copy link
Contributor

aaRopi commented Sep 30, 2020

Description

WebView.Navigated NOT fired on iOS when no internet connection is available.

Steps to Reproduce

  1. Hook into WebView.Navigating and WebView.Navigated events.
  2. Run app on iOS without internet connection.
  3. Handler for WebView.Navigated is never called.

Expected Behavior

On iOS, when loading a url in the WebView, if there is no internet connection available, the WebView should fire a Navigated event with WebNavigationResult.Failure.

Since this is observed behavior on Android, I expected iOS to behave the same way.

Actual Behavior

The Navigated event is never fired for this error case.

Basic Information

  • Version with issue: 4.8.0.1364
  • Platform Target Frameworks:
    • iOS: 13, 14

Workaround

No suitable workaround found yet. I know where the bug is and how it can be fixed.

  1. iOS WkWebView requires a delegate WkNavigationDelegate to handle various callbacks from the WkWebView.

  2. The WkNavigationDelegate has 2 methods to handle errors:

  • DidFailNavigation(WKWebView webView, WKNavigation navigation, NSError error)
  • DidFailProvisionalNavigation(WKWebView webView, WKNavigation navigation, NSError error)
  1. Only one of them has been implemented as can be seen here: WkWebViewRenderer source code

  2. For now the solution would be to implement the other method. The implementation can be copied from DidFailNavigation

@aaRopi aaRopi added s/unverified New report that has yet to be verified t/bug 🐛 labels Sep 30, 2020
@samhouts samhouts added the in-progress This issue has an associated pull request that may resolve it! label Oct 1, 2020
@jsuarezruiz jsuarezruiz added a/webview p/iOS 🍎 and removed s/unverified New report that has yet to be verified labels Oct 5, 2020
@pcdus
Copy link

pcdus commented Nov 2, 2020

It's the same thing when requesting a invalid url:

  • on Android, this will fire a Navigated event with WebNavigationResult.Failure
  • on iOS, nothing happens: we only have a white empty View

Do you prefer I create a new issue, or is it possible to fix this in the same time?

@aaRopi
Copy link
Contributor Author

aaRopi commented Nov 2, 2020

Hi @Goldstrike ,

Thank you for the additional info. I have a PR that is open fixing the issue I have outlined. Here: #12327

I don't know if the PR fixes your issue as well.

@pcdus
Copy link

pcdus commented Nov 2, 2020

Hi @aaRopi ,
So if I want to use your code, what do I have to do?

Is it correct? Is there something else to do?

@aaRopi
Copy link
Contributor Author

aaRopi commented Nov 2, 2020

Hi @Goldstrike ,

Unfortunately, that will not work. This is because the current code references a lot of code that is internal to Xamarin.Forms. I could not find a way to fix my issue from outside, without duplicating a lot of the code that already exists. Thus, making a PR was the easier solution for me.

@pcdus
Copy link

pcdus commented Nov 2, 2020

@samhouts @jsuarezruiz
What's new about this PR? Is there another way to fix the original issue?

@pcdus
Copy link

pcdus commented Nov 4, 2020

I've created a new bug for the other cases: #12732

@rmarinho rmarinho added the e/4 🕓 4 label Nov 4, 2020
@PureWeen PureWeen added this to the 5.0.1 milestone Nov 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/webview e/4 🕓 4 in-progress This issue has an associated pull request that may resolve it! p/iOS 🍎 t/bug 🐛
Projects
None yet
Development

No branches or pull requests

6 participants