bowser-js / bowser

a browser detector
Other
5.47k stars 485 forks source link

Short name 'edge' not working while full name 'Microsoft Edge' is #389

Open kevinhaas opened 4 years ago

kevinhaas commented 4 years ago

window.navigator.userAgent of the browser is:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299

And it's detected like:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299

However, the real name of the browser is: Microsoft Edge

I'm having an issue with the 'edge' short name, or perhaps I didn't understand the docs correctly.

With the above UA using bowser@2.8.1 the following code evaluates to false when using latest Microsoft Edge:

Bowser.getParser(window.navigator.userAgent).is('edge')

While the following code evaluates to true under the same conditions:

Bowser.getParser(window.navigator.userAgent).is('Microsoft Edge')

I am using 'chrome', 'firefox' and 'ie' short names in the same manner with no issues.

Thanks!

lancedikson commented 4 years ago

Hi, @kevinhaas! Thanks for the question and sorry for such a late answer. Having hectic times :D

Unfortunately, the Parser.is() method is not that flexible and doesn't reply to short names. Aliases work only with Parser.isBrowser() method: https://lancedikson.github.io/bowser/docs/Parser.html#isBrowser. I recommend using that one for now, and I think I'll fix the .is() method a bit later.

willamesoares commented 4 years ago

@lancedikson is the PR mentioned above an acceptable way of supporting the use case reported?

It's pretty much what isBrowser does with the includingAlias param and it was done in a backward compatible way by setting the default to false. Let me know and I can update the PR as needed.