Table of Contents

Class MutationObserver

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The MutationObserver interface provides the ability to watch for changes being made to the DOM tree. It is designed as a replacement for the older Mutation Events feature, which was part of the DOM3 Events specification.

[Value("MutationObserver")]
public class MutationObserver
Inheritance
MutationObserver
Inherited Members

Remarks

Constructors

MutationObserver()

public MutationObserver()

MutationObserver(MutationCallback)

The DOM MutationObserver()
constructor — part of the MutationObserver interface — creates and
returns a new observer which invokes a specified callback when DOM events
occur.

public MutationObserver(MutationCallback callback)

Parameters

callback MutationCallback

Remarks

DOM observation does not begin immediately; the
Observe(Node, MutationObserverInit) method must be called first to
establish which portion of the DOM to watch and what kinds of changes to watch for.

See also on MDN

Methods

Disconnect()

The MutationObserver method
disconnect() tells the observer to stop watching for
mutations.

[Value("disconnect")]
public GlobalObject.Undefined Disconnect()

Returns

GlobalObject.Undefined

undefined.

NOTE
All notifications of mutations that have already been
detected, but not yet reported to the observer, are discarded.
To hold on to and handle the detected but unreported mutations, use
the TakeRecords() method.

Remarks

The observer can be reused by calling its
Observe(Node, MutationObserverInit) method again.

See also on MDN

Observe(Node, MutationObserverInit)

The MutationObserver method observe() configures the MutationObserver
callback to begin receiving notifications of changes to the DOM that match the given options.

[Value("observe")]
public GlobalObject.Undefined Observe(Node target, MutationObserverInit options = null)

Parameters

target Node
options MutationObserverInit

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Depending on the configuration, the observer may watch a single Node in the DOM tree, or that node and some or all of its descendant nodes. The same node can be observed by multiple observers, and the same MutationObserver can watch for changes to different parts of the DOM tree and/or different types of changes by calling observe() multiple times on the same
MutationObserver.

To stop the MutationObserver (so that none of its callbacks will be triggered any longer), call Disconnect().

See also on MDN

TakeRecords()

The MutationObserver method
takeRecords() returns a list of all matching DOM changes
that have been detected but not yet processed by the observer's callback function,
leaving the mutation queue empty.

[Value("takeRecords")]
public List<MutationRecord> TakeRecords()

Returns

List<MutationRecord>

An array of MutationRecord objects, each describing one change applied to
the observed portion of the document&apos;s DOM tree.

NOTE
The queue of mutations which have occurred, but not been
delivered to the observer&apos;s callback is left empty after calling
takeRecords().

Remarks

The most common use case for this is to
immediately fetch all pending mutation records immediately prior to disconnecting the
observer, so that any pending mutations can be processed when shutting down the
observer.

See also on MDN