@@ -3,28 +3,33 @@ import type { TrackHTMLAttributes } from 'react';
33import { useState , useRef , forwardRef } from 'react' ;
44
55import { Box , Button , IconButton , Margins } from '../..' ;
6+ import { useOwnerDocument } from '../../contexts' ;
67import { Slider } from '../Slider' ;
78
89const getMaskTime = ( durationTime : number ) =>
910 new Date ( durationTime * 1000 )
1011 . toISOString ( )
1112 . slice ( durationTime > 60 * 60 ? 11 : 14 , 19 ) ;
1213
13- function forceDownload ( url : string , fileName ?: string ) {
14+ function forceDownload (
15+ ownerDocument : Document ,
16+ url : string ,
17+ fileName ?: string ,
18+ ) {
1419 const xhr = new XMLHttpRequest ( ) ;
1520 xhr . open ( 'GET' , url , true ) ;
1621 xhr . responseType = 'blob' ;
1722 xhr . onload = function ( ) {
1823 const urlCreator = window . URL || window . webkitURL ;
1924 const imageUrl = urlCreator . createObjectURL ( this . response ) ;
20- const tag = document . createElement ( 'a' ) ;
25+ const tag = ownerDocument . createElement ( 'a' ) ;
2126 tag . href = imageUrl ;
2227 if ( fileName ) {
2328 tag . download = fileName ;
2429 }
25- document . body . appendChild ( tag ) ;
30+ ownerDocument . body . appendChild ( tag ) ;
2631 tag . click ( ) ;
27- document . body . removeChild ( tag ) ;
32+ ownerDocument . body . removeChild ( tag ) ;
2833 } ;
2934 xhr . send ( ) ;
3035}
@@ -126,6 +131,8 @@ const AudioPlayer = forwardRef<HTMLAudioElement, AudioPlayerProps>(
126131 handlePlaybackSpeed ( 1 ) ;
127132 } ;
128133
134+ const { document : ownerDocument } = useOwnerDocument ( ) ;
135+
129136 return (
130137 < Box
131138 borderWidth = 'default'
@@ -188,9 +195,9 @@ const AudioPlayer = forwardRef<HTMLAudioElement, AudioPlayerProps>(
188195 medium
189196 onClick = { ( e ) => {
190197 const { host } = new URL ( src ) ;
191- if ( host !== window . location . host ) {
198+ if ( host !== ownerDocument . defaultView ? .location . host ) {
192199 e . preventDefault ( ) ;
193- forceDownload ( src ) ;
200+ forceDownload ( ownerDocument , src ) ;
194201 }
195202 } }
196203 />
0 commit comments