PressureObserver Class

Observes the pressure of the sources of the device (https://w3c.github.io/compute-pressure/#the-pressureobserver-object), read from the PressureSourceProvider of the browsing context (ComputePressureOptions.Provider). Its callback is invoked from a task with the records queued since the previous call, while the document has the focus.

public sealed class PressureObserver

Constructors

NameDescription
PressureObserver(GlobalScope, PressureUpdateCallback)Creates an observer of the pressure of a global object.
PressureObserver(PressureUpdateCallback)Creates an observer of the pressure of the current global object (https://w3c.github.io/compute-pressure/#the-constructor-method).

PressureObserver overloads

PressureObserver(GlobalScope, PressureUpdateCallback)

ComputePressure.cs

Creates an observer of the pressure of a global object.

public PressureObserver(GlobalScope global, PressureUpdateCallback callback)
Parameters
global GlobalScope
The window or the worker whose observer it is.
callback PressureUpdateCallback
The callback invoked with the records of the changes.

PressureObserver(PressureUpdateCallback)

ComputePressure.cs

Creates an observer of the pressure of the current global object (https://w3c.github.io/compute-pressure/#the-constructor-method).

public PressureObserver(PressureUpdateCallback callback)
Parameters
callback PressureUpdateCallback
The callback invoked with the records of the changes.
See also

Properties

NameDescription
KnownSourcesGets the source types supported by the user agent, in alphabetical order (https://w3c.github.io/compute-pressure/#the-knownsources-attribute).

KnownSources

ComputePressure.cs

Gets the source types supported by the user agent, in alphabetical order (https://w3c.github.io/compute-pressure/#the-knownsources-attribute).

public static IReadOnlyList<PressureSource> KnownSources { get; }

Methods

NameDescription
Disconnect()Stops observing all the sources (https://w3c.github.io/compute-pressure/#the-disconnect-method): the queued records are removed.
Observe(PressureSource, PressureObserverOptions?)Starts observing a source (https://w3c.github.io/compute-pressure/#the-observe-method). The task fails with a NotAllowedError DomException when a document of the global object is not allowed to use the compute-pressure feature, a NotSupportedError when the source is not supported by the PressureSourceProvider, and an AbortError when PressureObserver.Unobserve or PressureObserver.Disconnect is called before it completes.
TakeRecords()Returns the queued records and empties the queue (https://w3c.github.io/compute-pressure/#the-takerecords-method).
Unobserve(PressureSource)Stops observing a source (https://w3c.github.io/compute-pressure/#the-unobserve-method): its queued records are removed.

Disconnect()

ComputePressure.cs

Stops observing all the sources (https://w3c.github.io/compute-pressure/#the-disconnect-method): the queued records are removed.

public void Disconnect()

Observe(PressureSource, PressureObserverOptions?)

ComputePressure.cs

Starts observing a source (https://w3c.github.io/compute-pressure/#the-observe-method). The task fails with a NotAllowedError DomException when a document of the global object is not allowed to use the compute-pressure feature, a NotSupportedError when the source is not supported by the PressureSourceProvider, and an AbortError when PressureObserver.Unobserve or PressureObserver.Disconnect is called before it completes.

public Task Observe(PressureSource source, PressureObserverOptions? options = null)

Parameters

source PressureSource
The observed source.
options PressureObserverOptions?
The requested sample interval.

Returns

Task

See also

TakeRecords()

ComputePressure.cs

Returns the queued records and empties the queue (https://w3c.github.io/compute-pressure/#the-takerecords-method).

public IReadOnlyList<PressureRecord> TakeRecords()

Unobserve(PressureSource)

ComputePressure.cs

Stops observing a source (https://w3c.github.io/compute-pressure/#the-unobserve-method): its queued records are removed.

public void Unobserve(PressureSource source)

Parameters

source PressureSource
The source that is no longer observed.

See also