Bug 29139 - WebView does not detect url changes via javascript
Summary: WebView does not detect url changes via javascript
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.2
Hardware: Macintosh Mac OS
: Normal enhancement
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-04-16 02:46 UTC by roger.schmidlin
Modified: 2016-04-08 19:44 UTC (History)
13 users (show)

Tags: all functional ac
Is this bug a regression?: ---
Last known good build:


Attachments
repro project (181.56 KB, application/zip)
2015-04-21 13:28 UTC, Jimmy [MSFT]
Details
Demo of non-Forms project crashing in same way (21.92 KB, application/x-zip-compressed)
2015-07-01 05:09 UTC, Jason Smith [MSFT]
Details


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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description roger.schmidlin 2015-04-16 02:46:49 UTC
Running my simple web browser app works fine with websites like google or others, meaning if I click on a link and the navigated event gets fired and I can update my browser bar. It doesn't get fired, if I do the same on some sites like youtube. There, I can display the first page but from then on the navigation doesn't get reported anymore. This works though on all the web browser apps on each platform, like safari, chrome ...
Thanks for your help

===================

using System;
using System.Diagnostics;
using Xamarin.Forms;

namespace WebBrowserSimple
{
	public partial class WebBrowserPage : ContentPage
	{
		Entry urlEntry;
		WebView simpleBrowser;

		public WebBrowserPage ()
		{
			InitializeComponent ();
			StackLayout mainStackLayout = new StackLayout ();
			urlEntry = new Entry ();
			urlEntry.Text = "https://www.youtube.com/watch?v=_Idra8rVS1I";
			urlEntry.HorizontalOptions = LayoutOptions.FillAndExpand;
			urlEntry.Completed += OnNavigationBarChanged;
			mainStackLayout.Children.Add (urlEntry);

			simpleBrowser = new WebView ();
			simpleBrowser.Navigated += OnNavigated;
			simpleBrowser.HorizontalOptions = LayoutOptions.FillAndExpand;
			simpleBrowser.VerticalOptions = LayoutOptions.FillAndExpand;
			simpleBrowser.MinimumWidthRequest = 100;
			simpleBrowser.MinimumHeightRequest = 100;
			simpleBrowser.Source = urlEntry.Text;
			mainStackLayout.Children.Add (simpleBrowser);

			Content = mainStackLayout;
		}

		void OnNavigated (object sender, WebNavigationEventArgs e)
		{
			Debug.WriteLine ("URL received after navigated: {0}", e.Url);
			urlEntry.Text = e.Url;
		}

		void OnNavigationBarChanged (object sender, EventArgs e)
		{
			simpleBrowser.Source = urlEntry.Text;
		}
	}
}
Comment 1 Jimmy [MSFT] 2015-04-21 13:28:01 UTC
Created attachment 10843 [details]
repro project

*** Overview ***
The WebView.Navigated event on iOS and Android does not work properly on sites like Youtube, but it works as expected on sites like Xamarin.

On iOS I tested the repro project on the iPhone 6 8.3 simulator and iPhone 5S on 8.2. The navigated event did not get fired on both devices. 

On Android I tested using an emulator running 4.4.2 and a Nexus 7(2013) running 5.0. On the Nexus the event fired, but the  WebNavigationEventArgs.Url contained the Url of the previous page. However, the project worked as expected on the emulator so I’m not sure if the issue on Android is exclusive to 5.0+. 


*** Steps to Reproduce ***
1. Download and run the repro project
2. Note that the correct Url is shown in the entry control above
3. Click on a link on the page to navigate to another page
   - On iOS, note that the Url in the entry control does not change
   - On Android, note that the Url also does not change
4. Click on another link
   - On iOS, it continues to display the original Url
   - On Android, the Url displayed changes to the previous Url


*** Actual Results ***
On iOS, the Navigated event does not get fired and therefore the Url in the entry control does not change.

On Android, the event gets fired but the Url is the one previously navigated to.


*** Expected Results ***
The Navigated event should be fired whenever the WebView navigates to a new page and with the WebNavigationEventArgs.Url.


*** System Environment ***
=== Xamarin Studio ===

