New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-25462] Android: Implement Ti.UI.WebView.userAgent #9576
Conversation
ef52917
to
d1469c5
Compare
@@ -460,6 +460,10 @@ public void processProperties(KrollDict d) | |||
if (d.containsKey(TiC.PROPERTY_DISABLE_CONTEXT_MENU)) { | |||
disableContextMenu = TiConvert.toBoolean(d, TiC.PROPERTY_DISABLE_CONTEXT_MENU); | |||
} | |||
|
|||
if (d.containsKey(TiC.PROPERTY_USER_AGENT)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processProperties
is called after the creation of the native WebView and this causes a behavior that is a bit confusing - the WebView fires 'load' event twice. This seems to be an issue in chromium itself:
https://bugs.chromium.org/p/chromium/issues/detail?id=315891
Changing the UserAgent while loading a page provokes a reload. I could not find more recent discussion about that.
The result is that the test may fail because of that. The first 'load' event is delivered with an empty html and the UserAgent will never match the value from the creation dictionary.
Setting a userAgent
value from the creation dictionary when preparing the WebView settings before initializing it seems to avoid this:
https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiUIWebView.java#L301
Something like that maybe:
if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_USER_AGENT)) {
settings.setUserAgentString(TiConvert.toString(proxy.getProperty(TiC.PROPERTY_USER_AGENT)));
}
Still that leaves us with that undesired result when changing the UserAgent after the WebView has been created. I am not sure what is the behavior on iOS side:
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-property-userAgent
But does it make sense to set the property as Creation Only ?
CC: @hansemannn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ypbnv nice catch! I'll update the PR to use the creation dictionary 👍
it('userAgent', function (finish) { | ||
win = Ti.UI.createWindow({backgroundColor: 'gray'}); | ||
var webView = Ti.UI.createWebView({ | ||
url: 'http://whatsmyuseragent.org', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is with spaces for some of the next lines. Using tabs would match the rest of the file.
7eb14d3
to
4237876
Compare
@garymathews , when I run the test, I see 2 alerts one with no value before the webview loads & the other with the value |
b912f77
to
ff006d7
Compare
@lokeshchdhry Updated PR |
FR Passed. User Agent is set & detected successfully. Studio Ver: 4.10.0.201709271713 |
userAgent
property for parity with iOSTEST CASE
JIRA Ticket