PressureObserver: unobserve() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Note: This feature is available in Web Workers, except for Service Workers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The unobserve() method of the PressureObserver interface stops the pressure observer callback from receiving pressure records from the specified source.

Syntax

js
unobserve(source)

Parameters

source

A string specifying which source to unobserve.

Return value

None (undefined).

Examples

Stop observing a specific source

The following example shows how to stop observing the "gpu" source after the observer previously observed both, the "cpu" and "gpu" sources.

js
const observer = new PressureObserver(callback);

observer.observe("cpu");
observer.observe("gpu");

// Callback now gets called whenever the pressure state changes for 'cpu' or 'gpu'.

observer.unobserve("gpu");

// Callback now only gets called whenever the pressure state changes for 'cpu'.

Specifications

Specification
Compute Pressure Level 1
# the-unobserve-method

Browser compatibility

BCD tables only load in the browser