donatj / PhpUserAgent

Lightning Fast, Minimalist PHP User Agent String Parser.
https://donatstudios.com/PHP-Parser-HTTP_USER_AGENT
MIT License
565 stars 128 forks source link

Consistent detection of "Safari shells" in iOS #84

Open igorsantos07 opened 2 years ago

igorsantos07 commented 2 years ago

After giving up on some "simple regex" to detect common browsers (yep, you know for which project lol), I landed in this library :) Thus, I already had a bunch of UA strings to test against; I noticed that, while iPhone/CriOS is detected as Chrome on iPhone, FxiOS and EdgiOS end up simply as Safari.

This seems related to #40 since there might not be much value on distinguishing them all, but looking from a statistical POV, it would make some sense to separate the shells from the actual Safari. Besides that, consistency is always good :)

Samples:

Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/103.0.5060.63 Mobile/15E148 Safari/604.1
Mozilla/5.0 (iPad; CPU OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/103.0.5060.63 Mobile/15E148 Safari/604.1
Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/101.0 Mobile/15E148 Safari/605.1.15
Mozilla/5.0 (iPad; CPU OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/101.0 Mobile/15E148 Safari/605.1.15
Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 EdgiOS/100.1185.50 Mobile/15E148 Safari/605.1.15
donatj commented 2 years ago

I've gone back and forth and back and forth on how to handle iOS browsers. It's a complex issue with no right answer.

As you've seen, thus far I've just landed on just not handling them to and letting them be parsed as Safari.

I've got two groups of people who use this

a. people who use it for deploying features by browser b. people who use it for stats/analytics

I suspect for the majority of users, not parsing them is in their best interest -

If I called CriOS "Chrome", someone offering up a feature only available on Chrome could be burned because CriOS isn't actually Chrome and doesn't behave like Chrome.

On the other hand people using it for analytics might be burned because they get inflated states for Chrome use, despite it actually being Safari, so they invest more time in optimizing for Chrome and not enough time optimizing for Safari that people are actually running.

As for the specific advantages of detecting them, there are certainly going to be people specifically targeting features towards specific Safari wrapping pseudo-browsers - I imagine propper feature detection is more optimal in these cases.

As for the stats people, I don't know why you'd actually care what Safari wrapper they're running, it doesn't really affect you?

Please push back though, this is just the state of my thinking currently. I'm more than happy to hear you out.

igorsantos07 commented 2 years ago

If I called CriOS "Chrome", someone offering up a feature only available on Chrome could be burned because CriOS isn't actually Chrome and doesn't behave like Chrome. This makes total sense. It would definitely be misleading.

And indeed... not sure how useful it is to know what browser the person uses, if in the end the actual data is "how to support our users".

That all said.......... I'm really reporting a bug in this topic :sweat_smile: CriOS is reported as iPhone Chrome, while the others go as Safari, as it would make more sense.

donatj commented 2 years ago

I'm really reporting a bug in this topic πŸ˜… CriOS is reported as iPhone Chrome, while the others go as Safari, as it would make more sense.

HAH - I need to work on my reading comprehension πŸ˜† I feel like a dork now. I didn't realize that was the case… let me get back to you…

igorsantos07 commented 2 years ago

~There's a translation happening here.~

~I guess EdgiOS and FxiOS should also be included in that array?~

Seems I just copy-pasted without reading lol nvm

donatj commented 2 years ago

I guess EdgiOS and FxiOS should also be included in that array?

See, that's the question. You're completely right, the inconsistency sucks. I don't know how or why I did that.

My gut says this means I need to add iOS Firefox and Edge, but my heart says I should drop Chrome πŸ˜†

igorsantos07 commented 2 years ago

I'm not exactly sure what's going on, I didn't took the time to fully grasp the codebase. Anyhow, I would guess by the time you coded the CriOS override, FxiOS and EdgiOS weren't available yet, so we could guess it's just outdated?

Another idea, as to cater to that duality you face, is adding an option to the class instance (or parse() call, so it feeds directly to the procedural function), like parse($keepSimilars = false). Go with the default behavior the library currently has (if I understood it righ) - which is to translate all "similar browsers" to their original counterparts (e.g. IceWeasel to Firefox, CriOS to Chrome, and add EdgiOS/FxiOS to the bucket), and then allow the user to request that all similar browsers are kept as-is, so the library can better serve their statistical purposes. Does that make any sense?

igorsantos07 commented 1 year ago

Fun fact: a while after the discovery of your fake clone, I stumbled upon this dependency on the project and realized I was kinda talking to you here as if you were really working with us (re: "yep you know for which project" in the description and all) πŸ€¦β€β™‚οΈ

Anyhow, at least I didn't include this because of the other guy, it was just a coincidence. I guess I should've asked him for help, instead of formally opening this issue lol

donatj commented 1 year ago

a while after the discovery of your fake clone, I stumbled upon this dependency

My fake clone?

igorsantos07 commented 1 year ago

Yep...... That person that was working at a company (or more?) using your name?

On Tue, Jan 24, 2023, 23:44 Jesse Donat @.***> wrote:

a while after the discovery of your fake clone, I stumbled upon this dependency

My fake clone?

β€” Reply to this email directly, view it on GitHub https://github.com/donatj/PhpUserAgent/issues/84#issuecomment-1403021329, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEB6S4GRLYZ35XNIPR3DVLWUCHQFANCNFSM52AYVTBA . You are receiving this because you authored the thread.Message ID: @.***>

donatj commented 1 year ago

Oh, I see. You worked with the person who stole my identity! Did you work for one of the two companies that have already reached out to me - or is there a third I’m just learning about now?

igorsantos07 commented 1 year ago

πŸ˜‚ πŸ˜‚ Yep! It's the most recent one, which got in touch with you earlier this month (or around that).

Not sure if you found the other GitHub, but... It's donatij lol

Igor Santos -- Desenvolvedor Web [enviado do meu celular]

On Wed, Jan 25, 2023, 03:06 Jesse Donat @.***> wrote:

Oh, I see. You worked with the person who stole my identity! Did you work for one of the two companies that have already reached out to me - or is there a third I’m just learning about now?

β€” Reply to this email directly, view it on GitHub https://github.com/donatj/PhpUserAgent/issues/84#issuecomment-1403139698, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEB6S2TJJGHM54WMY426TLWUC7FXANCNFSM52AYVTBA . You are receiving this because you authored the thread.Message ID: @.***>

donatj commented 1 year ago

Thanks for the heads up. I contacted GitHub and their account is already gone. It was really quick.

igorsantos07 commented 1 year ago

Wow, that was really fast indeed! Glad it works that way. Better luck in the future, man! And congrats for being so good that you're being copied around πŸ˜‚

Igor Santos Web Developer / Community Leader @ Toptal - top 3% of freelancer talent http://www.toptal.com/#obtain-only-eye-opening-coders-now igorsantos.com.br http://www.igorsantos.com.br

On Wed, Jan 25, 2023 at 11:34 AM Jesse Donat @.***> wrote:

Thanks for the heads up. I contacted GitHub and their account is already gone. It was really quick.

β€” Reply to this email directly, view it on GitHub https://github.com/donatj/PhpUserAgent/issues/84#issuecomment-1403716685, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEB6SYXZP26KY4DBFJ6XITWUE2XVANCNFSM52AYVTBA . You are receiving this because you authored the thread.Message ID: @.***>