Quantcast
Channel: Active questions tagged filereader - Stack Overflow
Viewing all articles
Browse latest Browse all 107

`` picker was blocked due to lack of user activation when programmatically trying to open File Load dialog

$
0
0

I am working on a Firefox add-on that needs to read a text file.However, I am getting the error <input> picker was blocked due to lack of user activation., which I understand is because I am doing it programmatically.

This is how I set the FileReader in the contentscript.js:

var fileChooser = document.createElement('input');fileChooser.type = 'file';fileChooser.addEventListener('change', function () {    const file = event.target.files[0];    var fr = new FileReader();    fr.onload = function (file) {      console.log(file.target.result)    };    fr.readAsText(file);});

Then it gets called when the user clicks on a button on the popup.html and sends a message to the contentscript.js which triggers the click:

browserInUser.runtime.onMessage.addListener((obj, sender, sendResponse) => {    const { type, value } = obj;    if (type === "upload") {        console.log("Listening")        fileChooser.click();    }});

This gets called and it gets printed "Listening" but also the error described above.This is one of the attempts I tried to programmatically open a FileReader dialog from an add-on, but it seems like I am not going to be able to do this programmatically.

I have been trying to achieve this for almost two weeks now, but I am about to give up. This is really easy to do in Chrome, but it seems to be a nightmare on Firefox.

Is this approach the wrong one? Is this even possible to do on Firefox? Please, even if you cannot help me with a "successful" answer, I need to know if this is even possible from an add-on.


Viewing all articles
Browse latest Browse all 107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>