2

我可以在 Firefox 扩展中获取当前页面 URL,但我也想获取 POST 数据。Firefox 将其存储在某处,以便在刷新时再次发送。如何从我的扩展程序中获取它?

我可能可以像 Firebug 一样捕获每个请求,但我宁愿避免这种情况,只按需获取 POST 数据。

我正在使用附加 SDK (jetpack)。我在我的主脚本中尝试了此页面的代码:

{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);

但它失败了

postdata.QueryInterface(Ci.nsISeekableStream).seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);

因为postdata is null( TypeError)。

我还在附加到活动选项卡的内容脚本中尝试了这种方法,但是在获取Components.classes.

4

1 回答 1

2

此代码检索最后一页的 POST 数据,而不是当前页面。

我改为history.index-1并且history.index它有效。

于 2011-07-11T20:07:17.873 回答