bowser-js / bowser

a browser detector
Other
5.5k stars 487 forks source link

iOS WKWebView UA does not provide a browser version. #418

Open DizzyDeveloper opened 4 years ago

DizzyDeveloper commented 4 years ago

This isn't an issue with bowser, more of a question about handling this scenario. The UA of an embedded webview in an iOS app does not provide a browser version, or browser technically but bowser defines it as Safari (which is actually quiet nice). This causes the satisfy constraint will fail.

window.navigator.userAgent of the browser is:

Mozilla/5.0 (iPhone; CPU iPhone OS 13_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148

And it's detected like Safari with an undefined version number. At the moment I have a nasty hack around, it injects a version number into parsedResult object to get the satisfy constraint to pass.... Has anyone else encounter this and/or solved it another way?

aw-pf commented 4 years ago

I am also finding this, I'm trying to create an iOS webview app for my companies intranet apps. Like you @DizzyDeveloper , I can easily think of a hack but I'd rather not if I can avoid it!

I've only noticed it in the Simulator on my Mac as I've not got as far as real device testing yet but I'm assuming it happens on-device as well.

nBollard commented 1 year ago

This isn't an issue with bowser, more of a question about handling this scenario. The UA of an embedded webview in an iOS app does not provide a browser version, or browser technically but bowser defines it as Safari (which is actually quiet nice). This causes the satisfy constraint will fail.

window.navigator.userAgent of the browser is:

Mozilla/5.0 (iPhone; CPU iPhone OS 13_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148

And it's detected like Safari with an undefined version number. At the moment I have a nasty hack around, it injects a version number into parsedResult object to get the satisfy constraint to pass.... Has anyone else encounter this and/or solved it another way?

You could check outside of the satisfies method for "Safari" and "undefined" and then set the result of satisfies to true. E.g. parser.getBrowserName() == bowser.BROWSER_MAP.safari && parser.getBrowserVersion() == undefined.

Or If you want to only allow some newer webviews you could specify by iOS version. Then set statisfies result. I assume WKWebView is tied to iOS version. This is my approach since I had a bug with web views on iOS 12. E.g. parser.getOSName() == bowser.OS_MAP.iOS && parser.getOSVersion() < '13'