10

Because the canvas bug of samsung stock browser, my program will cause error. (http://code.google.com/p/android/issues/detail?id=39247)

So I want to disable canvas on all Samsung stock browser.

Could I detect it by navigator object or other way?

I found the same question, but it's solution looks like not perfect (javascript - regex matching devices on user agent)

Wiki shows Samsung has more models. (http://en.wikipedia.org/wiki/Samsung_Galaxy_S_III)

Community
  • 1
  • 1
Sam
  • 615
  • 2
  • 6
  • 20
  • use feature detection, not browser sniffing. Is easier and what happens if next week's Samsung comes out supporting it? – charlietfl Feb 19 '13 at 02:31
  • 1
    But it supports Canvas, it just has a bug. – Sam Feb 19 '13 at 02:35
  • 1
    can likely build a support test regardless, then when bug is fixed you won't be excludung those users – charlietfl Feb 19 '13 at 02:37
  • @charlietfl feature detection doesn't always work, for example the samsung stock browser gives a lot of false positives – Josh Dec 20 '13 at 20:52

5 Answers5

7

You can simply do this

var isSamsungBrowser = navigator.userAgent.match(/SamsungBrowser/i)
imal hasaranga perera
  • 7,622
  • 2
  • 44
  • 35
4

The following regex covers almost all Samsung mobile devices.

if(navigator.userAgent.match(/SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i)) {
    console.log("it's Samsung");
    // your code for Samsung Smartphones goes here...
}
Diego Vieira
  • 1,166
  • 2
  • 13
  • 31
Anulal S
  • 5,824
  • 5
  • 21
  • 31
0

using the userAgent is enough to detect this bug. Look for the string 534.30. For instance:

  if (window.navigator && window.navigator.userAgent.indexOf('534.30') > 0) {
    // Clear the canvas a different way because they are using a known-bad version of the default android browser
  }
Simon Sarris
  • 58,131
  • 13
  • 128
  • 161
  • Thanks. Does the number '534.30' represents WebKit version? If it is, other mobile manufacturers may have this number in userAgent, too. – Sam Apr 11 '13 at 00:37
  • Yes, and one not used by Chrome Mobile. You could check for both that number and webkit, to be safer. But you can only ever be "really mostly safe" about it. – Simon Sarris Apr 11 '13 at 17:18
  • 1
    Thanks. But it doesn't solve my problem. Other Android manufacturers may be detected the same version, not only Samsung. I have tested my Canvas program on Asus and HTC stock browser, it works great! Only Samsung has this canvas problem. – Sam Apr 12 '13 at 03:00
0

Some samsung user agents have the word "samsung" in them. If you find "samsung" in the user agent string it's a good indicator. However, most samsung user agents I looked at didn't contain the word samsung. But there is a different check, all samsung model numbers (so far) are in the format "GT-xxxxxx" so we check for the user agent having "android" in, followed by "GT-" somewhere in the UA. (or the word samsung...) This is obviously a little slack but seems to catch them ok so far....

0

I think it can be ok:

const isSamsungBrowser = navigator.userAgent.indexOf('SamsungBrowser') > - 1