Page MenuHomePhabricator

SamsungBrowser is classified as "mobile" even when sending desktop user agent string
Closed, ResolvedPublic

Description

@IKhitron Can you try with https://doc.wikimedia.org/T403510/T403510-check.php in your three modes:

  1. regular mode where you prefer desktop,
  2. in your private browsing mode where you want desktop but it seems you are getting mobile,
  3. in regular mode after clicking "Mobile site" for that page), and share the results with me?

Specifically, the server-side user-agent string and what tokens it matches. If the client one is different, share the client ones too.

When SamsungBrowser on an Android tablet is configured to "Prefer desktop website" it sends the following user agent which resembles desktop Chrome on desktop Linux/X11.

User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/28.0 Chrome/130.0.0.0 Safari/537.36
Is-Mobile: Yes, user-agent contains Samsung.

However, we classify it as mobile because of the samsung token in the mobile_redirect regex in the Varnish configuration.

I suspect this originates from 2009/2010, when we first wrote these regexes, to match various obscure user agent strings on Samsung phones. This likely also involved an uncommon browser engine (i.e. not Chrome-based and if it used WebKit, it was probably not using a UA string based on Safari but its own custom one).

Nowadays, the "Android" claim and/or the "Mobile" token (Chrome Mobile, Mobile Safari) are standard and widespread in all browser engines which should suffice.

Let's figure out why this is here and then decide on a path forward. Maybe we don't remove it but limit it first to avoid false positives e.g. match generic "Samsung" except for "SamsungBrowser" (the modern app based on Chromium).

Event Timeline

Note that post-2013, the lineage diverges between what we have in Varnish for WMF vs what MobileFrontend ships for third-parties.

  • MobileFrontend: In 2016, change 314001 refactored DeviceDetection.php which included "samsung". This was originally added in 2013 with change 42348 which added DeviceDetection.php with the "samsung" token, along with other tokens imported from Wikimedia's Squid ACL.

Looking at the 2016 patch, I notice that, unlike in the 2013 patch, the refactor patch also removes test cases, and those mentioned an example and bug report for the samsung token. That test case traces back to a May 2013 patch by MaxSem, who added tons of great test cases and documented why they were added in change 61942, referencing T32827: Dolphin on Samsung Jet receives WAP content:

tests/DeviceDetectionTest.php
// https://bugzilla.wikimedia.org/show_bug.cgi?id=30827
'SAMSUNG-S8000/S800MXEJA1 SHP/VPP/R5 Jasmine/1.0 Nextreaming SMM-MMS/1.2.0 profile/MIDP-2.1 configuration/CLDC-1.1 SS-Widget/S8000-FM'
Krinkle updated the task description. (Show Details)

I think there is a problem. The option "use desktop sites only" on tablet does not work when opening some wikisite in private mode.

Which operating system, which version, which browser?

Samsung Galaxy Android 14 (Upside Down Cake), Open UI 6.1, Samsung Internet 28.0.5.9 (the last available).

What happen today when you visit sites that still use the old m-subdomains?

Enwiki opens Minerva with and without "m".

What happens on the new ones?

Ditto.

Everything looks fine outside of the Private mode.

[…] Is it specific to Wikimedia sites?

For example, these sites also have a mobile and desktop variant:

Both work well, including Private mode. […] Only Wikipedia started to be problematic today. Even if I click on "prefer mobile version" and after that "prefer desktop version" button, nothing happens. […]

[…]

For example, in YouTube: I can see the menu on the right. When clicking on "prefer mobile version", the layout changes, and the menu is on bottom line. When I click on "prefer desktop version", it returns to the previous layout, and the menu is on the right again. It happens the same in Public and in Private modes.

@IKhitron Can you try with https://doc.wikimedia.org/T403510/T403510-check.php in your three modes:

  1. regular mode where you prefer desktop,
  2. in your private browsing mode where you want desktop but it seems you are getting mobile,
  3. in regular mode after clicking "Mobile site" for that page), and share the results with me?

Specifically, the server-side user-agent string and what tokens it matches. If the client one is different, share the client ones too.

Here you are: P83447.

This is useful, thanks. Can you confirm once more on my test page that you get the same User-Agent string after pressing "Mobile site" in the Samsung app? This data says it is sending the desktop identification to the server no matter what. I would have expected that when you press that button, you get something mentioning "Android" instead of "Linux X11".

I ask because if your browser always sends the same UA string, and if our server is always classifying you as mobile, then we have a mystery as to how you are receiving the desktop site outside private browsing. I believe you wrote earlier:

  1. Things work fine on en.wikipedia.org (redirect to old-style mobile subdomain).
  2. Things work fine outside private browsing mode on new wikis like test.wikipedia.org.

If your data is correct, then the Samsung Internet app has a "Mobile site" button that does nothing. It sends the same desktop Linux user-agent string, no matter whether you push the button or not. If true, that is a bug you should report to Samsung, not Wikimedia.

