Created
January 8, 2015 02:43
-
-
Save Noitidart/b52f518111c2009705b0 to your computer and use it in GitHub Desktop.
_ff-addon-snippet-CancelAJAX - Detect if AJAX request and then cancel it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
README
Rev1