Clicking <a> element with download link not working?

I have the following code in a custom component:

var a = document.createElement('a');
a.href = "https://render.carbone.io/render/" + resp.data.renderId;
a.download = 'download';
document.body.appendChild(a);
a.click();

This is supposed to open the file save dialog to download the file referenced in the URL.

The click happens, Dev Tools Network tab tells me that the link is fetched, but no download window appears. I guess I might expect this within the main sandbox, but not in a custom component iFrame. And I do have All Popups to Escape... and Allow Links within the component... enabled.

I tried doing it by opening up a blank window and adding the tag there, and that does work as expected, but then leaves my user with a blank tab to close.

HI Bradly,

I believe that this is likely not working since downloads are blocked in the custom component iFrame. I am working on expanding the capabilities of the custom component, but there are a lot of implications around these changes. I can definitely follow up when these changes go live!

Thanks, Just today I finished implementing a "workaround" where when the file is complete and readu for download, the component updates the model with a url value. An alert box then goes visible telling the user to click the link to the right to copy the URL to the clipboard. Click event handlers then copy to clipboard and set visibility back to false. They then need to paste the URL into a new browser tab.

It sounds worse than it is, but any better ideas would be appreciated!

Would using a 'Go to URL' instead of a 'Copy to Clipboard' option be better here?

Also, once you have that URL, you could potentially use a REST API query to fetch the file, then a JS query to utils.downloadFile() the result of that fetch, so the user does not even need to leave the app.

Palm to forehead. (Slap)

Ok, that goes to the URL and the browser opens a save-as dialog automatically. Downloads immediately with the default "Ask where to save each file before downloading" browser setting disabled.

Do not need utils.downloadFile() at all!

Now that you have added full event support to query outcomes, I can just fire a Go To URL action onSuccess. So I can get rid of the alert component.