Last active
October 16, 2015 17:11
-
-
Save DamianZaremba/afdf810c0c9ce799e4ad to your computer and use it in GitHub Desktop.
FireFox Plugin
This file contains 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
// AssetErrorController.getErrors() needs to be exposed to either the window or document scope on pages | |
// i.e. javascript:alert(window.foo); should work with the plugin loaded and return an object/hash back | |
var events = require("sdk/system/events"); | |
var { Ci, Cu } = require("chrome"); | |
// Store errors here | |
var AssetErrorController = new function() { | |
var errors = {}; | |
this.put = function(url, status) { | |
if(errors[url] == undefined) { | |
errors[url] = []; | |
} | |
errors[url].push(status); | |
}; | |
this.getErrors = function() { | |
return errors; | |
} | |
}; | |
// Catch errors | |
events.on("http-on-examine-response", function (event) { | |
try { | |
event.subject.QueryInterface(Ci.nsIHttpChannel); | |
// If the request failed, but wasn't a redirect 3xx (redirects are not a success) | |
var status = event.subject.responseStatus; | |
var url = String(event.subject.URI.spec); | |
if( | |
// Didn't load | |
(event.subject.requestSucceeded == false && !(status >= 300 && status < 400)) || | |
// Internal address | |
(/^https?:\/\/((127|10)\.[0-9]{1,3}\.)|(172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)|(192\.168\.)\.[0-9]{1,3}\.[0-9]{1,3}/.test(url)) | |
) { | |
AssetErrorController.put(url, status); | |
} | |
} catch(err) { | |
console.log("ERROR: Capture error: " + err); | |
} | |
}, true); | |
exports.main = function(options, callbacks) { | |
events.on("content-document-global-created", function(event) { | |
// This throws a security error | |
// Security wrapper denied access to property undefined on privileged Javascript object. | |
// Support for exposing privileged objects to untrusted content via __exposedProps__ is being gradually removed - | |
// use WebIDL bindings or Components.utils.cloneInto instead. | |
// Note that only the first denied property access from a given global object will be reported. | |
//Cu.exportFunction(AssetErrorController.getErrors, event.subject.window, {defineAs: "bar"}); | |
// Throws a permission denied error | |
// Error: Permission denied to pass a Function via structured clone | |
//event.subject.window.bar = Cu.cloneInto(AssetErrorController, event.subject.window); | |
//event.subject.window.bar = Cu.cloneInto(AssetErrorController.getErrors, event.subject.window); | |
// Does not work without any errors | |
//event.subject.window.bar = Cu.cloneInto(AssetErrorController, event.subject.window, {cloneFunctions: true}); | |
//event.subject.window.bar1 = Cu.cloneInto(AssetErrorController.getErrors, event.subject.window, {cloneFunctions: true}); | |
//event.subject.window.bar2 = Cu.cloneInto(AssetErrorController.getErrors, event.subject, {cloneFunctions: true}); | |
//event.subject.window.bar3 = Cu.cloneInto(AssetErrorController.getErrors, event, {cloneFunctions: true}); | |
// This works | |
Cu.createObjectIn(event.subject.window, {defineAs: "foo"}); | |
}, true); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment