Using prototype.js in chrome
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
Hi, do you have your patched prototype library somewhere? The link in your post is broken. I would like to use it. Thank you
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
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.
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.
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.
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" />
Your patch is great! It inspired me to hack up 1.6.0 RC1 to work in chrome.
Good work, Adam! Thanks for the kind words.
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!
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.
Thanks for dashing my dreams with your Prototype patch v404
Heh
Thanks for the poke. Fixed the link to the patch.