tintin
tintin

Reputation: 21

Intercept access to DOM by JavaScript

I wanted to know how do I intercept a DOM access by a JavaScript. Are there any tools or whitepapers available on this ? (Else I will need to write one!)

The idea behind the interception is something to do with a security module for web browsers.

Thanks.

Upvotes: 2

Views: 868

Answers (1)

Tim Down
Tim Down

Reputation: 324627

The best you can do is use DOM mutation events. There are various events such as DOMNodeInserted, DOMNodeRemoved, DOMAttrModified etc (see the DOM events spec, linked to above). There is a general catch-all event called DOMSubtreeModified that is fired after any individual DOM mutation; this event bubbles, so you can set a listener on the document to be notified of all changes to the document's DOM.

document.addEventListener("DOMSubtreeModified", function(evt) {
    console.log("DOM mutation", evt);
}, false);

These events are supported in most recent browsers, with the exception of IE (up to and including version 8) and Opera, which supports some evenbts but notably not DOMSubtreeModified.

Upvotes: 1

Related Questions