Skip to content

Conversation

@pypt
Copy link
Contributor

@pypt pypt commented Nov 16, 2015

Some web servers (e.g. Facebook video) misinterpret the current User-Agent string as if the app was a feature phone and was only able to parse WML content, e.g.:

wp-android/4.7 (Android 6.0; en_US; <...>)

So, append "wp-android/" to the WebView's default User-Agent string and use it instead:

Mozilla/5.0 (Linux; Android 6.0; Android SDK built for x86_64 Build/MASTER; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/44.0.2403.119 Mobile Safari/537.36 wp-android/4.7

This pull request references iOS project's (PR: wordpress-mobile/WordPress-iOS/pull/4444, issue: wordpress-mobile/WordPress-iOS/issues/4295) problem with Facebook video embed code not loading properly because of a short-spoken User-Agent string.

While Android app itself doesn't have this problem (it uses its custom User-Agent only in a few select places), it would be neat to have the same UA format across projects for the sake of analytics.

pypt added 4 commits November 17, 2015 00:22
…ack to XHTML / WML.

Some web servers (e.g. Facebook video) misinterpret the current User-Agent
string as if the app was a feature phone and was only able to parse WML
content, e.g.:

wp-android/4.7 (Android 6.0; en_US; <...>)

So, append "wp-android/<version>" to the WebView's default "User-Agent"
string and use it instead:

Mozilla/5.0 (Linux; Android 6.0; Android SDK built for x86_64 Build/MASTER; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/44.0.2403.119 Mobile Safari/537.36 wp-android/4.7
@pypt
Copy link
Contributor Author

pypt commented Nov 17, 2015

Regarding UA detection libraries:

@daniloercoli: It should be OK with Jetpack UA detection library as long as Safari is not in the new UA string. (wordpress-mobile/WordPress-iOS#4444 (comment))

If the Android version of the patch is applied, the UA would contain both Safari and wp-android substrings. But again, custom UA is only used in a few places in Android code at the moment (ReaderWebView, WPDelayedHurlStack, WPRestClient, and XMLRPCClient).

@daniloercoli
Copy link
Contributor

@pypt - I commented on the iOS project It should be OK with Jetpack UA detection library as long as Safari is not in the new UA string. because of this
https://github.com/Automattic/jetpack/blob/master/class.jetpack-user-agent.php#L117

The function get_mobile_user_agent_name is used in a lot of places and first checks if it's an iphone (Safari + iphone strings in the UA), and then later it checks if the UA string belongs to the wp-ios app https://github.com/Automattic/jetpack/blob/master/class.jetpack-user-agent.php#L165

There should not be problems for Android.

Note for the reviewer: double check this :)

@maxme
Copy link
Contributor

maxme commented Nov 24, 2015

I've checked our internal tools, wpandroid user agent is always tested by the same kind of 0 === strpos( $ua, 'wp-android' ), so :shipit:!

maxme added a commit that referenced this pull request Nov 24, 2015
Use more detailed HTTP "User-Agent" header so web servers won't fallback to XHTML / WML
@maxme maxme merged commit 7605848 into wordpress-mobile:develop Nov 24, 2015
@pypt pypt deleted the issue/extended-user-agent branch November 24, 2015 16:11
@maxme maxme added this to the 4.9 milestone Dec 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants