Ideally, you'll be able to reach a solution that works on all browsers, since browser detection is not very reliable unless you use comercial solutions like
WURFL, or
DeviceAtlas.
That being said, browser detection is usually done by parsing the user agent string that is sent with a HTTP request and comparing it to known patterns used by browsers. If you open the
Silk UI Framework, it contains an action (that isn't public), called
detectBrowser and it does just that. I bet that action isn't public because it is not reliable, though.