Could it be that you've clicked on the "Desktop" link in the footer of some wiki sites, which sets an opt-in cookie to remember that you prefer desktop? This cookie is separate from the Samsung browser "Mobile site" / "Prefer desktop site" feature, and those opt-in cookies indeed would naturally not apply when you're in private browsing mode.

Perhaps you can clear cookies for wikipedia sites and then confirm the original behaviour once more. E.g. for both "en.wikipedia.org" and "test.wikipedia.org" 1) In regular mode where you prefer desktop, 2) In private browsing mode, 3) In regular mode where you ask for the "Mobile site".

Change #1190358 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/extensions/MobileFrontend@master] UADeviceDetector: Avoid "samsung" device token matching "SamsungBrowser"

https://gerrit.wikimedia.org/r/1190358

Change #1190359 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/extensions/MobileFrontend@master] phpunit: Fold SamsungSmartTV into main mobile/desktop data provider

https://gerrit.wikimedia.org/r/1190359

Change #1190361 had a related patch set uploaded (by Krinkle; author: Krinkle):

[operations/puppet@production] varnish: Expand samsung-related test fixtures

https://gerrit.wikimedia.org/r/1190361

Change #1190362 had a related patch set uploaded (by Krinkle; author: Krinkle):

[operations/puppet@production] varnish: Avoid "samsung" device token matching "SamsungBrowser"

https://gerrit.wikimedia.org/r/1190362

Not at all. I showed you what happens when I click Mobile site button, rhe one below every wiki page. When I'm pressing the button "prefer mobile version", provided by Samsung app, I get

User-Agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/28.0 Chrome/130.0.0.0 Safari/537.36

Is-Mobile: Yes, user-agent contains Android Samsung.

Client-side
User-Agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/28.0 Chrome/130.0.0.0 Safari/537.36

Is-Mobile: Yes, user-agent contains Android Samsung.

instead of (X11; Linux x86_64), so it does work differently.

maybe Samsung only changes the default viewport dimensions ?

maybe Samsung only changes the default viewport dimensions ?

We now have confirmation from @IKhitron that the user agent does change. I kind-of knew this already, because of these two examples:

[…] Is it specific to Wikimedia sites?

For example, these sites also have a mobile and desktop variant:

For example, in YouTube: I can see the menu on the right. When clicking on "prefer mobile version", the layout changes, and the menu is on bottom line. When I click on "prefer desktop version", it returns to the previous layout, and the menu is on the right again. It happens the same in Public and in Private modes.

I used these two sites as examples because these two sites vary those things server-side by user agent.

Yes, it does. Looks like I misunderstood the instructions.

I've updated https://doc.wikimedia.org/T403510/T403510-check.php with the above proposed patch.

@IKhitron Can you confirm that it now correctly toggles between Is-Mobile: Yes/No for your browser?

Can you confirm that it now correctly toggles between Is-Mobile: Yes/No for your browser?

Please explain me what exactly I need to do, so there will be not any problem as before.

Can you confirm that it now correctly toggles between Is-Mobile: Yes/No for your browser?

Please explain me what exactly I need to do, so there will be not any problem as before.

You can treat the "Is-Mobile: Yes/No" text as showing what Wikipedia will do (i.e. redirect/show mobile version, or show standard version). So through whatever browsing mode or buttons you want to use, you can observe whether it meets your expectations.

You could do the same three things as before:

  • Regular mode where you prefer desktop: It should say Is-Mobile: No.
  • Private mode where you expect desktop: It should say Is-Mobile: No.
  • After clicking "Mobile site": It should say Is-Mobile: Yes.

Previously, it always said "Yes" for your browser, which was wrong. With my bug fix, it should now understand the way SamsungBrowser describes its desktop/mobile mode.

  • After clicking "Mobile site": It should say Is-Mobile: Yes.

Clicking the button of Mediawiki or the button of Samsung Browser?

  • After clicking "Mobile site": It should say Is-Mobile: Yes.

Clicking the button of Mediawiki or the button of Samsung Browser?

Samsung Browser, when viewing https://doc.wikimedia.org/T403510/T403510-check.php.

Change #1190361 merged by BCornwall:

[operations/puppet@production] varnish: Expand samsung-related test fixtures

https://gerrit.wikimedia.org/r/1190361

Change #1190362 merged by BCornwall:

[operations/puppet@production] varnish: Avoid "samsung" device token matching "SamsungBrowser"

https://gerrit.wikimedia.org/r/1190362

@IKhitron Thank you. The fix is now live in production, including on https://he.wikipedia.org. Do you consider the original issue now resolved?

The option "use desktop sites only" on tablet does not work when opening some wikisite in private mode.

Krinkle triaged this task as High priority.

Absolutely, it works. Thanks a lot.

Change #1190358 merged by jenkins-bot:

[mediawiki/extensions/MobileFrontend@master] UADeviceDetector: Avoid "samsung" device token matching "SamsungBrowser"

https://gerrit.wikimedia.org/r/1190358

Change #1190359 merged by jenkins-bot:

[mediawiki/extensions/MobileFrontend@master] phpunit: Fold SamsungSmartTV into main mobile/desktop data provider

https://gerrit.wikimedia.org/r/1190359