Is it possible to detect changes in the DOM and do it wrong?

Is it possible to track DOM insertions and changes in the DOM in some way, and then decide whether this is done in some way or not? Through some parameter, to cancel the event or cause the event does not occur when I perform a custom action, for example, one second callback.

I don’t need to work in all browsers, and more specifically, I need it to be applied in some situations and specifically run tests for the extension that I create for Google Chrome, so the browser is Google Chrome.

There is an element in the DOM that I modify, extending and applying this right, but this DOM element is updated after a certain action (send a message) to send the DOM element is “updated” and returns to the initial state of deleting the changes that I made, to me you should always save your changes, and not the "original" imposed by the modification of the DOM through the site.

+3
source share
1 answer

Change Monitoring:

What you are looking for is this MutationObserver.

Example from MDN

// select the target node
var target = document.querySelector('#some-id');

// create an observer instance
var observer = new MutationObserver(function(mutations) {
  mutations.forEach(function(mutation) {
    console.log(mutation.type);
  });    
});

// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };

// pass in the target node, as well as the observer options
observer.observe(target, config);

They work with the latest version of Chrome® , so you should have no problem using them in an extension.

As for bringing it back, I suspect you will have to push it back.

:

, . , , , .

:

, , .

+5

All Articles