Is there a way to detect on which browser i'm using.. HTML5 target


i am making an HTML5 game for desktop only not mobile… But i am having an performance issue on firefox. on chrome and opera its pretty okay. So i was wandering if there’s a way to detect on which browser im in? How to implement it. thnx

Sound Issues HTML5


import js.Browser;

Which prints the user agent for me

You can find out more here:


How to make it on If statement?
i’ve try this Does not work.

if ((Browser.navigator.userAgent)==“Chrome”){
trace("Chrome it is! ");
trace(“not Chrome”);

i guess im doing it wrong… sorry newbie here.


Hi jathan,

have you traced out the userAgent variable? It actually contains a more complex string. Also many browsers obfuscate their true identity by pretending to be a different agent in hopes to improve compatibility with many sites out there. Usually people don’t suggest detecting browsers but features instead.

I had a look online how JS web developers solve this and found this solution

I converted their regular expression example to Haxe code for you. It uses regular expressions.

trace("userAgent: "+Browser.navigator.userAgent);
trace("vendor: "+Browser.navigator.vendor);

var isChrome:Bool = (~/Chrome/).match( Browser.navigator.userAgent) && (~/Google Inc/).match( Browser.navigator.vendor);

trace("isChrome: "+isChrome);

Here is the trace output results in my Chrome browser

So what happens in this code?

The actual strings that the userAgent and vendor return are quite detailed, using a regular expression we can test if the string matches the regular expression. For example the regular expression


Checks if the passed on string contains the string ‘Chrome’. And the other regular expression checks if the vendor string contains the string ‘Google Inc’. You can read more about regular expressions here:
Haxe Regular Expressions


An alternative way of detecting if a string contains a substring is

if( Browser.navigator.userAgent.indexOf("Chrome") != -1 ){ }

This looks up the string “Chrome” and returns the index (position) if found, if not found it returns -1. So checking if it is not -1 essentially means does it contain “Chrome”.

Hope this explains and helps you


shoot! Thnx renderhjs… i will look for this later,thank you so much for your time.


Mind you, Opera Browser uses Blink (just like Chrome) and there are other browsers that behave similarly, so be cautious about how this information is used :slight_smile:



Yes, i Notice after i tested,it gave me the same output when i run it on Chrome and opera.


Okay, well that’s probably fine for most functionality