I'd like to disable some features of a web app I'm building, if the browser is Tor Browser. Can I inside the browser itself (client side, not server side) find out if the browser is Tor Browser?

I would prefer a solution that didn't issue any HTTP requests to match the browser's IP against Tor exit nodes.

Background: In my case, Tor Browser pops up a dialog that asks the user *"Should Tor Browser allow this website to extract HTML5 canvas image data?"*, because, says Tor Browser, canvas image data can be used to uniquely identify a browser.

**Update:** After reading the answers below: Perhaps the best solution in my case, is to keep a list of Tor exit nodes server side (an up-to-date list, refreshed periodically), and when a browser loads the page, I set a variable in a `<script>` tag, if the browser's IP matches such an exit node: `var isProbablyTorBrowser = true`. Then, client side, no additional requests, or complicated logic, is needed.
['https://Stackoverflow.com/questions/28200567', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/694469/']
The "official" way to detect tor is to check the user's IP address and see if it's a tor exit node. Tor runs [TorDNSEL](https://www.torproject.org/projects/tordnsel.html.en) for this purpose.

Here's a PHP implementation of a TorDNSEL lookup from a tutorial by [Irongeek](http://www.irongeek.com/i.php?page=security/detect-tor-exit-node-in-php)

```
function IsTorExitPoint(){
    if (gethostbyname(ReverseIPOctets($_SERVER['REMOTE_ADDR']).".".$_SERVER['SERVER_PORT'].".".ReverseIPOctets($_SERVER['SERVER_ADDR']).".ip-port.exitlist.torproject.org")=="127.0.0.2") {
        return true;
    } else {
        return false;
    } 
}

function ReverseIPOctets($inputip){
    $ipoc = explode(".",$inputip);
    return $ipoc[3].".".$ipoc[2].".".$ipoc[1].".".$ipoc[0];
}

```

If you're not using PHP, you should still be able to adapt this relatively easily.

***Another method of detecting Tor is to have a script download the list of Tor exit nodes every half hour or so, then check each user's IP address against that list. This may be less reliable, though, as not all exit nodes are published. There's a list you can use, and instructions, available at [dan.me.uk](https://www.dan.me.uk/tornodes).***

EDIT: Since you updated your question, the second option (a list you host locally) is going to be preferable.
There is no reliable way to detect the TOR Browser... That's kind of a goal of that browser. If you find a reliable way, chances are somebody else finds it too, tells the TOR developers and they close it.

E.g. all TOR Browser bundles report bogus, but reasonable User-Agents. The current release version e.g. says it is `Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0` no matter what OS you're actually using.

You may apply some heuristics to detect a TOR Browser with a certain probability, but will also generate some false-positives...

* Check the user agent. TOR Browser will report the latest Firefox ESR on a certain OS, currently Windows 7 32-bit (but some users might have changed that again and other users might simply use the ESR release but not the TOR Browser)
* Plugins are disabled, so `navigator.plugins` will be empty (but some users might have re-enabled plugins again).
* etc.
* Detect the browser actually [uses the TOR network](https://www.torproject.org/docs/faq-abuse.html.en#Bans).

Of course, you'll have to keep your checks up to date, so it requires a fair amount of maintenance busywork.

Personally, given the less than stellar detection results, maintenance burden and very modest experience improvements for users, I wouldn't try to handle TOR Browser differently at all.