title: Retrieve POST data of the current web page in a Firefox extension
body: <p>I can get the current page URL in a Firefox extension but I'd like to get the POST data too. Firefox stores it somewhere to send it again on refresh. How can I get it from my extension ?</p>
  
  <p>I could probably capture each request like Firebug, but I'd rather avoid that and get the POST data only on demand.</p>
  
  <p>I'm using the <a href="https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/" rel="nofollow">add-on SDK (jetpack)</a>. I tried the code from <a href="https://developer.mozilla.org/en/Code_snippets/Miscellaneous#Getting_postData_of_a_webpage" rel="nofollow">this page</a> in my main script:</p>
  
  <pre><code>{Cc,Ci} = require("chrome");
  
  wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
  mainWindow = wm.getMostRecentWindow("navigator:browser");
  
  history = mainWindow.gBrowser.selectedBrowser.webNavigation.sessionHistory;
  
  postdata = history.getEntryAtIndex(history.index-1,false).QueryInterface(Ci.nsISHEntry).postData;
  
  postdata.QueryInterface(Ci.nsISeekableStream).seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
  stream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIBinaryInputStream);
  stream.setInputStream(postdata);
  postBytes = stream.readByteArray(stream.available());
  poststr = String.fromCharCode.apply(null, postBytes);
  
  console.log(poststr);
  </code></pre>
  
  <p>But it fails at</p>
  
  <pre><code>postdata.QueryInterface(Ci.nsISeekableStream).seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
  </code></pre>
  
  <p>Because <code>postdata is null</code> (<code>TypeError</code>).</p>
  
  <p>I also tried this method in a content script attached to the active tab, but it fails with a permission denied while getting <code>Components.classes</code>.</p>