mozilla-mobile / firefox-ios

Firefox for iOS
Mozilla Public License 2.0
12.1k stars 2.88k forks source link

Downloading local data via HTML5 anchor `download` attribute not working #13299

Open AeonSake opened 1 year ago

AeonSake commented 1 year ago

Currently, Firefox on iOS seems to not support saving data as file via the anchor download attribute. Serializing a Blob or inlining a data URL directly does not trigger a file download but sets the browser into an infinite loading state without ever finishing. If the data type is set to a preview-able type (e.g., application/json), the content is loaded as new page instead of being downloaded.

Steps to reproduce

Any HTML5 anchor element with a download attribute and the href attribute set to a data url. In the example, octet/stream is used to force a download rather than a content preview. Use application/json to reproduce the undesired content preview issue instead.

const data = {
  bool: true,
  str: 'test_string',
  val: 123.56,
  obj: {
    prop1: 'val1',
    prop2: [1, 2, 3]
  },
  arr: [1, 2, 3]
};

function download() {
  const blob = new Blob([JSON.stringify(data)], {type: 'octet/stream'});
  const url = URL.createObjectURL(blob);

  const el = document.createElement('a');
  document.body.appendChild(el);
  el.href = url;
  el.download = 'test.json';
  el.click();

  URL.revokeObjectURL(url);
  document.body.removeChild(el);
}

Example on JSFiddle: https://jsfiddle.net/uymk5xr0/2/

Expected behavior

Browser triggers a file download with the content given in the data URL. The data is saved as file with the given name in the download attribute and is listed in the download history.

Actual behavior

Browser starts a loading sequence briefly showing a loading bar but never finishes (refresh button is replaced with the cancel button). Loading process cannot be aborted until a new page is opened or the page is reloaded. No actual file is created.

Device & build information

┆Issue is synchronized with this Jira Task

estarner-sugarcrm commented 1 year ago

@AeonSake Any update or work around for this issue?

jeffreyazevedo commented 9 months ago

I'm running into this issue as well, seems to still be broken. @AeonSake did you by chance ever figure out a workaround here?

AeonSake commented 9 months ago

Haven't found a workaround for this issue, at least none that wouldn't impact UX on other browsers as well. It's unfortunate but I've given up on (fully) supporting iOS Firefox due to this issue.

osc707 commented 9 months ago

I am currently working on a fairly large project for Adobe (Express) and we are facing this issue.

We programmatically download an MP4 for a user, when they choose to export. Instead of downloading the file, it's opened in a separate player/tab for the user to view.

Our desired result would be like the other browsers, where the user gets prompted to save the file or it's downloaded.

clemlesne commented 8 months ago

Maybe related to https://github.com/mozilla-mobile/firefox-ios/issues/14053.

data-sync-user commented 8 months ago

➤ Yoana Rios Diaz commented:

Note to QA: Test downloads on other flows continue to work as expected

JRDove commented 3 months ago

Still not fixed?

gen63 commented 2 months ago

It's a way to work around this issue. https://stackoverflow.com/questions/27115748/download-attribute-not-working-in-firefox

data-sync-user commented 2 months ago

➤ Alina Moldovan commented:

Validated this issue using v126(41677) using iPhone 15+ (17.4.1) iPhone 13 Pro Max (15.7.1).

Not able to reproduce the issue anymore.

sanal-soman-ai commented 4 weeks ago

The issue exist in Firefox (v127.1) and iPhone 15 Pro Max (17.5.1).