# Options.html (as popup) & file picker

**URL:** <https://discourse.mozilla.org/t/options-html-as-popup-file-picker/137368>\
**Category:** Development\
**Created:** [November 21, 2024, 2:51pm UTC](https://discourse.mozilla.org/t/options-html-as-popup-file-picker/137368 "2024-11-21T14:51:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![irvinm](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/irvinm/32/22968_2.png) [@irvinm](https://discourse.mozilla.org/u/irvinm)\
**Post date:** [November 21, 2024, 2:51pm UTC](https://discourse.mozilla.org/t/options-html-as-popup-file-picker/137368/1 "2024-11-21T14:51:48Z")

</div>

I’m working on an addon that I would like to support export and import of some rules that would be stored. Currently I have an import button on options.html which opens a file picker to choose the input JSON file and will parse and store the information into the addon.

This solution works fine if options.html is in a separate tab, but does not work when it is just being used as a popup from clicking on the addon icon. It looks to me that the popup closes once the file picker comes up. This makes sense to me from a popup behavior perspective.

Is there a way to keep the popup open even during the file picker process? Or do I need to push the import/export process only when options.html is in a separate tab?

---

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [November 21, 2024, 8:40pm UTC](https://discourse.mozilla.org/t/options-html-as-popup-file-picker/137368/2 "2024-11-21T20:40:15Z")

</div>

Sadly, it’s a very old Firefox bug:

> **[1378527 - popups opened from a panel cause the panel to close](https://bugzilla.mozilla.org/show_bug.cgi?id=1378527)**
>
> NEW (nobody) in Core - XUL. Last updated 2024-11-02.

The best you can do is:

1. vote for that bug in bugzilla 🙂

2. detect that your popup.html is opened in the popup, and in that case, instead of “input” show something like this:  

NOTE:  
I’m pretty sure this can happen also with exports!  
Some users have “Always ask where to save file” option enabled in Firefox, so for them Firefox will again show a target download folder picker and the export will then fail.

---

<div class="post-metadata">

**Author:** ![dotproto](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/dotproto/32/62957_2.png) [@dotproto](https://discourse.mozilla.org/u/dotproto)\
**Post date:** [November 22, 2024, 1:35am UTC](https://discourse.mozilla.org/t/options-html-as-popup-file-picker/137368/3 "2024-11-22T01:35:09Z")

</div>

I haven’t tested this, but I think it would work. Your background script runs in the background page, so in the background you could

1. use `document.createElement()` to create an anchor tag
2. give it the [`download`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download) attribute
3. set the URL to the file that you want the user to download
4. the append it to the background document
5. use JavaScript to call `.click()` on the element

I _think_ that would allow you to download the file unless the user has the “Always ask where to save file” setting enabled as @juraj.masiar described.

---

<div class="post-metadata">

**Author:** ![irvinm](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/irvinm/32/22968_2.png) [@irvinm](https://discourse.mozilla.org/u/irvinm)\
**Post date:** [November 22, 2024, 1:14pm UTC](https://discourse.mozilla.org/t/options-html-as-popup-file-picker/137368/4 "2024-11-22T13:14:33Z")

</div>

Yeah, this is what I will end up doing. I’ll probably just create a link/button on the options page to open a new tab with the import/export options. (I did vote for the bug and I will watch it)

Thank you.
