Mootools conflicting with FB.ui (Uncaught TypeError: Cannot read property ‘className’ of undefined)

I just spent a few hours running down a gnarly bug that became an issue on production late last night.  All of the FB.ui dialog calls began to fail on our website with a Javascript exception.

After much trial and error, I was able to determine that Mootools was the root cause.  Without Mootools, everything worked.  With Mootools – whether it’s 1.2 or 1.3.2 – this exception gets thrown:

Uncaught TypeError: Cannot read property ‘className’ of undefined

Then I went in and took a while to make Facebook JS SDK’s all.js human readable so I can step through it and actually understand what’s going on.  It turns out that things blow up when FB.Dialog.create is called, and Mootools had an old, deprecated override on Function.create.

Since we don’t use Function.create anywhere else in the code, I went ahead and commented out and it worked like a charm.  In the uncompressed version of Mootools 1.3.2 source, it’s at line 918.  Or you can search for “Function.implement({” and then take out the create function.

Hope this helps… and hope it saves you guys some time!

This entry was posted in Development and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

12 Comments

  1. Jacob
    Posted July 9, 2011 at 8:24 pm | Permalink

    Fought with this all stinking day yesterday. Your fix works. Unfortunately we have code that is dependent on that method in mootools. Definitely helps give me a place to focus a solution on.

  2. Posted July 9, 2011 at 10:37 pm | Permalink

    :P Thanks!!

  3. Goutte
    Posted July 12, 2011 at 5:52 am | Permalink

    Thanks for the tip, you saved my day !

    I never suspected Mootools (because it is javascript goodness) and accused facebook… Well, eviler things get singled out first ! Maybe next time I’ll be less narrow-minded. Cheers !

  4. Alexandre Paulo
    Posted July 18, 2011 at 11:04 am | Permalink

    You saved my life!

    Thanks to your tip I went to http://mootools.net/download and downloaded “MooTools Core 1.3.2 without compatibility” and it seems to be working fine… so far… until FB plays another trick on us…

  5. Posted July 23, 2011 at 4:58 am | Permalink

    Oh God thank you! I was going crazy trying to fix this, you saved me :)

    • Posted August 15, 2011 at 7:28 am | Permalink

      Thought I’d throw in here to comment on the “Making JS SDK Human Readable”. I am dealing with a similar bug it would seem messing with FB.apply on the registration plugin, and was doing a search for the uncompressed version of the SDK, and I found this blog post.
      TO THE POINT:
      In chrome while I have the console open, there a few little icons on the bottom left of the browser window. One of them is a set of curly braces “{}” and its called ‘Pretty Print’ . Click it and Voila! Human readable Javascript! GREAT!

  6. Posted August 24, 2011 at 9:52 pm | Permalink

    Cannot read property ‘className’ of null all.js –>nice fix

  7. Posted September 30, 2011 at 12:31 pm | Permalink

    Thank you very much for taking the time to solve this one, and especially to post about it. You have saved me a lot of time, and I really appreciate it!

  8. Posted December 23, 2011 at 3:18 pm | Permalink

    Oh finally!! You saved my life.

  9. Daffy
    Posted January 31, 2012 at 2:56 pm | Permalink

    I am not using MooTools and still getting this error. I am using jQuery 1.6.1 and no other javascript libs. Any Idea/help is appreciated..

    • Shawn
      Posted February 8, 2012 at 4:59 pm | Permalink

      I haven’t ran into this problem with jQuery, but if I do come across it I’ll post an update here.

  10. Manish
    Posted March 19, 2012 at 3:01 am | Permalink

    Thanks man, you saved my hrs.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>