Send Text With Post Method From Chrome Extension
Send big text with chrome extension. I'm trying to send big text which is stored in my local storage to a site using my chrome extension. I've seen this answer and using this code
Solution 1:
Basically, the answer would be that you cannot use the described method. Your big data won't fit into an URL, and the code you inject via a URL has no way at all to interact with extension code.
You need an alternative solution, but thankfully it should be easy. You can include an html file into your extension that will post the data, and open that page instead. That HTML file, being part of your extension, has access to its localStorage
.
Edit: I've created a general solution, see this answer.
Something along those lines:
post.html:
<html><head></head><body><scriptsrc="post.js"></script></body></html>
post.js:
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "http://cvsguimaraes.altervista.org/fiddles/postcheck.php");
var params = {action: localStorage['txt'];};
for(var key in params) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
document.body.appendChild(form);
form.submit();
background.js:
chrome.browserAction.onClicked.addListener(function(t) {
chrome.tabs.create({"url" : chrome.runtime.getURL("post.html")});
});
Post a Comment for "Send Text With Post Method From Chrome Extension"