Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check current browser against the list of supported ones

We have a list of browsers we test our webapp in. I have a task to notify the user if his browser isn't supported or tested to work well with our app.

We have a browserslist configuration in the project and I'm looking for a way to test current browser against the list. I tried browserlist-useragent but we can't compile it with webpack due to the fact it uses net, fs, tls and other native node modules we don't want to include in our bundle.

Is there any better way do avoid copying the list of supported browsers in many different places and just use browserlist configuration that already exists to detect if user uses supported one or not?

like image 537
Elessar.perm Avatar asked Feb 15 '18 13:02

Elessar.perm


People also ask

How do I know what my browser is?

In the menu bar at the top of your screen, click Help and then select About Internet Explorer. The browser version will be displayed on the screen. Or: On the upper-right corner of the browser window, click the gear icon.

How do I know which browser client to use?

To detect user browser information we use the navigator. userAgent property. And then we match with the browser name to identify the user browser. Now call this JS function on page load, and this will display the user browser name on page load.

What is a supported browser?

Supported Web Browser means the current release of Microsoft Edge, Mozilla Firefox, Google Chrome, Apple Safari, or any other web browser that the Provider agrees in writing shall be supported.

How do I find my browser name and version?

appName returns the string “Mozilla Firefox”. If it is Edge, navigator. appName returns the string “Microsoft Edge”. Using both objects, we can create an alert box to display what web browser the client is using and this navigator object contain all the information about web browser version, name, and more.


1 Answers

I'd consider using this "utility" package https://github.com/browserslist/browserslist-useragent-regexp in the project that uses browserslist, and then use the file generated by the script suggested by this package to then use anywhere else. In reality, all you want is the regex in the generated file. This can be placed in any client or server code you need for browser detection. I've placed mine in some classic asp.

Also note that on a Windows PC, the instructions provided don't result in a file containing a RegEx. Instead, you'd need to run npx browserslist-useragent-regexp --allowHigherVersions to display a suitable RegEx on your console, and then add that where needed.

like image 133
Shiraz Avatar answered Jan 03 '23 22:01

Shiraz