javascript - Failed to execute 'createObjectURL' on 'URL':

ID : 20237

viewed : 4

Tags : javascriptcreateobjectjavascript

Top 5 Answer for javascript - Failed to execute 'createObjectURL' on 'URL':

vote vote


I experienced the same error, when I passed raw data to createObjectURL:


It has to be a Blob, File or MediaSource object, not data itself. This worked for me:

var binaryData = []; binaryData.push(data); window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"})) 

Check also the MDN for more info:


Back in the day we could also use createObjectURL() method with MediaStream objects. This use has been dropped by the specs and by browsers.
If you need to set a MediaStream as the source of an HTMLMediaElement just attach the MediaStream object directly to the srcObject property of the HTMLMediaElement e.g. <video> element.

const mediaStream = new MediaStream(); const video = document.getElementById('video-player'); video.srcObject = mediaStream; 

However, if you need to work with MediaSource, Blob or File, you still have to create a blob:// URL with URL.createObjectURL() and assign it to HTMLMediaElement.src.

Read more details here:

vote vote


This error is caused because the function createObjectURL no longer accepts media stream object for Google Chrome

I changed this:


to this:


This worked for me.

vote vote


My code was broken because I was using a deprecated technique. It used to be this:

video.src = window.URL.createObjectURL(localMediaStream);; 

Then I replaced that with this:

video.srcObject = localMediaStream;; 

That worked beautifully.

EDIT: Recently localMediaStream has been deprecated and replaced with MediaStream. The latest code looks like this:

video.srcObject = new MediaStream(); 


  1. Deprecated technique:
  2. Modern deprecated technique:
  3. Modern technique:
vote vote


Video with fall back:

try {   video.srcObject = mediaSource; } catch (error) {   video.src = URL.createObjectURL(mediaSource); }; 


vote vote


I had the same error for the MediaStream. The solution is set a stream to the srcObject.

From the docs:

Important: If you still have code that relies on createObjectURL() to attach streams to media elements, you need to update your code to simply set srcObject to the MediaStream directly.

Top 3 video Explaining javascript - Failed to execute 'createObjectURL' on 'URL':