1

I am trying to make a firefox extension that will list all the videos on a page. I had already got it working as a normal js script (not as an extension) so I know the script works.

My problem is that the $.ajax inside my firefox extension doesn't get called at all. If I look at the error console it shows a message like "unsafe use of Jquery". I've tried searching Google and other sites but I couldn't come up with a solution.

Here's the code where the problem is:

    var listMainVid = function ()
{
    // Make a JSONP call. We are using JSONP instead of JSON because we have to make a cross-domain AJAX call
    $.ajax({
        url:        vidinfo_q_url + "?jsoncallback=?",      // Don't forget to put in the 'jsoncallback=' part
        dataType:   'jsonp',        // Make a JSONP request, have it received as text, and interpreted by jQuery as JSON: "jsonp text xml."
        data:       {
                        video_url:  '' + doc.document.location
                    },
        success:    function ( data, textStatus, jqXHR )    // Keep in mind that this is just the request sending success.
                    {
                        if ( data.status === 'SUCCESS' )
                        {
                            var vid_loc = data.url, img_url=data.image_url;
                            if( Object.prototype.toString.call( vid_loc ) === '[object Array]' )    // Check if it's an array
                                vid_loc = data.url[0];
                            if( Object.prototype.toString.call( img_url ) === '[object Array]' )    // Check if it's an array
                                img_url = data.image_url[0];
                            addVideoToVidDiv( data.id, vid_loc, img_url );
                        }
                        else    // Error
                        {
                            //alert ( " Error! Data=" + data.status );
                        }
                        afterMainVid();
                    },  
        error:      function( xhRequest, ErrorText, thrownError )       
                    {
                        Application.console.log( " Can't do because: " + ErrorText + ", " + thrownError );
                        afterMainVid();
                    }
    });
    afterMainVid();
}

Any help/pointers would be greatly appreciated.

OK, I finally figured it out on my own. This is to anyone else who might run into the same problem. Change the dataType: 'jsonp', TO dataType: 'json', And that's it! I don't know why but FF doesn't seem to support 'jsonp' calls from inside extensions. One thing to note here is that inside FF extensions, you don't need 'jsonp' anyway as the extensions are free to make cross-domain ajax calls. Hope this will help.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
GarbageGigo
  • 303
  • 2
  • 10

2 Answers2

0

Have you fully installed the extension? You can't just execute the .xul file, you have to install it properly to let Firefox know you "trust" the extension before letting it do stuff like AJAX requests.

Christoph
  • 50,121
  • 21
  • 99
  • 128
Dunhamzzz
  • 14,682
  • 4
  • 50
  • 74
  • Hi Christoph, thanks for your response. Yes I have already installed it. I don't know about the trust thing (I'm pretty new to extension development) but I have installed it. I've made an extra menu item come up in the toolbar and that is where I execute it from. – GarbageGigo Jul 23 '12 at 08:11
0

OK, as SomeKittens requested, I am answering my own question (didn't know I could do that).

The solution to the problem is to change the dataType: 'jsonp', To dataType: 'json'.

I don't know why but FF doesn't seem to support 'jsonp' calls from inside extensions. One thing to note here is that inside FF extensions, you don't need 'jsonp' anyway as the extensions are free to make cross-domain ajax calls. Hope this will help.

I've also provided the answer in the question itself.

GarbageGigo
  • 303
  • 2
  • 10