Version 5.8.3 (build 1)
Installation UUID: 94ce5106-6a72-4691-b34e-cd5857b1db66
Runtime:
	Mono 3.12.1 ((detached/0849ec7)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312010003

=== Xamarin.Android ===

Version: 4.20.2.1 (Business Edition)
Android SDK: /Users/jimmygarrido/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: 8.9.1.3 (Business Edition)
Hash: f7736a4
Branch: 
Build date: 2015-04-09 04:22:08-0400

=== Xamarin.Mac ===

Version: 1.12.0.14 (Business Edition)

=== Build Information ===

Release ID: 508030001
Git revision: 6e8e725e0d689351901c2c70453bfa4ea25e293b
Build date: 2015-04-06 20:31:47-04
Xamarin addins: 051cd5f8c1b5dbfc87eaef80a74aec03f34c60a8

=== Operating System ===

Mac OS X 10.10.3
Darwin Jimmys-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 2 Dominic N [MSFT] 2015-04-21 14:27:45 UTC
I've been able to replicate the behaviour Jimmy noted using an iPhone 5S simulator running 8.2 on both the stable and alpha channels.

Marking as confirmed.
Comment 3 roger.schmidlin 2015-04-27 02:11:35 UTC
It has been pretty quiet about this bug. I'm really under pressure by my customer for this to be fixed. My app is useless without this. It used to work about 4 weeks ago. 
Is it possible to bump up the priority or even better assign this bug to someone? 

Thanks for your understanding and support,
Roger
Comment 4 roger.schmidlin 2015-05-21 00:00:13 UTC
After this bug not being fixed (for quite a while now), I decided to solve my problem from a different angle. I wanted to use intents or the equivalent with iOS. Unfortunately that doesn't work in the webview either. 
You can use the same example as above and go to one of the youtube clips and try to share. E.g. trying to email the share it calls a mailto rather than the app itself.

Someone out there that has an idea to make the WebView a bit more usable?

I'm hanging in the air with not being able to use the WebView and having no alternative.

Please help!
Comment 5 Chris King 2015-05-27 16:39:40 UTC
Repro is reasonable. Clicking on a link crashes app. Tooling doesn't capture exception so needs further investigation.
Comment 6 roger.schmidlin 2015-06-16 21:13:17 UTC
I am very disappointed to not see this bug fixed in the newest XF release. Still, this bug entry hasn't even touched (at least the status hasn't changed). This is a show stopper for my app. It's almost 3 months now! Please make some noise!
Comment 7 rkmoorthy13 2015-06-20 07:37:04 UTC
Hi,

I am also looking for the same, I have found out this issue is still open.

Is there anyone have any solution for the issue.
Comment 8 roger.schmidlin 2015-06-30 23:10:11 UTC
Event though the state of this bug hasn't change, I thought I give it another try with the new Forms Release from the 30th of June. After all you told to me that you are going to look into this for this release (1.4.3.6372), but wasn't mentioned in the release notes nor of course changes to the bug entry itself.

I added the Navigating event too for more details:
simpleBrowser.Navigating += OnNavigating;
  void OnNavigating (object sender, WebNavigatingEventArgs e)
	{
		Debug.WriteLine ("URL received after navigating: {0}", e.Url);
	}

It has a different behaviour with this release (1.4.3.6372) of Forms:

- Samsung Note 4 (5.0.1) & Samsung S4 (5.0.1): It works like it should now :-) Although no "Navigating" event fired.

- Sony Ericsson (4.0.4): Not even first link works!

- iPod Touch, iPhone 4s Simulator: 
first link works: 
URL received after navigating: https://www.youtube.com/watch?v=_Idra8rVS1I
URL received after navigating: https://m.youtube.com/watch?v=_Idra8rVS1I
URL received after navigating: about:blank
URL received after navigated: https://m.youtube.com/watch?v=_Idra8rVS1I
after that I get only following lines and not actual url:
URL received after navigating: about:blank

- Simulator Nexus 4 API19 & API22: continues with throwing errors like
[eglCodecCommon] **** ERROR unknown type 0x0 (glSizeof,73)

