Skip to content

Commit

Permalink
Special case ios safari for stem download (#3385)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson authored May 18, 2023
1 parent d38238d commit 334ea0d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/web/src/services/track-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 334ea0d

Please sign in to comment.