Detecting what browser you are using?

Get help using Construct 2

Post » Tue Feb 24, 2015 12:56 pm

How can I detect which browser my app is being used in so that I may enable or disable features based on the result?
Some games: https://play.google.com/store/search?q= ... s&hl=en_GB Feel free to show the panda some support, he would appreciate it :)
B
19
S
5
G
1
Posts: 155
Reputation: 1,619

Post » Fri Feb 27, 2015 8:40 pm

Frosty Elk AB
www.frostyelk.se
Have no fear, We come in peace!
B
13
S
3
G
1
Posts: 106
Reputation: 1,169

Post » Fri Feb 27, 2015 10:23 pm

Its not that simple. Wish it was.
Some games: https://play.google.com/store/search?q= ... s&hl=en_GB Feel free to show the panda some support, he would appreciate it :)
B
19
S
5
G
1
Posts: 155
Reputation: 1,619

Post » Fri Feb 27, 2015 10:28 pm

I haven't tried it, but none of Name, Product, UserAgent or Vendor (or a combination) will do the job?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sat Feb 28, 2015 1:54 pm

Its un reliable apparently, I would like a way to disable audio on stock android phones, I was thinking of using the browser version for this but the general conversation is that this is not such a good test to do.
Some games: https://play.google.com/store/search?q= ... s&hl=en_GB Feel free to show the panda some support, he would appreciate it :)
B
19
S
5
G
1
Posts: 155
Reputation: 1,619

Post » Sat Feb 28, 2015 2:20 pm

good luck with that, this is normally what the useragent is supposed to report (the browser name and version), but since too many people tried to filter browsers in the past (not having them play audio, or not having them work at all for some really old websites), the result is that every browser tries to look like every other browser to be sure this kind of discrimination based on those infos cannot be done.

you may be able to find the default user agent string of the android stock browser somewhere though, still seen as a bad idea though.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
49
S
21
G
18
Posts: 2,115
Reputation: 16,904

Post » Sat Feb 28, 2015 2:23 pm

In general, enabling or disabling features depending on the browser is a very bad idea. You want to enable features depending on if the browser supports it, not if they are using a specific browser. For example suppose in 2012 you detected if the user was on Chrome, and only enabled Web Audio effects for that browser. Later Firefox adds support for Web Audio, and soon IE will as well, and you've unnecessarily crippled those browsers because you detected Chrome instead of Web Audio support.

You can detect the browser based on the user agent string, but all browsers pretend to be all other browsers because developers keep making that exact mistake over and over again. For example IE now pretends to be Chrome so developers who wrote browser tests instead of feature tests get fooled and enable the features which IE also supports. This makes it pretty hard to actually tell which browser it is from the user agent string. It's possible, but then if you do so, you're making exactly the same mistake all over again!

So don't do it. Think about the problem you are trying to solve and how to make it based on available features rather than the type of browser.
Scirra Founder
B
384
S
227
G
86
Posts: 24,143
Reputation: 190,784


Return to How do I....?

Who is online

Users browsing this forum: Cappu and 6 guests