FinalizationRegistry.prototype.register()

Baseline Widely available *

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

* Some parts of this feature may have varying levels of support.

The register() method of FinalizationRegistry instances registers a value with this FinalizationRegistry so that if the value is garbage-collected, the registry's callback may get called.

Syntax

js
register(target, heldValue)
register(target, heldValue, unregisterToken)

Parameters

target

The target value to register.

heldValue

The value to pass to the finalizer for this target. This cannot be the target itself but can be anything else, including functions and primitives.

unregisterToken Optional

A token that may be used with the unregister method later to unregister the target value. If provided (and not undefined), this must be an object or a non-registered symbol. If not provided, the target cannot be unregistered.

Return value

None (undefined).

Exceptions

TypeError

Thrown in one of the following cases:

  • target is not an object or a non-registered symbol (object as opposed to primitives; functions are objects as well)
  • target is the same as heldValue (target === heldValue)
  • unregisterToken is not an object or a non-registered symbol

Description

See the Avoid where possible and Notes on cleanup callbacks sections of the FinalizationRegistry page for important caveats.

Examples

Using register

The following registers the value referenced by target, passing in the held value "some value" and passing the target itself as the unregistration token:

js
registry.register(target, "some value", target);

The following registers the value referenced by target, passing in another object as the held value, and not passing in any unregistration token (which means target can't be unregistered):

js
registry.register(target, { useful: "info about target" });

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-finalization-registry.prototype.register

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
register
Chrome – Full support
Chrome 84 (Release date: 2020-07-27)
footnote Full support
Edge – Full support
Edge 84 (Release date: 2020-07-16)
footnote Full support
Firefox – Full support
Firefox 79 (Release date: 2020-07-28)
footnote Full support
Opera – Full support
Opera 70 (Release date: 2020-07-27)
footnote Full support
Safari – Full support
Safari 14.1 (Release date: 2021-04-26)
footnote Full support
Chrome Android – Full support
Chrome Android 84 (Release date: 2020-07-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 60 (Release date: 2020-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 84 (Release date: 2020-07-27)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 14.6 (Release date: 2020-07-21)
footnote Full support
Non-registered symbol as target
Chrome – Full support
Chrome 109 (Release date: 2023-01-10)
footnote Full support
Edge – Full support
Edge 109 (Release date: 2023-01-12)
footnote Full support
Firefox – Full support
Firefox 146 (Release date: 2025-12-09)
footnote Full support
Opera – Full support
Opera 95 (Release date: 2023-02-01)
footnote Full support
Safari – Full support
Safari 16.4 (Release date: 2023-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 109 (Release date: 2023-01-10)
footnote Full support
Firefox for Android – Full support
Firefox for Android 146 (Release date: 2025-12-09)
footnote Full support
Opera Android – Full support
Opera Android 74 (Release date: 2023-03-13)
footnote Full support
Safari on iOS – Full support
Safari on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 21 (Release date: 2023-05-19)
footnote Full support
WebView Android – Full support
WebView Android 109 (Release date: 2023-01-10)
footnote Full support
WebView on iOS – Full support
WebView on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.28 (Release date: 2022-11-13)
footnote Full support
Node.js – Full support
Node.js 20 (Release date: 2023-04-18)
footnote Full support

Legend

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

Full support
Full support

See also