Safari Blob URL Audio Fails: How to Fix It
In this article
Loading audio via a blob URL fails in Safari because Safari enforces stricter security and media rules than most browsers. The direct answer: if your audio player uses a blob URL created from a Blob or MediaSource, Safari may refuse to play it unless the blob is created with the correct MIME type, the audio element has proper user interaction, and the blob URL is not revoked too early. In many cases, switching from a blob URL to a data URL or a direct object URL of the original file resolves the issue. Below are the exact steps to diagnose and fix the problem.
What You'll Need
- A Mac, iPhone, or iPad with Safari (steps apply to Safari 15 and later; menu labels may differ slightly by version and region).
- Access to the web page or app code that creates the blob URL (you will need to edit JavaScript).
- Basic familiarity with the browser's developer tools (on Mac: Develop > Show Web Inspector; on iPhone/iPad you must enable Web Inspector in Settings > Safari > Advanced).
- The original audio file or a server endpoint that can serve it directly.
Step-by-Step
- Confirm the blob URL is the problem. Open the page in Safari. If the audio element shows an error or stays silent, open the Web Inspector (Mac: Develop > Show Web Inspector; iPhone/iPad: connect to a Mac and use Safari's Develop menu). Go to the Console tab and look for errors like "Failed to load resource" or "NotSupportedError". If the same page works in Chrome or Firefox but not Safari, the blob URL handling is the likely cause.
- Check the MIME type of the Blob. When you create the Blob, the second argument must be an object with a
typeproperty set to a valid audio MIME type, for examplenew Blob([arrayBuffer], { type: 'audio/mpeg' })for MP3 or'audio/mp4'for AAC/M4A. Safari is strict: if the type is missing or wrong (e.g.,application/octet-stream), it may refuse to play. Fix the MIME type to match the actual audio format. - Ensure the blob URL is created from a supported source. Safari supports blob URLs created from a Blob or File object, but not all blob URLs work with the
<audio>element. If you are usingMediaSource(MSE), note that Safari supports MSE for audio only in specific versions and with HLS, not for arbitrary blob streams. For simple audio playback, create the blob URL directly from a Blob containing the audio data, not from a MediaSource object. - Do not revoke the blob URL too early. If you call
URL.revokeObjectURL(blobUrl)immediately after settingaudio.src = blobUrl, Safari may fail to load the audio because the URL is invalidated before the media element fetches it. Revoke the URL only after the'loadeddata'or'canplay'event fires, or when you no longer need the audio element. - Trigger playback from a user gesture. Safari blocks autoplay of audio with sound. Even with a blob URL, the audio will not start unless the user taps or clicks a play button. Make sure your play call is inside a click or touch event handler. If you need autoplay, set
audio.muted = truefirst, then unmute after user interaction. - Set the
crossoriginattribute if needed. If the blob URL is created from a resource fetched cross-origin, Safari may requireaudio.crossOrigin = 'anonymous'before setting the source. This is less common for blob URLs but can matter if the blob was built from a cross-origin fetch. - Test with a data URL as a fallback. If the blob URL still fails, convert the audio data to a base64 data URL and set that as the source. This avoids blob URL restrictions entirely, though it increases memory usage for large files. Use
FileReader.readAsDataURLon the Blob to get the data URL. - Serve the audio file directly instead of via blob. If the audio comes from your server, the simplest fix is to set
audio.srcto the direct file URL (e.g.,/audio/track.mp3) and skip the blob entirely. Ensure the server sends the correctContent-Typeheader (e.g.,audio/mpeg) and supports range requests for seeking. - Update Safari and test again. Older Safari versions had bugs with blob URLs and media elements. Update to the latest Safari available for your macOS or iOS version, then retest. On iOS, also check Settings > Safari > Advanced > Experimental Features and ensure no media-related experimental flags are enabled that could interfere.
Common Mistakes
- Creating a Blob without a MIME type or with
application/octet-stream. Safari will often reject it for audio playback. - Revoking the blob URL immediately after assigning it to
audio.src. Wait for the media to load. - Assuming autoplay works. Safari requires a user gesture for audible playback.
- Using
MediaSourcefor simple audio files. MSE is intended for streaming and is not a drop-in replacement for a Blob URL in Safari. - Forgetting to set
audio.load()after changing the source. Some Safari versions need an explicit load call.
Tips
- Always specify the correct MIME type when creating a Blob:
audio/mpegfor MP3,audio/mp4for AAC/M4A,audio/oggfor Ogg (Safari support for Ogg is limited). - Use
audio.addEventListener('error', ...)to log theaudio.errorobject; it often reveals whether the issue is a network error, decode error, or unsupported source. - For large audio files, prefer direct URLs over blob URLs to avoid memory bloat and revocation timing issues.
- Test on both macOS Safari and iOS Safari, as behavior can differ.
- If you must use a blob URL, create it once and reuse it; avoid creating a new blob URL on every play attempt.
Troubleshooting
If the audio still fails after the steps above, work through these checks:
- Check the console for specific errors. In Safari's Web Inspector, look for messages like "Unsupported media type" or "The operation is not supported". These point to MIME type or codec issues.
- Verify the audio codec is supported by Safari. Safari supports AAC, MP3, and ALAC in various containers, but not all codecs (e.g., Opus in WebM is not supported on older Safari). Convert the audio to a supported format like MP3 or AAC.
- Try a minimal test page. Create a simple HTML file with an
<audio>element and a script that creates a blob URL from a small known-good audio file. If that works, the issue is in your app's logic; if not, it's a Safari limitation. - Check for Content Security Policy (CSP) restrictions. If your page has a CSP that blocks
blob:URLs inmedia-src, Safari will refuse to load the audio. Addblob:to themedia-srcdirective. - Disable Safari extensions or content blockers that might interfere with media loading, then retest.
- If all else fails, use a direct file URL or a data URL. These are the most reliable fallbacks for Safari.
Frequently Asked Questions
Why does a blob URL work in Chrome but not Safari?
Safari has stricter rules for blob URLs used in media elements, especially regarding MIME types and revocation timing. Chrome is more permissive.
Can I use a blob URL for audio autoplay in Safari?
No. Safari blocks audible autoplay regardless of the source URL. You must start playback from a user gesture.
Does Safari support blob URLs for video as well?
Yes, but the same restrictions apply: correct MIME type, no early revocation, and user gesture for playback with sound.
What MIME type should I use for an MP3 blob?
Use audio/mpeg. For AAC in an MP4 container, use audio/mp4.
Why does the audio element show an error after I revoke the blob URL?
Revoking the URL invalidates it. If the media element has not finished loading, it will fail. Revoke only after the canplay or loadeddata event.
Is there a way to play audio from a blob without a URL?
Not directly in Safari. You can use the Web Audio API to decode and play an ArrayBuffer, but that requires more code and does not use the <audio> element.