kiwibrowser / src.next

Source-code for Kiwi Next, a Kiwi Browser auto-rebased with latest Chromium
BSD 3-Clause "New" or "Revised" License
2.2k stars 281 forks source link

Kiwi's UA #428

Open IcedWatermelonJuice opened 2 years ago

IcedWatermelonJuice commented 2 years ago

I want to distinguish between chrome and kiwi, but Kiwi's UA is so similar to chrome's that it is difficult to distinguish.

KaKi87 commented 2 years ago

Why would anyone want that, unless you'd want to maliciously and discriminatorily inflict degraded user experience to Kiwi Browser users ?

danny0838 commented 2 years ago

It is obvious that the essential of the user agent is to provide a meaningful expression of the user agent that is distinguishable from a different one. It is also very helpful for the developer to make the code more compatible to different browsers, which may have very different behaviors in some aspects that cannot be detected by any available API.

As a matter of fact, most Chomium-based browsers, such as Opera, Vilvadi, Brave, and new Edge, have a distinguishable UA from Chromium and Google Chrome. I don't think Kiwi is any different from them.

Although it is possible that some bad sites use the UA in a wrong malicious or discriminatory way, it should be relatively rare as breaking user experience is generally doing nothing good for the web site owner. There are also user agent switcher extensions available for customizing the UA for such special cases. IMHO, Faking the UA natively due to such reason is like throwing away the apple because of the core.

KaKi87 commented 2 years ago

It is also very helpful for the developer to make the code more compatible to different browsers

I would agree if we were talking about distinguishing browsers that use different rendering engines, like Chrome (Blink, formerly Webkit) vs Firefox (Quantum, formerly Gecko) vs Safari (Webkit).

But in this case, Kiwi uses Chrome, so everything that works on Chrome, must work on Kiwi, or be reported here. Therefore, there is no point in differenciating Kiwi from Chrome, unless you want to implement a dirty workaround.

Moreover, Kiwi Browser is the only open source Chromium-based Android browser that allows unlimited access to Chrome extensions, therefore hostile website developers would be more interested in discriminating it than others, especially to counteract content blockers.

danny0838 commented 2 years ago

There may be a difference so long as Kiwi is a different browser, even if it uses the same engine.

For example, can the bug I just reported in #427 be fixed? Are the developers willing to fix it? How long does it take to be fixed? If it can't be fixed in no time for any reason, there would be a need for the web site developer to use the user agent to deal with such issue for better browser compatibility. (Actually, the developers still need the UA to support the users that use the older browser versions with the bug unfixed even if it is fixed in the newer version...)

It might be possible that a feature detection can work for this, but not every bug can be dealt with feature detection. OTOH, if a feature detection is possible for such thing, a malicious site can also use it to do the same thing for a discriminatory purpose. After all, faking user agent won't actually work as long as there is any detectable feature difference among the different browsers.

gnadelwartz commented 2 years ago

feature or bug detection based on User-Agent is IMHO the worst thing a web developer can do. stick to Webstandards and common set of features. browser specific (JavaScript) implementation and bugs should be detected dynamically but not on UA., e.g. use https://modernizr.com/docs/

this is also the reason why Google had planned to remove UA https://www.infoq.com/news/2020/03/chrome-phasing-user-agent/

danny0838 commented 2 years ago

@gnadelwartz I agree that UA detection is generally the worst thing. Unfortunately, it is the only thing the developer can do in many cases, and many of them is what I have actually done in my projects.

About the point that "Google plans to remove UA": The User Agent Client Hints project Google has planned is to make a more accurate version of UA and make developers detect the user agent more easily, instead of making it impossible. This clearly is a dis-support instead of a support for the argument "UA is useless/bad".

gnadelwartz commented 2 years ago

let me phrase it this way: classic UA-string is exactly this: a string of unstructured content, you can try to extract information from but you will fail for whatever reason. relying on this random string is at least ugly.

UA hints are http response headers containing information in a well defined format, even it may a bad idea to use this for bug or feature detection, it is not based on parsing a random string.

as always opinions may vary

danny0838 commented 2 years ago

@gnadelwartz If I understand it correctly, this topic is about whether to provide a true user agent conventionally or to mimic/fake Chrome user agent, regardless of using the traditional UA or the new UA hints proposed by Google. What is your opinion about this?

gnadelwartz commented 2 years ago

I'm uncertain, as this may break random sites/parsing script's while the advantage is only for a small subset who want to optimize for kiwi.

e.g. kiwi has a special UA implemented for Facebook because Facebook parse UA instead of screen resolution. the downside iis that now Facebook Always redirect to mobile even I use kiwi on tablet.

in my opinion kiwi is 100% chromium with desktop features enabled on mobile, therefore it's valid to use chromium UA. non chromium compatible HTML/CSS/JS behvior as in #425 is a bug and must be fixed.

MTHS1901 commented 1 year ago

I did some tests comparing differences between "window" elements in Chrome PC/Android browser and Kiwi Browser, and for some reason in Kiwi Browser navigator.userAgentData.brands[2] is set to "undefined" so you could use the code below to set whether it is Kiwi browser or not.

!!chrome && navigator.userAgentData.brands[2] == undefined (if is true, you are on kiwi)

!!chrome && !!chrome.runtime no longer works, after 106 update.

foxjaw commented 10 months ago

Can anyone share how you guys change UA in Kiwi if possible ?