views:

102

answers:

1

I understand that jQuery is the preferred Javascript framework for Firefox extensions, but I'm comfortable with Prototype and need to implement a simple Firefox extension.

Unfortunately, I'm having trouble invoking a Prototype method. Each method call is resulting in a no-op: there are no errors or other signs the method call occurred.

Here's the overlay code:

<overlay id="liteextension-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;

This call to a Prototype method returns an empty array, even though there are divs in the page:

var all_divs = $$('div');

The "prototype.js" file lives in the same dir as the XUL file.

Help?

+1  A: 

Using libraries like prototype and jquery inside a Firefox extension is a complicated thing. The problem is that the JQuery is not loaded in the same context when loaded from XUL than when loaded from a webpage. So if you are trying to manipulate stuff in a page, a library loaded in XUL will not see the page DOM where it expects it to be. With JQuery (not sure about prototype) you can solve this by pointing to the right context.

Second, importing libraries inside an extension in a browser.xul overlay will put all functions and variables defined in the library in the global namespace, potentially conflicting with other extensions and even the Firefox code. This could cause a big mess.

There is more information in this forum post, it is about JQuery, but the same problems apply... maybe the suggested solutions could be useful for you:

http://forums.mozillazine.org/viewtopic.php?f=19&amp;t=1460255

fms