views:

291

answers:

3

Hi, I am developing a firefox extension and I need to include the Google Search API. But I am encountering an error in the google.load('search','1') line. Can anyone tell what the problem is

Thanks.

A: 

If you've gathered all the JavaScript files and are packaging them with your Firefox extension locally, and google's load function was designed for loading JavaScript from a server then your problem is that you can't use the load mechanism in that library. Instead use Components.utils.import or mozIJSSubScriptLoader depending on the version of Firefox you're targeting.

This might require editing, extending or overwriting the code in Google's library.

apphacker
A: 

I have the same problem, but according to what I can see in Google's JS code, it tries to add variable 'google' to window, but the extension is loaded when there is no window yet! So there will be no global google variable and therefore an error occurs when you try to fire google.load(). I think the solution is to load the script dynamically. I have just found an existing addon for transliteration:

h t t p s : / / addons.mozilla.org/pl/firefox/addon/8960

Look how they have solved the problem:

onPageLoad: function(event) {
var doc = event.originalTarget;
var ele = doc.createElement('script');
ele.setAttribute('type', 'text/javascript');
ele.setAttribute('src', 'h t t p : / / www.google.com/jsapi?key=internal');

}

onPageLoad is loaded when DOMContentLoaded event occures, so when the whole tree of the page is loaded (it seems it's a DOM equivalent to onLoad)

(Forgive me inserting spaces in links, but otherwise I would not be permitted to post them :])

A: 

But yo have to add 'ele' to head right ???

also pease give some more details on use of mozIJSSubScriptLoader or Components.utils.import beacuase I have been getting errors like (NS_ERROR_ILLEGAL_VALUE) Components.utils.import method