Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Created January 8, 2015 02:43
Show Gist options
  • Save Noitidart/b52f518111c2009705b0 to your computer and use it in GitHub Desktop.
Save Noitidart/b52f518111c2009705b0 to your computer and use it in GitHub Desktop.
_ff-addon-snippet-CancelAJAX - Detect if AJAX request and then cancel it.
var {utils: Cu, classes: Cc, instances: Ci, results: Cr} = Components
Cu.import('resource://gre/modules/Services.jsm');
var myobserve = function(aSubject, aTopic, aData) {
var httpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel);
var isXHR;
try {
var callbacks = httpChannel.notificationCallbacks;
var xhr = callbacks ? callbacks.getInterface(Ci.nsIXMLHttpRequest) : null;
isXHR = !!xhr;
} catch (e) {
isXHR = false;
}
if (isXHR) {
//its ajax
var requestUrl = httpChannel.URI.spec;
if (requestUrl.indexOf('https://www.facebook.com/ajax/mercury/change_read_status.php') > -1) {
httpChannel.cancel(Cr.NS_BINDING_ABORTED);
}
}
}
Services.obs.addObserver(myobserve, 'http-on-modify-request', false);
//Services.obs.removeObserver(myobserve, 'http-on-modify-request', false);
@Noitidart
Copy link
Author

README

Rev1

  • In working order, created for a question on SO which got deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment