Serializable errors
Serializable objects are objects that can be serialized and later deserialized in any JavaScript environment ("realm"). This allows them to, for example, be stored on disk and later restored, or cloned with structuredClone(), or shared between workers using DedicatedWorkerGlobalScope.postMessage().
The serialization may not include all the properties and other aspects of the original object. For example, a serialization of a DOMException must include the name and message properties, but whether it includes other properties is implementation dependent. As a result, a deserialized object may not be an identical clone/copy of the original object. The new deserialized object will however be a deep copy, so any properties that were serialized from the original object and then deserialized into the new object will share no references with the original object.
In some cases when serializing and deserializing an object, it makes sense to transfer some resources rather than creating a copy. Objects that can be transferred are called Transferable objects.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
api.DOMException.serializable_object | 77 | 79 | 101 | | 77 | |
| Built-in object | ||||||
| Serializable objects are objects that can be serialized and later deserialized in any JavaScript environment ("realm"). This allows them to, for example, be stored on disk and later restored, or cloned with Window.structuredClone, or shared between workers using DedicatedWorkerGlobalScope.postMessage(). | 77 | 79 | 103 | | 77 | |
| Serializable objects are objects that can be serialized and later deserialized in any JavaScript environment ("realm"). This allows them to, for example, be stored on disk and later restored, or cloned with Window.structuredClone, or shared between workers using DedicatedWorkerGlobalScope.postMessage(). | 77 | 79 | 103 | | 77 | |
| Serializable objects are objects that can be serialized and later deserialized in any JavaScript environment ("realm"). This allows them to, for example, be stored on disk and later restored, or cloned with Window.structuredClone, or shared between workers using DedicatedWorkerGlobalScope.postMessage(). | 77 | 79 | 103 | | 77 | |
| Serializable objects are objects that can be serialized and later deserialized in any JavaScript environment ("realm"). This allows them to, for example, be stored on disk and later restored, or cloned with Window.structuredClone, or shared between workers using DedicatedWorkerGlobalScope.postMessage(). | 77 | 79 | 103 | | 77 | |
| Serializable objects are objects that can be serialized and later deserialized in any JavaScript environment ("realm"). This allows them to, for example, be stored on disk and later restored, or cloned with Window.structuredClone, or shared between workers using DedicatedWorkerGlobalScope.postMessage(). | 77 | 79 | 103 | | 77 | |
| Serializable objects are objects that can be serialized and later deserialized in any JavaScript environment ("realm"). This allows them to, for example, be stored on disk and later restored, or cloned with Window.structuredClone, or shared between workers using DedicatedWorkerGlobalScope.postMessage(). | 77 | 79 | 103 | | 77 | |
| Serializable objects are objects that can be serialized and later deserialized in any JavaScript environment ("realm"). This allows them to, for example, be stored on disk and later restored, or cloned with Window.structuredClone, or shared between workers using DedicatedWorkerGlobalScope.postMessage(). | 77 | 79 | 103 | | 77 | |
- Version 103 serialized properties: `name`, `message`, `cause`, `fileName`, `lineNumber` and `columnNumber`.
- Version 104 adds serialization of `stack` in the main thread (`window.postMessage()` and `structuredClone()`).
- Version 110 adds serialization of `stack` in workers (`worker.postMessage()` and `structuredClone()`).
- Version 103 serializable properties: `name`, `message`, `cause`, `fileName`, `lineNumber` and `columnNumber`.
- Version 104 also serializes `stack` in the main thread (`window.postMessage()` and `structuredClone()`).
- Version 110 also serializes `stack` in workers (`worker.postMessage()` and `structuredClone()`).
- Version 103 serializable properties: `name`, `message`, `cause`, `fileName`, `lineNumber` and `columnNumber`.
- Version 104 also serializes `stack` in the main thread (`window.postMessage()` and `structuredClone()`).
- Version 110 also serializes `stack` in workers (`worker.postMessage()` and `structuredClone()`).
- Version 103 serializable properties: `name`, `message`, `cause`, `fileName`, `lineNumber` and `columnNumber`.
- Version 104 also serializes `stack` in the main thread (`window.postMessage()` and `structuredClone()`).
- Version 110 also serializes `stack` in workers (`worker.postMessage()` and `structuredClone()`).
- Version 103 serializable properties: `name`, `message`, `cause`, `fileName`, `lineNumber` and `columnNumber`.
- Version 104 also serializes `stack` in the main thread (`window.postMessage()` and `structuredClone()`).
- Version 110 also serializes `stack` in workers (`worker.postMessage()` and `structuredClone()`).
- Version 103 serializable properties: `name`, `message`, `cause`, `fileName`, `lineNumber` and `columnNumber`.
- Version 104 also serializes `stack` in the main thread (`window.postMessage()` and `structuredClone()`).
- Version 110 also serializes `stack` in workers (`worker.postMessage()` and `structuredClone()`).
- Version 103 serializable properties: `name`, `message`, `cause`, `fileName`, `lineNumber` and `columnNumber`.
- Version 104 also serializes `stack` in the main thread (`window.postMessage()` and `structuredClone()`).
- Version 110 also serializes `stack` in workers (`worker.postMessage()` and `structuredClone()`).
Syntax
// Serializable errors example
// See MDN Web Docs for details Live demo
Use cases
-
Using Serializable errors
Serializable objects are objects that can be serialized and later deserialized in any JavaScript environment ("realm").
Cautions
- Limited browser support. Check compatibility before use.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.