I try to migrate my firefox addon wich use low level SDK API to WebExtension and at some point I want to POST data url-encoded to a new tab.
With the low level API it is possible through the following code:
const querystring = require('sdk/querystring');
let stringStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
stringStream.data = querystring.stringify(params); // params is a json data
let postData = Cc["@mozilla.org/network/mime-input-stream;1"].createInstance(Ci.nsIMIMEInputStream);
postData.addHeader("Content-Type", "application/x-www-form-urlencoded");
postData.addContentLength = true;
postData.setData(stringStream);
var tabBrowser = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator).getMostRecentWindow("navigator:browser").gBrowser;
var selectedTabIndex = tabBrowser.tabContainer.selectedIndex;
var newTab = tabBrowser.loadOneTab("https://myurl.com/", {
inBackground: false,
postData: postData
});
tabBrowser.moveTabTo(newTab, selectedTabIndex + 1);
But I haven't found a WebExtension equivalent.
Is it possible or the only solution is to create a form and submit it in js?