tor.js – Minimal JavaScript library to check if your visitors are TOR users

If you don’t know that yet. The TOR browser is a privacy protecting web browser defending you against tracking and surveillance and helps to circumvent censorship.

Visiting the NYTimes via the TOR browser it annoyed me, that they are not automatically redirecting me to their .onion service.

So I checked out, if it is possible to check if the person currently visiting your website is a TOR user and if so redirect them to your .onion address? As the TOR project offers a list with all currently active exit nodes, it was actually quite easy to build.

This super small project downloads the list and checks if the IP of the current request is in that list. The generated JavaScript file contains a global variable telling if current visitor is using TOR.

There are also a few convenient functions included, so you could archive the bespoken automatically redirect with 2 line of code.

If you offer special services to TOR users or if you just wondering how many of your traffic come from TOR give this tiny library a go.

The library documentation can be found on and as the Project is Licensed Public Domain you are happily invited to host the PHP backend part yourself. Checkout the github repo for more information on that.

To never miss an article subscribe to my newsletter
No ads. One click unsubscribe.