Scan Javascript for browser compatibility

UPDATE:

Have a look at the answer from Stephan Vierkant that shows a plugin to solve this problem.


There is no such tool, and there are a lot of browsers.

I think there is an alternative approach to scanning your code for compatibility to "all" browsers, although this truly would be a useful thing. Most people do the following two things to assure some degree of cross-browser compatibility.

Use a library

You can use a library like underscore.js, jQuery, Dojo, Modernizr, etc. that wrap browser incompatibilities for you. So you can for example use jQuery.inArray, which will work in all browsers that jQuery covers with a common interface for you to use.

Limit Browser support

Decide which browsers you want to support with your application, state this on your website, and then test in these browsers. Either natively if you have them, or use something like browserstack to do the testing for browsers you dont have. This answer also lists more alternatives for this.

And in the end there are best practices and personal experience to rely on when writing code.


You can use eslint-plugin-compat, a plugin for the ESlint linting utility. You can even use Browserlist to configure the browsers you want to support.

Nice animation about eslint-plugin-compat

Installation is very easy. You'll have to install eslint and this plugin:

npm install --save-dev eslint-plugin-compat

or

yarn add --dev eslint eslint-plugin-compat

And add a ESlint configuration file:

// .eslintrc
{
  "extends": ["plugin:compat/recommended"]
}

Add the supported browsers to your package.json file:

// sample configuration (package.json)
{
  // ...
  "browserslist": ["last 2 Chrome versions", "IE 11"],
}

And then run the linter:

eslint yourfile.js

In my case this was the output:

92:9   error  Promise.all() is not supported in IE 11  compat/compat
94:9   error  Promise.all() is not supported in IE 11  compat/compat

Update:

New link available for Javascript Compatibility Checker: https://seedmanc.github.io/jscc/


The checker is not available anymore.


Searching for the same question (after this couple of years), I bumped on the Javascript Compatibility Checker.

It gave me a hint on how compatible my script seems to be with the major browsers.