1

So I know that blobs are only available in the tab they were created in, but somehow I get an error message that the blob couldn't been found. It doesn't matter where I try it.

For example YouTube videos are blobs, I can get the object URL of it with

document.getElementsByTagName('video')[0].currentSrc /// => 'blob:http://youtube.com/asddasd-asdasd-asdasd-asddsa'

now if I try to get the blob with

fetch(url)

I get an error that the blob couldn't been found.

1
  • Maybe the blob is no longer available, youtube downloads videos small chunks at a time, each chunk would be a different blob. Commented Jan 6, 2020 at 13:56

2 Answers 2

3

Youtube videos blobURIs are not pointing to Blobs but to MediaSources.

Blobs are not the only objects we can point to using the URL.createObjectURL() method, we used to be able to pass MediaStreams too, and more importantly to our case, we can still pass MediaSource objects.

const source = new MediaSource();
const url = URL.createObjectURL( source ); // this doesn't throw
console.log( url ); // that's a valid blob URI

fetch( url ).catch( console.error ); // nothing to fetch there

YouTube does fetch the data as ArrayBuffers, and then populate a MediaSource with this data.

There is natively no way of retrieving the original MediaSource from the blobURI, and even though we can override URL.createObjectURL to get it back, we can't retrieve the actual data passed to the MediaSource anyway...

Sign up to request clarification or add additional context in comments.

Comments

0

I think you should fetch with a standard URL first, and then indicate that it should be interpreted as a blob.

const url = "http://youtube.com/asddasd-asdasd-asdasd-asddsa"
fetch(url)
  .then(response => response.blob())
  .then(console.log)

But you might run into some CORS issues when fetching youtube!

7 Comments

If I do it with "blob:" then I get the "ERR_FILE_NOT_FOUND" error. If I do it without "blob:" I get a 404 error.
@Mointy can you check the Network tab of the DevTools to get more information on why the request fails?
Here is one image for a request with and without "blob":ibb.co/xHGYG6Y, ibb.co/ydWbK5V
the blob: protocol isn't supported by all browsers and seems to be forbidden (?) when requesting cross origin resources.
Since I use it in my content script in my browser extension, it should work. The content script is directly injected into the site, so there is no cross origin problem. I will try it in google chrome, I was using edge with chromium engine(which means, it should still work)...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.