Skip to content

Commit 44be3df

Browse files
Merge pull request scratchfoundation#5927 from ericrosenbaum/prevent-ios-download-crash-timeout
Prevent crash when saving locally on iOS 13 safari
2 parents 3f03891 + e7177b2 commit 44be3df

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/lib/download-blob.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ export default (filename, blob) => {
1414
downloadLink.download = filename;
1515
downloadLink.type = blob.type;
1616
downloadLink.click();
17-
document.body.removeChild(downloadLink);
18-
window.URL.revokeObjectURL(url);
17+
// remove the link after a timeout to prevent a crash on iOS 13 Safari
18+
window.setTimeout(() => {
19+
document.body.removeChild(downloadLink);
20+
window.URL.revokeObjectURL(url);
21+
}, 1000);
1922
} else {
20-
// iOS Safari, open a new page and set href to data-uri
23+
// iOS 12 Safari, open a new page and set href to data-uri
2124
let popup = window.open('', '_blank');
2225
const reader = new FileReader();
2326
reader.onloadend = function () {

0 commit comments

Comments
 (0)