This project is archived and is in readonly mode.

#1158 ✓resolved

Browser detection fails

Reported by DeveloperChris | January 28th, 2011 @ 06:25 AM | in 1.3.1 (closed)

because browser detection relies on a regex on the useragent string it can fail if the string is not 'valid'

to bypass some rather restrictive firewall rules that would prevent me working I have munged my UA to include "ie 1"

thus mootools has decided I use Internet explorer and consequently fails when using ie specific code such as clearAttributes. This prevents me from working on Joomla.

the offending code is

UA = ua.match(/(opera|ie|firefox|chrome|version)\s\/:?.*?(safari|version\s\/:|$)/) || [null, 'unknown', 0],

Comments and changes to this ticket

  • Christoph Pojer

    Christoph Pojer February 2nd, 2011 @ 08:00 PM

    • State changed from “new” to “resolved”
    • Milestone set to 1.3.1
    • Assigned user set to “Christoph Pojer”
    • Milestone order changed from “877” to “0”

    I think this request makes sense in the way of putting the shortest string that is to be matched at the end. It doesn't affect other browsers and we will include it for 1.3.1.

    In any case, you should try not to modify your user agent.

  • Thomas Aylott
  • DeveloperChris

    DeveloperChris February 2nd, 2011 @ 11:03 PM

    User Agent matching is an unreliable method. the best way to my knowledge is feature or object detection.

    It is impractical to tell users not to modify their UA string. In my case its the only way I can get work done. many people have their ua's changed for other reasons.

    I know you are aiming for simple and light and I agree with the philosophy. but if simple and light = broken then is it the right thing to do?

    I suggest at the very least changing the detection string to 'MSIE' which is more likely to be correct and less likely to be misinterpreted if the user has loaded a browser module with 'ie' in its name.
    you will see from this page MSIE has been a in every version of IE since version 2.0

    String detection assumes you know every browser and its features. this immediately breaks for users with new or unusual browsers. with feature or object detection the problem simply goes away.

    For example in the case of my problem with the very popular joomla project.

    The code
    if (domobj.clearAttributes) domobj.clearAttributes(); works.

    In fact I note that very method is used elsewhere within mootools.core, namely the clear function.


  • Jan Kassens

    Jan Kassens February 2nd, 2011 @ 11:33 PM

    The UA detection is only there to detect the browser. Where it's possible feature detection is used in MooTools.

    The way feature -> browser proved fragile when Firefox removed a feature we used to detect Firefox.

  • Christoph Pojer

    Christoph Pojer February 2nd, 2011 @ 11:44 PM

    I had some error in my thinking earlier, haven't done a lot of MooTools/JavaScript in the past weeks.

    Anyway, I suppose your issue is coming from the Element.clone method and I have changed it to use feature detection of the clearAttributes method:

    This should resolve your issue, we don't have a lot of browser sniffs in mootools any more - in some cases its unavoidable however. Please confirm that your issue is fixed.

  • DeveloperChris

    DeveloperChris February 3rd, 2011 @ 12:23 AM

    That does fix the immediate issue.

    It seems that browser detection is used a fair bit, if you search for '' it returns many results and as it may well be wrong I must assume it will cause other problems, though as its my first use of Joomla and hence mootools, I don't know what other issues are looming.

    Unfortunately browser detection is not foolproof, That's why feature detection adds strength.. and unfortunately code. if a feature is not available you should degrade the function gracefully.

    Your example of Firefox is a perfect example of why one would use feature detection rather than browser detection. As long as the browser has the function (assuming different browsers implement the same named function in the same way) then it doesn't matter which browser the person is using.


  • Christoph Pojer

    Christoph Pojer February 3rd, 2011 @ 12:32 AM

    To be fair everyone used to have browser sniffs for this kind of stuff, we have changed this in MooTools Core 1.3 and we now heavily rely on feature detection. The previous method of sniffs was present in almost all libraries at the time we introduced them (which was in about 2006..).

    We still have a few sniffs in there because some features are impossible to detect. In any case, the remaining sniffs are trivial and won't alter the behavior of MooTools as a whole. Thanks for bringing this particular one to our mind, we appreciate the pointers :)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Referenced by