MutationObserver not working

Hi.

I have been requested to use a MutationObserver instead of mutation events. Using a MutationObserver was the first implementation in my add on, but it didn’t work - so I had to use mutation events.

The simple example (derived from the examples in the docs)

var observer = new MutationObserver(function(mutations) {});

generates an error message:

ReferenceError: MutationObserver is not defined

So how can the reviewers request something that doesn’t work? Or is there a possibility to make it work?

You may be in some scope where MutationObserver is not defined. It is not some inherent feature of javascript, but a property of the window object. If the window object is not the global in your scope then you’ll have to explicitly specify which window you want a mutation observer for. For example, content.MutationObserver.

1 Like