I've been working on creating a Firefox extension that can list all the videos on a page. Initially, I had successfully implemented this functionality as a standard JS script (not as an extension), which confirmed that the script was functioning correctly.
However, when attempting to use $.ajax within my Firefox extension, the call does not execute at all. Upon checking the error console, I encountered a message indicating "unsafe use of jQuery." Despite searching through various sources such as Google and other websites, I have been unable to find a solution to this issue.
The following code snippet depicts where the problem lies:
var listMainVid = function ()
{
// Making a JSONP call. Utilizing JSONP instead of JSON due to requiring a cross-domain AJAX call
$.ajax({
url: vidinfo_q_url + "?jsoncallback=?", // Ensure including the 'jsoncallback=' portion
dataType: 'jsonp', // Initiating a JSONP request, receiving it as text, and interpreting it as JSON using jQuery: "jsonp text xml."
data: {
video_url: '' + doc.document.location
},
success: function ( data, textStatus, jqXHR )
{
if ( data.status === 'SUCCESS' )
{
var vid_loc = data.url, img_url=data.image_url;
if( Object.prototype.toString.call( vid_loc ) === '[object Array]' )
vid_loc = data.url[0];
if( Object.prototype.toString.call( img_url ) === '[object Array]' )
img_url = data.image_url[0];
addVideoToVidDiv( data.id, vid_loc, img_url );
}
else
{
//alert ( " Error! Data=" + data.status );
}
afterMainVid();
},
error: function( xhRequest, ErrorText, thrownError )
{
Application.console.log( " Can't do because: " + ErrorText + ", " + thrownError );
afterMainVid();
}
});
afterMainVid();
}
Any assistance or guidance regarding this matter would be highly appreciated.
Update: After some independent investigation, I managed to resolve the issue. For anyone facing similar challenges, simply change the dataType from 'jsonp' to 'json'. It seems that Firefox does not fully support 'jsonp' calls within extensions for reasons unknown. It's worth noting that within Firefox extensions, there is no necessity for 'jsonp' anyway, as the extensions are capable of making cross-domain AJAX calls freely. Hope this explanation proves helpful to others facing the same dilemma.