I tried to convert a Chrome extenstion to Firefox using this tool http://www.extensionfactory.com/labs/conversion/ and it works great except the AJAX calls. Each time I make an AJAX call from the Firefox extension, I get this error(in Chrome works fine):
[Exception… “Component returned failure code: 0x80004005
(NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]” nsresult: “0x80004005
(NS_ERROR_FAILURE)” location: “JS frame ::
resource://nfglncbjnghpllgmelioileejdnldcgm-api-utils-lib/securable-module.js
-> resource://nfglncbjnghpllgmelioileejdnldcgm-api-utils-lib/content/content-proxy.js
:: :: line 97” data: no]
This is the AJAX call in the content_script(chrome extension):
var dataString='original_url='+imgsrc+'&filename='+filename+'&crop_x='+selX+'&crop_y='+selY+'&crop_h='+selH+'&crop_w='+selW;
$.ajax({
type: "GET",
url: "http://www.[website.com]/crop",
data: dataString,
async:false,
success: function() {
alert('Image successfully added!');
iframe.src = iframe.src;
} ,
error:function(){
$.ajax({
type: "GET",
url: "http://[www.website.com]/loggedin",
success: function() {
alert('An error occured when uploading image to server! Please try again.');
} ,
error:function(){
alert('You are not logged in! Please login.');
window.open('http://[www.website.com]/login');
}
});
}
});
I traced the error and nothing to be found, nothing related and I can’t get more details from Firebug. I also verified the website address and server code and everything is fine, it just doesn’t work on Firefox.
I’m thinking that Firefox Extension API has some limitations regarding to AJAX requests, but I don’t know what to say since I couldn’t find anything on the Internet.
Maybe you know what’s happening here…
There are multiple ways to make a Firefox extension so it’s difficult to give you a detailed answer, but I will say that the error message you are receiving is expected if you are trying to make network calls from within the extension sandbox environment because they don’t allow it.
If you can, use their latest SDK which can be found here:
https://addons.mozilla.org/en-US/developers/docs/sdk/latest/
You’ll notice they have a class called “request” in their api that does exactly what you want. It can be found here:
https://addons.mozilla.org/en-US/developers/docs/sdk/1.4/packages/addon-kit/docs/request.html
One thing to note, if you use their latest SDK (1.4 at the time of this writing) it is not compatible with versions of Firefox prior to 4.