Prześlij plik jako dane formularza przez rozszerzenie chrome
Przesyłam plik przez rozszerzenie chrome jako dane formularza, a mój kod znajduje się poniżej. Problem polega na tym, że okno przeglądania plików otwiera się na sekundę, a następnie znika.
Problem pojawia się tylko w systemie Mac OS.
manifest.json:
"background": {
"scripts": ["jszip.js", "background.js"]
},
background.js:
chrome.runtime.onMessage.addListener(function (msg) {
if (msg.action === 'browse')
{
var myForm=document.createElement("FORM");
var myFile=document.createElement("INPUT");
myFile.type="file";
myFile.id="selectFile";
//myFile.onclick="openDialog()";
myForm.appendChild(myFile);
var myButton=document.createElement("INPUT");
myButton.name="submit";
myButton.type="submit";
myButton.value="Submit";
myForm.appendChild(myButton);
document.body.appendChild(myForm);
}
});
popup.js:
window.onload = function () {
chrome.runtime.sendMessage({
action: 'browse'
});
}