Trouble downloading files in Google Apps Script web app after Chrome update
Asked Answered
G

5

8

I've had a Google Apps Script web app running for a bit over a year which gave users an option to download a csv file. It worked perfectly fine, although in the console it gave a warning about downloading from an iFrame being deprecated.

After updating Chrome, I now get the following error when trying to download:

Download is disallowed. The frame initiating or instantiating the download is sandboxed, but the flag ‘allow-downloads’ is not set. See https://www.chromestatus.com/feature/5706745674465280 for more details.

When following the above link, it provides the following information:

Chrome is planning on removing this capability - i.e. Chrome is going to block all downloads initiated from or instantiated in a sandboxed iframe by default. The embedder may add "allow-downloads" to the sandbox attributes list to opt in. This allows content providers to restrict malicious or abusive downloads.

How can I add "allow-downloads" to the sandbox attributes in the Google Apps Script environment? Alternatively, is there a workaround to enable downloading files?

Glandule answered 22/5, 2020 at 18:36 Comment(0)
G
2

Update as of 07/29/2020:

The attribute "allow-downloads" has now been added to the sandbox attributes and there is no longer any issue downloading files.

Glandule answered 29/7, 2020 at 17:2 Comment(2)
issuetracker.google.com/issues/157368720#comment76Spacetime
Yes, exactly. It is fixed right now, the iframe in GAS has been updated with allow-downloads flagSacrament
S
6

It is discussed here https://issuetracker.google.com/issues/157368720 that HtmlService.XFrameOptionsMode.ALLOWALL should set allow-downloads on GAS web app sandbox. We should watch this issue for changes.

Sacrament answered 28/5, 2020 at 15:53 Comment(1)
var html = HtmlService.createTemplateFromFile('page') html.ssid = 'hellothere'; html.reportid = "0"; var new_html = html.evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) IS THIS THE CORRECT SYNTAX?Voss
T
3

Include sandbox="allow-downloads" in your iframe tag, which contains the code that is used for downloading the CSV file.

Tertiary answered 28/5, 2020 at 6:19 Comment(1)
This is not possible in a Google Apps Script web app.Saimon
G
2

Update as of 07/29/2020:

The attribute "allow-downloads" has now been added to the sandbox attributes and there is no longer any issue downloading files.

Glandule answered 29/7, 2020 at 17:2 Comment(2)
issuetracker.google.com/issues/157368720#comment76Spacetime
Yes, exactly. It is fixed right now, the iframe in GAS has been updated with allow-downloads flagSacrament
A
1

There is one work around that I found if you have a download button, you can right click and open in a new tab. You have to rename the file but at least you can get it, until there is a fix.

Abb answered 1/6, 2020 at 17:20 Comment(3)
please tell me how to do this.Chancroid
I'm using sheets and creating a Json file. I just created a modal that retrieves the data to download, in my case its a JSON, Then turn it into a blob then a URL, then attach it to an anchor tag and display that in the modal. Right click and open in a new tab and the download comes through, just not the name of the file that was set.Abb
Could you please reply to my question asked here. people there does not seem to understand the actual problem. link also I am unable to get the result if you could provide any solution there I would greatly appreciate.Chancroid
D
0

iframe that embeds a webpage with sandbox attributes. You added allow-downloads to enable downloads from within the iframe, which is required to allow users to download content (such as reports) when the iframe is sandboxed.

<iframe width="100%" height="1068"
  src="url"
  frameborder="0" style="border: 0; border-radius: 24px" allowfullscreen
  sandbox="allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-downloads"></iframe>
Delafuente answered 12/9 at 12:30 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewSadism

© 2022 - 2024 — McMap. All rights reserved.