From 334ea0db257b6f89d45381b0ccba6c5ecd714304 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Thu, 18 May 2023 11:31:06 -0700 Subject: [PATCH] Special case ios safari for stem download (#3385) --- packages/web/src/services/track-download.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/web/src/services/track-download.ts b/packages/web/src/services/track-download.ts index 6ffdaaf1979..fc77056a7e5 100644 --- a/packages/web/src/services/track-download.ts +++ b/packages/web/src/services/track-download.ts @@ -2,6 +2,14 @@ import { TrackDownload as TrackDownloadBase } from '@audius/common' import { audiusBackendInstance } from './audius-backend/audius-backend-instance' +function isMobileSafari() { + if (!navigator) return false + return ( + navigator.userAgent.match(/(iPod|iPhone|iPad)/) && + navigator.userAgent.match(/AppleWebKit/) + ) +} + class TrackDownload extends TrackDownloadBase { async downloadTrack({ url, filename }: { url: string; filename: string }) { const response = await window.fetch(url) @@ -13,7 +21,11 @@ class TrackDownload extends TrackDownloadBase { if (document) { const link = document.createElement('a') link.href = url - link.target = '_blank' + // taget=_blank does not work on ios safari and will cause the download to be + // unresponsive. + if (!isMobileSafari()) { + link.target = '_blank' + } link.download = filename link.click() } else {