Failed to execute ‘createObjectURL’ on ‘URL’:

Posted on

Failed to execute ‘createObjectURL’ on ‘URL’: – Even if we have a good project plan and a logical concept, we will spend the majority of our time correcting errors abaout javascript and createobject. Furthermore, our application can run without obvious errors with JavaScript, we must use various ways to ensure that everything is operating properly. In general, there are two types of errors that you’ll encounter while doing something wrong in code: Syntax Errors and Logic Errors. To make bug fixing easier, every JavaScript error is captured with a full stack trace and the specific line of source code marked. To assist you in resolving the JavaScript error, look at the discuss below to fix problem about Failed to execute ‘createObjectURL’ on ‘URL’:.

Problem :

Display Below error in Safari.

Failed to execute ‘createObjectURL’ on ‘URL’: No function was found that matched the signature provided.

My Code is:

function createObjectURL(object) {
    return (window.URL) ? window.URL.createObjectURL(object) : window.webkitURL.createObjectURL(object);

This is my Code for image:

function myUploadOnChangeFunction() { 
    if (this.files.length) { 
       for (var i in this.files) { 
           if (this.files.hasOwnProperty(i)) { 
              var src = createObjectURL(this.files[i]); 
              var image = new Image(); 
              image.src = src; 
              imagSRC = src; 
              $('#img').attr('src', src); 

Solution :

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 = [];
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:

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.

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:

Video with fall back:

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


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.

The problem is that the keys provided in the loop do not refer to the index of the file.

for (var i in this.files) {

The output of the above code is:


But what was expected was:


Then the error occurs when the browser tries to execute, for example:


I suggest implementation based on the following code:

var files = this.files;
for (var i = 0; i < files.length; i++) {
    var file = files[i],
        src = (window.URL || window.webkitURL).createObjectURL(file);

I hope this can help someone.


If you are using ajax, it is possible to add the options xhrFields: { responseType: 'blob' }:

  url: 'yourURL',
  type: 'POST',
  data: yourData,
  xhrFields: { responseType: 'blob' },
  success: function (data, textStatus, jqXHR) {
    let src = window.URL.createObjectURL(data);

If you are using angular this tutorial will be helpful: link. However you will need to replace this line: = window.URL.createObjectURL(stream);

with this, since createObjectURL() is deprecated on chrome for MediaStream. = stream;

I tried few things, but for me simply assigning stream to src worked.


//my code was:

this._videoEl = videoEl;
            video : true
        }).then(stream => {
            this._videoEl.src = URL.createObjectURL(stream);
        }).catch(err => {

//and replace to this worked for me :

this._videoEl = videoEl;
            video : true
        }).then(stream => {
            this._videoEl.srcObject = stream;
        }).catch(err => {

Leave a Reply

Your email address will not be published. Required fields are marked *