Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26325] Android: Ti.UI.WebView not firing events in 7.x

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-08-21T20:06:07.000+0000
Affected Version/sRelease 7.0.0, Release 7.1.1, Release 7.3.0, Release 7.2.1
Fix Version/sRelease 7.3.1
ComponentsAndroid
Labelsandroid, events, issue, webview
Reporterkedomuz
AssigneeChristopher Williams
Created2018-08-20T21:20:29.000+0000
Updated2018-08-23T09:41:35.000+0000

Description

Setting custom UserAgent for WebView (Android) causes WebView to not fire events (ex. load, beforeLoad and etc.).Using default UserAgent - expected behaviour, events firing.

Comments

  1. Rakhi Mitro 2018-08-21

    Hello, Thanks for sharing with us. Are you experiencing this in all android devices? It would be great if you can share a simple test case to reproduce this on our end.
  2. Hans Knöchel 2018-08-21

    Also, is this happening on SDK 7.3.0 only? Could you do me a favor and check if it worked on 7.2.0.GA? Moving to TIMOB already.
  3. kedomuz 2018-08-21

    Cannot edit this issue description anymore, message appeared - no permissions. Latest SDK i used 6.2.2 GA, as it was very stable, now just installed 7.3.0 GA, i have no 7.2.0 GA. Example for this issue:
       $.webview.setUserAgent('Mozilla/5.0 (Linux; Android 6.0.1; SM-G920V Build/MMB29K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36');
       $.webview.url = "https://google.com";
       //also $.webview.setUrl("https://google.com") have the same unexpected behaviour - events are not firing
       
  4. Hans Knöchel 2018-08-21

    This is a regression of [this commit](https://github.com/appcelerator/titanium_mobile/commit/ff006d7bd16d61fcca3aefee67cb28970c05a5e6) and is happening since 7.0.0 (via TIMOB-25462), assigning to [~gmathews].
  5. Christopher Williams 2018-08-21

    This is certainly related to TIMOB-25462:
       // TIMOB-25462: minor 'hack' to prevent 'beforeload' and 'load' being
       // called when the user-agent has been changed, this is a chromium bug
       // https://bugs.chromium.org/p/chromium/issues/detail?id=315891
       public boolean hasSetUserAgent = false;
       
    I think this "hack" is causing the bug experienced here. I think the important thing here is: - The user agent should be set earlier in processProperties, before we attempt to set the URL/content to avoid a reload. (Maybe it doesn't matter? It's not the use case triggered here) - If the developer sets the user agent after the web view is up, I think it makes sense to reload and potentially get 2 load/beforeLoad events. Websites can offer different content based on a user agent, which is likely why Chromium does the reload. So, to avoid the double events, developers should set the user agent in the creation properties. - If we still want to keep a hack flag around for the post-load change, then I think we need the hack to be smarter and have it track event count per url. Right now it looks like we basically just swap the flag after the first load. My personal preference is to remove this "hack", and add a note in the docs about point #2 above: set the user agent in the creation dictionary to avoid a reload/multiple events firing (as changing user agent can trigger a reload). cc [~gmathews] [~ybanev]
  6. Yordan Banev 2018-08-21

    I am OK with reverting the "hack" part and describing the behavior resulting from changing the userAgent after the proxy creation in the documentation.
  7. Christopher Williams 2018-08-21

    7_3_X: https://github.com/appcelerator/titanium_mobile/pull/10273
  8. Christopher Williams 2018-08-21

    Merged to 7_3_X and master.
  9. Keerthi Mahalingam 2018-08-22

    Verified the fix in SDK 7.3.1.v20180822075516. Closing.

JSON Source