WebView events does not detect the url change

Alan Rojas 1 Reputation point
2021-06-17T15:28:35.95+00:00

I want to navigate only to a youtube video and if I try to navigate to youtube home or another page inside youtube, i want to detect the url change and cancel it from loading. I have implemented the OnNavigating and OnNavigated event, a webview custom renderer to use ShouldOverrideUrl, PageStarted, PageFinished to detect the url change and nothing works. The only event that detect it is DoUpdateHistory but when it detect the url, the page is already loaded and i want to prevent loading another page.

It should be noted that when I try to navigate outside of YouTube, the events do work.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,338 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,956 Reputation points
    2021-06-18T07:11:03.917+00:00

    Hello @Alan Rojas ,​

    Welcome to our Microsoft Q&A platform!

    WebView events does not detect the url change

    There are two ways to redirect web pages: Forward and Redirect. It exists a clear difference in the jump between the two ways.

    Forward: The address bar of the browser URL remains unchanged.
    Redirect: The address bar of the browser URL changes.

    The youtube api seems to use the Forward way to redirect the url. When clicking a tab on the youtube home page, the related event will not be called. But these events are triggered when testing google web. You could test it on your side to vertify that.

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.