How to detect browser TLS compatibility with JavaScript?

Sometimes, we want to detect browser TLS compatibility with JavaScript

In this article, we’ll look at how to detect browser TLS compatibility with JavaScript.

How to detect browser TLS compatibility with JavaScript?

To detect browser TLS compatibility with JavaScript, we can use How’s my SSL.

For instance, we write:

(async () => {
  const res = await fetch(`https://api.allorigins.win/get?url=${encodeURIComponent('http://www.howsmyssl.com/a/check')}`)
  const {
    contents
  } = await res.json()
  const data = JSON.parse(contents)
  const [versionName, versionNum] = data.tls_version.split(' ');
  if (versionName !== 'TLS' || versionNum < 1.2) {
    console.log('not secure')
  } else {
    console.log('secure')
  }
  console.log(data);
})()

We make a GET request to http://www.howsmyssl.com/a/check with fetch.

It doesn’t support CORS, so we’ve to use a CORS proxy to make a request to it.

Next, we get the versionName and versionNum from the data.

If versionName is 'TLS' and versioNum is 1.2 or bigger, then our browser is secure.

Conclusion

To detect browser TLS compatibility with JavaScript, we can use How’s my SSL.