faisalman / ua-parser-js

UAParser.js - The Essential Tool for User-Agent Detection in JavaScript & Web Development.
https://uaparser.dev/
GNU Affero General Public License v3.0
8.85k stars 1.18k forks source link

Catch "Safari" and "Safari Mobile" in a single check #685

Open maphe opened 8 months ago

maphe commented 8 months ago

Is your feature request related to a problem? Please describe. Today is("Safari") is does not catch variants like Mobile Safari. That's one example I came across but now I'm wondering if I'm missing other cases.

Describe the solution you'd like It would be nice to have a helper function similar to is() but doing string matching instead of equality (eg. match()). I imagine that'd also help for Windows and Windows Phone and some other cases.

Describe alternatives you've considered Right now I'm doing is("Safari") || is("Mobile Safari") but that feels a little precarious.

Thanks

faisalman commented 8 months ago

Hi! Thanks for the suggestion, as a general rule, I'll consider to add a feature if there are enough users who need it as well.

In the mean time we can also use includes():

browser.name.includes("Safari")
maphe commented 8 months ago

Cool thanks, that's what I ended up doing but it is case-sensitive, which is() is a nice trick for.

Thanks for considering, and thank for the work.

aradalvand commented 6 months ago

Somewhat related question: Is Safari detected as Mobile Safari when device.type is tablet (i.e. in iPad)?