Home > programming > Using prototype.js in chrome

Using prototype.js in chrome

February 9th, 2007 Leave a comment Go to comments

Are you writing a Firefox/Thunderbird extension, or maybe a XULRunner app, and want to make use of the Prototype JS library? Then you will run into this issue.

Because of a long-standing bug in Mozilla, Function.prototype cannot be extended with the method ‘bind’, and so all the utilities in Prototype.js that make use of bind() won’t work as expected. Once again, this happens with documents loaded from _chrome_, not with normal web pages.

Steve Conover posted a workaround for this bug, about a year ago. I’m happy to offer a patch against Prototype 1.5.0 (final), with that workaround applied. Hope you’ll find it useful.

Categories: programming
  1. Marcos
    July 4th, 2007 at 23:51 | #1

    Hi, do you have your patched prototype library somewhere? The link in your post is broken. I would like to use it. Thank you :)

  2. yu_li_yan
    July 8th, 2007 at 17:05 | #2

    Hi Marcos,

    Please try the link now, it should work again.

    Apparently I fudged it up during an upgrade of Wordpress.

    Let me know how your extension comes along ;)

  3. Mindstorm
    September 19th, 2007 at 19:16 | #3

    Out of curiosity, have you used prototype.js in a FireFox extension? I tried to give it a go, but within the extension, you must use content.document vs document (e.g. content.document.getElementById(’someElement’)) and prototype.js uses document.getElementById(‘…’). At least I think that’s the reason it is not working for me. Just wondering.

  4. yu_li_yan
    September 20th, 2007 at 15:13 | #4

    Mindstorm: The two idioms mean different things. *content.document* is the HTML document currently loaded in the window, whereas *document* is the XUL “document” representing the window.

  5. October 4th, 2007 at 19:20 | #5

    Thanks, but I still don’t understand on how to get a FireFox extension to use prototype.js. Should I be able to use $(’someElementId’) “out of the box” when trying to use prototype within a FireFox extension? If so, I am doing something wrong. Any pointers would be appreciated.

  6. yu_li_yan
    October 4th, 2007 at 19:33 | #6

    Make sure you load prototype.js in your XUL file, before loading your JS. You need to add something like this to every XUL file:

    <script src="chrome://yourextensionname/content/prototype.js"
    type="text/javascript" />

  7. November 7th, 2007 at 13:58 | #7

    Your patch is great! It inspired me to hack up 1.6.0 RC1 to work in chrome.

  8. yu_li_yan
    November 7th, 2007 at 15:35 | #8

    Good work, Adam! Thanks for the kind words.

  9. SeanQ
    December 7th, 2007 at 02:52 | #9

    Thanks, this quickly answered a question I had (before loosing too much hair! :) .

    Adam (anyone), do you have a patch for 1.6.0 final ready? I’ve downloaded the patch above but I’d prefer to use 1.6 and would rather not spend the evening replicating work that might already be done.

    Thanks!

  10. June 26th, 2009 at 01:13 | #10

    hello.
    i’m using prototype.js 1.6.0.3 and i’m experiencing an issue with it inside an extension: tooltip appears everywhere (it seems on mouseover) with the text referred with the last valid tooltip displayed. May someone help me?

    thanks in advance
    Christian F.

  11. October 27th, 2009 at 03:09 | #11

    Thanks for dashing my dreams with your Prototype patch v404 :-)

  12. Iulian Dogariu
    November 4th, 2009 at 00:07 | #12

    Heh :) Thanks for the poke. Fixed the link to the patch.

  1. No trackbacks yet.