createObjectURL doesnt work if run on Chrome

26,572

From MDN:

This method is prefixed in Chrome and Webkit as window.webkitURL.createObjectURL().

You should test if URL exists and then use the appropriate object:

(window.URL ? URL : webkitURL).createObjectURL(evt.data);
Share:
26,572
Eldon Lesley
Author by

Eldon Lesley

Updated on July 05, 2022

Comments

  • Eldon Lesley
    Eldon Lesley almost 2 years

    Hello everyone,

    I've tried to retrieve an image from a websocket server (in .NET) I send the image as bytes then I retrieve it on the client side, the code for retrieving on the client side (using canvas and JavaScript):

    var c=document.GetElementById("myCanvas");
    var ctx=c.getContext("2d");
    ws.onmessage=function(evt)
    {
        var image=new Image();
        image.src=URL.createObjectURL(evt.data);
        ctx.drawImage(image,0,0);
    }
    

    it perfectly displays the picture on firefox, but at Chrome, it just returning undefined and won't load the image through createObjectURL I'm using Chrome 18.0.1025.162

    any idea?