I'm trying to insert a text programmaticaly to a div of some websites but then the whole UI gets broken and the changes are rejected. It seems that any changes made programmaticaly are being tracked by MutationObserver. Yet it seems to be a common problem, as Grammarly developers seem to have had it:
Another—perhaps even bigger—issue with this approach is that websites don’t like it when somebody tries to change their DOM. The code running on the site expects that the DOM it created will not be changed by any other code. If that assumption is broken, bad things can happen. So both website and text editor developers started to look for ways to disable Grammarly, including such popular editors as ProseMirror, Quill.js, Draft.js, and many others. Source
But still there is a way out of this, as it seems:
If we were going to make any change to the DOM at all, we needed to make sure it wouldn’t be noticed by the code running on the page. Source
How is it possible that you could change the DOM without the code's notice?
EDIT:
An example would be Facebook. If you try to insert a text into the "Create Post" dialog, it crashes and closes.
I'm trying the following in chrome's console as "Create Post" is already shown:
editor = document.querySelectorAll(`[role="textbox"]`)[0];
editor.focus();
document.execCommand("insertText", false, "some text");