dimanche 31 mai 2020

How can I use the user agent string for browser detection if the strings include information about more than one browser?

I want to use the user agent string to determine what browser the user is coming from (specifically interested in whether the user is using Chrome). There is a section of the MDN web doc on user agents that says "...to detect Safari you have to check for the Safari string and the absence of the Chrome string". But a Safari user agent string looks something like this: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36. It seems like Chrome user agent strings look similar and also include information about the Safari version. How can I distinguish between the two?

I know using the UA string for browser detection is not recommended but unfortunately I need to do it this way for a project I am working on.




Aucun commentaire:

Enregistrer un commentaire