javascriptjquerydom

Easily detect when user alters DOM


Is it possible to easily detect DOM manipulation by the user?

When a user uses the console in any modern browser, he/she can manipulate the DOM in ways the developer did not intend.

I have a web app that is very much tied to the DOM being in certain states and should the user do anything to the DOM via a console, I'd like to be notified.

The answer:

  1. Doesn't need to be browser agnostic
  2. Doesn't need to be perfect. I fully understand that most, if not all, methods could be circumvented, but I'd like a good general solution.
  3. Can't be too convoluted. I'm not interested in registering an event handler with all DOM events that checks some flag set when my code performs an DOM manipulation

Edit:

There appears to be some confusion in the answers I've received thus far. As pointed out in #2 above, I understand that most, if not all, methods can be circumvented.

In addition, this is an internal tool and thus is protect by a VPN. Further more, there is server-side checking. However, there are reasons, which I cannot elaborate upon, for me wanting to know when a user (who are few in number) manipulated the DOM.

To be clear, this isn't for security reasons. I'm not trying to stop malicious users here. Think of this more as out of curiosity.


Solution

  • I've received a lot of answers in which the respondent delivers advice about how to build a web app. While that may be useful to some readers, that isn't answering the question. Some, however, have attempted to answer. The closest I seen to a complete answer was given by @Keith. The only problem is that it fails the 'easy' test.

    It appears that the correct answer, as some have said, is NO - it isn't possible to easily detect DOM manipulation by a user.