Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The example you have there is meant for a classic (XUL-based) extension, not for the Add-on SDK. You can still add that observer using the <a href="https://addons.mozilla.org/en-US/developers/docs/sdk/1.9/packages/api-utils/observer-service.html" rel="nofollow">low-level <code>observer-service</code> API</a>. Also, SDK-based extensions don't usually have access to the <code>Components</code> object, it requires <a href="https://addons.mozilla.org/en-US/developers/docs/sdk/1.9/dev-guide/tutorials/chrome.html" rel="nofollow">chrome authority</a>. Add the following code to your <code>main.js</code> file:</p> <pre class="lang-js prettyprint-override"><code>var observer = require("observer-service"); var {Cc, Ci} = require("chrome"); observer.add("http-on-modify-request", function(subject, data) { var channel= subject.QueryInterface(Ci.nsIHttpChannel); if (channel.requestMethod == "POST") { channel = channel.QueryInterface(Ci.nsIUploadChannel); channel = channel.uploadStream; channel.QueryInterface(Ci.nsISeekableStream) .seek(Ci.nsISeekableStream.NS_SEEK_SET, 0); var stream = Cc["@mozilla.org/binaryinputstream;1"] .createInstance(Ci.nsIBinaryInputStream); stream.setInputStream(channel); var postBytes = stream.readByteArray(stream.available()); poststr = String.fromCharCode.apply(null, postBytes); //change the poststr // poststr=poststr.replace(....); // ERROR HERE - stringStream is not defined stringStream.setData(poststr, poststr.length); //changing the postdata channel = channel.QueryInterface(Ci.nsIUploadChannel); channel = channel.uploadStream; channel.QueryInterface(Ci.nsISeekableStream) .seek(Ci.nsISeekableStream.NS_SEEK_SET, 0); channel.uploadStream.QueryInterface(Ci.nsIMIMEInputStream); channel.uploadStream.setData(stringStream); channel.requestMethod = "POST"; } }); </code></pre> <p>Note that I merely replaced <code>Components.classes</code> by <code>Cc</code> and <code>Components.interfaces</code> by <code>Ci</code> in the code you provided - I'm not sure what this code is supposed to do but I am quite sure that it doesn't work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload