2

現在のページの URL は Firefox の拡張機能で取得できますが、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-1history.index、それは動作します。

于 2011-07-11T20:07:17.873 に答える