A tiny bug in Prototype JS leads to major incompatibility with Facebook JS client library

0

I have been working on a Facebook application using their all-new JavaScript
client library. I was trying to reuse a large self-contained module that relied
heavily on prototype & scriptaculous JS libraries. The module was working
just fine outside the context of the Facebook application. But after including
the Facebook JS library, runtime JS errors began to appear, especially when
initiating a scriptaculous effect. Obviously, that was concluded as to be a
compatibility issue between the prototype & scriptacuolous family on one
side, and the Facebook JS client library on the other.

The origin of incompatibility, courtesy of Mohammad Ali, was discovered to
be a tiny bug in Prototype’s browser identification. To date, the problem was
discovered to be as follows:

  • Prototype identifies the
    browser as IE according to the presence of the IE specific function
    ‘attachEvent’. In prototype.js line 13:
  • Obviously, this condition is
    fragile, and will fail if any other included script defines a
    "window.attachEvent" function for any other browser, which is
    the exact case of Facebook JS client library.
  • The Facebook library contains
    the following line (FacebookApi.debug.js line 387):

    This code is embedded in an if-condition that it is only executed
    if the browser is not IE.


  • The function "_loadMozillaCompat"
    defines "window.attachEvent" for Mozilla browser type, which
    causes Prototype’s IE identification condition to fail, leading to a total
    mess up in many cases.

  • The solution introduced by
    our JS guru, oldmoe, is to power up Prototype’s IE identification
    condition, by adding a check that the browser is not Mozilla. The new
    condition looks like this… and it works :)

This will do it for this specific incompatibility instance. However, the
sure thing is that the foundation of Prototype’s browser identification needs a
basic tweak to be concrete against other libraries.

Post a Comment

eSpace podcast Prodcast

RSS iTunes