Open file dialog from background script
-
nekomajin last edited by
I am in a need of some help.
I am working on a music player extension. The idea is simple: select files from the local machine and play them in the sidebar. Thanks to the
<audio>
element, everything is working fine, while the sidebar panel is open.I use the
createObjectURL()
method to pass the files to the<audio>
element. The problem is that it only holds a reference to the files in the memory, which gets lost when the sidebar panel unloads. I can send these references to the background script, but it won't help.Using a FileReader is not an option, because it uses a lot of CPU and RAM, and temporarily freezes the browser when I open the files. So I came up with the idea to use the
createObjectURL()
method in the background script, so the references would be alive while the browser itself is running.Now the problem is that I can't open a file dialog from the background script. I can create a file type input, and also use the
click()
method, but the dialog window does not show up. However, the click event happens, because the onclick event listener is being called.So I'd like to ask some help. Is it possible to open the file dialog from the background script at all? If it is, how can I make it work?
-
gustavwiz last edited by
Open the dialog in the script that you did it in before, and send a message to the background script with the file path.
https://dev.opera.com/extensions/message-passing/
https://developer.chrome.com/extensions/messaging -
nekomajin last edited by
That's not a solution to my problem.
The
createObjectURL()
creates references to the files stored in the memory. It is useless to send these references to the background script, because when the panel unloads, the references cease to exist.