Set content-type on blob
First I would wonder if when you say "error" you actually mean "warning". They are really two different things and the browser treats them differently (it usually only tracks/raises warnings when the developer tools are open etc).
So first I would challenge the premise that this is even an issue ( the overhead of the browser "auto-typing" the blob versus the overhead of "newing" up a Blob etc ).
But, that said, the blob.type property is indeed inmutable in JavaScript and as such you have to set it when the blob is "newed". In your case it sounds like you are getting the data from a Objective-C socket and just daisy chaining it down via:
ws.send(fromObjectiveCSocket, {binary: true, mask: true});
The blob data itself from the Objective-C socket is not containing the "header" type data of the type when it sends it across, and it sounds like your node is not touching the blob at all (have you tried decorating the new Blob in your node and then sending that down the socket to see if it retains the typing?).
So what is happening is that the websocket is sending down just the blob data as it got it and when the receiving javascript gets it, it is implicitly typing it with a new Blob right then and there, just with a blank type.
So essentially no, there does not seem to be any way around the new Blob construction if you really want to get rid of this warning. Even if you tried tricks like adding the type into the blob data and then splicing it out etc, you still can't get around the websocket receiving code implicitly typing it as a blob with a blank type.
Let's consider you have Blob instance (blob
). You can use then slice
method on it:
blob = blob.slice(0, blob.size, "image/jpeg")
and that's it.
It just creates a new blob with the same data, but with the new type.