blob: URLs

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Blob (or object) URLs, URLs prefixed with the blob: scheme, enable integration of Blobs and MediaSources with other APIs that are only designed to be used with URLs, such as the <img> element. Blob URLs can also be used to navigate to as well as to trigger downloads of locally generated data. They are designed as opaque identifiers (that is, you shouldn't be handwriting them) and should be managed with the URL.createObjectURL() and URL.revokeObjectURL() functions.

Blob URLs are similar to data URLs, because they both allow representing in-memory resources as URLs; the difference is that data URLs embed resources in themselves and have severe size limitations, whereas blob URLs require a backing Blob or MediaSource and can represent larger resources.

Syntax

url
blob:<origin>/<uuid>
blob:

The scheme of the URL.

<origin>

The origin of the creator of this URL. If the creator's origin is opaque, then this part is implementation-defined.

<uuid>

A UUID.

Usage notes

Memory management

Each time you call createObjectURL(), a new object URL is created, even if you've already created one for the same object. Each of these must be released by calling URL.revokeObjectURL() when you no longer need them. As long as there's one object URL active, the underlying object cannot be garbage-collected and may cause memory leaks.

Browsers will release object URLs automatically when the document is unloaded; however, for optimal performance and memory usage, if there are safe times when you can explicitly unload them, you should do so.

However, avoid freeing the object URL too early. One common anti-pattern is the following:

js
const url = URL.createObjectURL(blob);
img.src = url;
img.addEventListener("load", () => {
  URL.revokeObjectURL(url);
});
document.body.appendChild(img);

Revoking the blob URL immediately after the image gets rendered would make the image unusable for user interactions (such as right-clicking to save the image or opening it in a new tab). For long-lived applications, you should revoke object URLs only when the resource is no longer accessible by the user (such as when the image is removed from the DOM).

Storage partitioning

Access to resources via blob URLs are subject to the same restrictions as all other storage mechanisms, i.e., state partitioning. Blob URLs have an associated creator origin (which is stored in the URL itself) and can only be fetched from environments where the storage key matches that of the creator environment. Blob URL navigations are not subject to this restriction, although browsers may enforce privacy measures such as noopener for cross-site navigations to a blob URL.

Using object URLs for media streams

In older versions of the Media Source specification, attaching a stream to a <video> element required creating an object URL for the MediaStream. This is no longer necessary, and browsers are removing support for doing this.

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

Fetching with the Range header

Blob URLs support fetching with the Range header to request partial content. This is particularly useful when working with large blobs, allowing you to fetch only the necessary parts of the blob instead of the entire content. For an example, see fetching a range from a blob URL.

Examples

Valid blob URLs

url
blob:https://example.org/40a5fb5a-d56d-4a33-b4e2-0acf6a8e5f64

Creating blob URLs

In this example, we first create a Blob from a <canvas>, create a blob URL to it, and finally attach the URL to an <img> element.

js
const canvas = document.querySelector("canvas");
canvas.toBlob((blob) => {
  const img = document.createElement("img");
  img.src = URL.createObjectURL(blob);
  document.body.appendChild(img);
});

Specifications

Specification
File API
# url

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
createObjectURL() static method
Chrome – Full support
Chrome 19 (Release date: 2012-05-15)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 19 (Release date: 2013-02-19)
footnote
footnote createObjectURL() is no longer available within the context of a ServiceWorker.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 6 (Release date: 2012-07-25)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 19 (Release date: 2013-02-19)
footnote
footnote createObjectURL() is no longer available within the context of a ServiceWorker.
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 6 (Release date: 2012-09-10)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 6 (Release date: 2012-09-10)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.9 (Release date: 2021-04-13)
footnote Full support
Node.js – Full support
Node.js 16.7 (Release date: 2021-08-17)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

See also