It gets horrible after clicking a link:
URL received after navigated: https://m.youtube.com/watch?v=_Idra8rVS1I
[chromium] [INFO:CONSOLE(0)] "The page at https://m.youtube.com/watch?v=kqfS82tJHto displayed insecure content from android-webview:default_video_poster/-2793590044950430564.
[chromium] ", source: https://m.youtube.com/watch?v=kqfS82tJHto (0)
URL received after navigated: https://m.youtube.com/watch?v=_Idra8rVS1I
URL received after navigated: https://m.youtube.com/watch?v=kqfS82tJHto
URL received after navigated: https://m.youtube.com/watch?v=kqfS82tJHto
[eglCodecCommon] **** ERROR unknown type 0x0 (glSizeof,73)
[chromium] [INFO:CONSOLE(0)] "The page at https://m.youtube.com/watch?v=kqfS82tJHto displayed insecure content from android-webview:default_video_poster/-2793590044950430564.
[chromium] ", source: https://m.youtube.com/watch?v=kqfS82tJHto (0)
[chromium] [INFO:CONSOLE(0)] "The page at https://m.youtube.com/watch?v=kqfS82tJHto displayed insecure content from android-webview:default_video_poster/-2793590044950430564.
[chromium] ", source: https://m.youtube.com/watch?v=kqfS82tJHto (0)
[chromium] [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
[eglCodecCommon] **** ERROR unknown type 0x0 (glSizeof,73)
[chromium] [ERROR:gles2_cmd_decoder_autogen.h(1144)] [GroupMarkerNotSet(crbug.com/242999)!:30FD4AB9]GL ERROR :GL_INVALID_OPERATION : GetIntegerv: <- error from previous GL command
[eglCodecCommon] **** ERROR unknown type 0x0 (glSizeof,73)
[chromium] [ERROR:gles2_cmd_decoder_autogen.h(69)] [GroupMarkerNotSet(crbug.com/242999)!:30FD4AB9]GL ERROR :GL_INVALID_ENUM : glBindTexture: target was GL_TEXTURE_EXTERNAL_OES
[chromium] [ERROR:gles2_cmd_decoder_autogen.h(3142)] [GroupMarkerNotSet(crbug.com/242999)!:30FD4AB9]GL ERROR :GL_INVALID_ENUM : glProduceTextureCHROMIUM: target was GL_TEXTURE_EXTERNAL_OES
[eglCodecCommon] **** ERROR unknown type 0x0 (glSizeof,73)
[chromium] [ERROR:gles2_cmd_decoder_autogen.h(69)] [GroupMarkerNotSet(crbug.com/242999)!:30FD4AB9]GL ERROR :GL_INVALID_ENUM : glBindTexture: target was GL_TEXTURE_EXTERNAL_OES
[chromium] [ERROR:gles2_cmd_decoder_autogen.h(3142)] [GroupMarkerNotSet(crbug.com/242999)!:30FD4AB9]GL ERROR :GL_INVALID_ENUM : glProduceTextureCHROMIUM: target was GL_TEXTURE_EXTERNAL_OES
[eglCodecCommon] **** ERROR unknown type 0x0 (glSizeof,73)
[OMXClient] Using client-side OMX mux.
[ACodec] [OMX.ffmpeg.h264.decoder] storeMetaDataInBuffers failed w/ err -2147483648
[ACodec] frameworks/av/media/libstagefright/ACodec.cpp:3813 CHECK_EQ( (status_t)OK,mCodec->initNativeWindow()) failed: 0 vs. -2147483648
[mono-rt] 
[mono-rt] Attempting native Android stacktrace:
[mono-rt] 
[mono-rt]   at ???+1735986 [0x95542d32]
[mono-rt] 
[mono-rt] =================================================================
[mono-rt] Got a SIGSEGV while executing native code. This usually indicates
[mono-rt] a fatal error in the mono runtime or one of the native libraries 
[mono-rt] used by your application.
[mono-rt] =================================================================
[mono-rt] 
[libc] Fatal signal 11 (SIGSEGV) at 0x00000004 (code=1), thread 1592 (CodecLooper)
Comment 9 Jason Smith [MSFT] 2015-07-01 02:49:04 UTC
Bumping priority to reflect new information
Comment 10 Jason Smith [MSFT] 2015-07-01 03:05:34 UTC
Are you able to cause the crash to happen without youtube/flash involved?
Comment 11 Jason Smith [MSFT] 2015-07-01 03:58:55 UTC
The issue with youtube crashing is unrelated to Xamarin.Forms. I can trivially reproduce the crash without Forms.

As for the navigation issue, this is due to the Url being set by javascript on youtube and not by actual navigation events. This is fine but it is somewhat hard to detect. I am trying something but it will have to wait for a feature release. I'm not entirely sure why android is giving out PageFinished events sometimes, iOS is more correct in its behavior of never changing.
Comment 12 roger.schmidlin 2015-07-01 04:34:42 UTC
I can understand, when you say it is not a Forms issue. But at the end of the day I'm using the WebView which is part of Forms. And my app is crashing using this Forms view. Please understand my side too. In the past it has worked randomly and at one stage it was even working on iOS. So there seem to be a way to get it to work. "Normal" web browsers seem to be able to.

I am really in big trouble not be able to use the Navigated events using youtube sites and even worse crashes in my app. My customer is not very happy. 

You talked about some ideas to get around this. Can you share this with me? Any other ideas how I could bypass this problem?

I simply just need to show a youtube page in my webview while tracking the users browsing. That shouldn't be too hard. What do you think.

Any help would be appreciated
Comment 13 Jason Smith [MSFT] 2015-07-01 04:39:51 UTC
When the feature lands, this will most likely be the correct way to handle this:

public partial class TestPage : ContentPage
    {
        Entry urlEntry;
        WebView simpleBrowser;

        public TestPage ()
        {
            //InitializeComponent ();
            StackLayout mainStackLayout = new StackLayout ();
            urlEntry = new Entry ();
            //urlEntry.Text = "http://xamarin.com";
			//urlEntry.Text = "https://www.youtube.com/watch?v=_Idra8rVS1I";
            urlEntry.HorizontalOptions = LayoutOptions.FillAndExpand;
            urlEntry.Completed += OnNavigationBarChanged;
            mainStackLayout.Children.Add (urlEntry);

            simpleBrowser = new WebView ();
            simpleBrowser.Navigated += OnNavigated;
            simpleBrowser.HorizontalOptions = LayoutOptions.FillAndExpand;
            simpleBrowser.VerticalOptions = LayoutOptions.FillAndExpand;
            simpleBrowser.MinimumWidthRequest = 100;
            simpleBrowser.MinimumHeightRequest = 100;
            simpleBrowser.Source = "https://www.youtube.com/watch?v=_Idra8rVS1I";
            mainStackLayout.Children.Add (simpleBrowser);

	        urlEntry.SetBinding (Entry.TextProperty, new Binding ("Source.Url", BindingMode.OneWay, source: simpleBrowser));

            Content = mainStackLayout;
        }

        void OnNavigated (object sender, WebNavigationEventArgs e)
        {
            Debug.WriteLine ("URL received after navigated: {0}", e.Url);
			//urlEntry.Text = e.Url;
        }

        void OnNavigationBarChanged (object sender, EventArgs e)
        {
            simpleBrowser.Source = urlEntry.Text;
        }
    }

Notice I am not using the navigated event because navigation is not happening. We wont simulate those events in the case of a javascript URL set because there is no way to simulate all of the features. I have this working locally and will add it for the next feature release.
Comment 14 roger.schmidlin 2015-07-01 04:52:34 UTC
Looks good to me. Do you have any ideas when the next feature release is going to be? I am really desperate!!! Or can I get a fix to this now?
Comment 15 Jason Smith [MSFT] 2015-07-01 05:07:56 UTC
Im sorry I don't know when the next feature release will be.

I have also built you a demo showing the simulator crash without forms.

If you simply change HardwareAccelerated = true, to false, it will stop crashing. Make sure you turn it back on before you ship as this is a simulator specific issue.
Comment 16 Jason Smith [MSFT] 2015-07-01 05:09:15 UTC
Created attachment 11795 [details]
Demo of non-Forms project crashing in same way
Comment 17 Jason Smith [MSFT] 2015-07-01 05:11:13 UTC
It is possible to work around your need with a renderer without much issue. Simply replace the WebViewClient with your own WebViewClient that proxies down to the client we create (otherwise you will break the webview) and make sure you handle the url updates.

Note there is no exact event for these javascript URL updates, so its a bit of an imprecise science.
Comment 18 Michael 2015-08-11 15:20:05 UTC
If anyone is curious how to implement what Jason Smith is referring to for creating our own WebViewClient (comment #17), I created a sample and posted it online. It shows how to capture the events that would be triggered through various events in WebViews. The solution is for iOS and Android.

https://github.com/xamarin/customer-success/tree/master/samples/Xamarin.Forms/FormsCustomWebViewClient
Comment 19 roger.schmidlin 2015-08-11 16:09:17 UTC
Great job Michael :) Thanks. That helps me a lot.
Comment 20 roger.schmidlin 2015-08-28 14:27:15 UTC
Actually, it doesn't work so well on iOS. Very random behavior. Works find though on Android.
Comment 21 roger.schmidlin 2015-08-30 03:25:29 UTC
I put my iOS solution in this thread
http://forums.xamarin.com/discussion/comment/149522#Comment_149522
Comment 22 Samantha Houts [MSFT] 2016-04-08 19:44:21 UTC
Thank you for taking the time to submit this feature request. We like this idea and have added it to our internal feature tracking system.

Warm regards,
Xamarin Forms Team