Jump to main content
Menu

navigator Object

Considerations in Browser Detection

  • Browser detects should only be used as a last resort.
    • Object detection is preferable, but sometimes browsers "support" the same object but handle it differently so simply detecting the object is insufficient.
    • Sample object detection:
      if (document.querySelector) {
        // code involving document.querySelector
      }
      
    • Or the issue requiring browser-specific changes has nothing to do with object detection (such as navigation menus being off by a few pixels on Mac browsers, compared to Windows browsers).
    • If there is some other way to isolate a browser that is also preferable to browser detection. Some options:
    • These are better than browser detection because the user cannot turn them off or change them; the browser either matches the criteria or it does not.
  • No browser detection script will cover every user agent.
    • New browsers are introduced.
    • Existing browsers get updated and change their navigator details.
    • There are always obscure browsers being used.
    • As a result, you are continually updating your browser detection script and it is not always easy to go back and fix existing websites (you may not even realize they are "broken" for quite a while, unless a user reaches out to tell you).
  • There is always the risk of improperly detecting a browser.
    • This is termed a false positive.
    • The practice of websites using browser detection has made this problem more common, as it creates a need to change the user agent (and this can be changed via a browser plugin or in browser settings).
  • Server-side detection is more reliable than client-side detection, but is still far from perfect or reliable.
    • The client-side language (JavaScript) can be disabled, thus wiping out the detection.
    • Server-side detection occurs regardless (it cannot be disabled by the user). However, changes to the user agent string can still defeat this detection.
  • Browser detection can be impacted by third parties or have unanticipated effects on other parties.
    • Proxy servers sometimes scramble the user agent string, rendering the detection code useless.
    • Poorly written server-side browser detection could read a search engine spider's user agent string, not recognize it, and redirect the spider to an alternate version of the website or give them an error message. This behavior would potentially deal a serious blow to search engine ranking, because the indexing is derailed.