Some context: I'm making an add-on for firefox. In firefox add-ons, js scripts can be attached to a webpage at certain events (content scripts). In those scripts I'd like to use the prototype of XMLHttpRequest
.
Is it possible to access the prototypes of the available classes in javascript? For example: XMLHttpRequest.toString()
returns [object XMLHttpRequest]
, while XMLHttpRequest.prototype
is null
. Am I doing anything wrong, or isn't it possible to use prototypes in those scripts?
Yes, you must be doing something wrong. I tried with a minimal SDK-based extension, the main.js
file being:
var pageMod = require("page-mod");
pageMod.PageMod({
include: "*.google.com",
contentScriptWhen: "end",
contentScript: 'throw "XMLHttpRequest.prototype = " + XMLHttpRequest.prototype'
});
When I load google.com I see the following message in the Error Console:
XMLHttpRequest.prototype = [object XMLHttpRequestPrototype]
So XMLHttpRequest.prototype
is definitely not null
.