How can I freeze all JS DOM changes completely using JS from a chrome extension?
Example: a user hovers over a button, which onMouseEnter
displays a modal and hides it onMouseLeave
.
If I bind a callback to a certain keyboard-shortcut, how can I freeze the DOM in that point in time so that the modal stays visible and nothing can change in the DOM anymore (until the shortcut is pressed again) ?
I know there might not be a direct API to freeze the DOM, but I'm looking for any ideas that can help me do this.
One Idea I tried was:
- When user presses the shortcut (toggles the freeze on)
- grab the html node in current state
- query and remove all script nodes
- clone the html node (to get rid of bound listeners)
- replace actual html node with the cleaned-out cloned html node (one without js scripts)
- grab the html node in current state
- When user presses the shortcut again (toggles the freeze off)
- replace the original DOM (with all script tags) back
However that didn't work, if I hovered my mouse over the button and the modal showed up, then I invoked that algorithm with the keybind, the cloning would happen successfully and script tags would be removed, however when I remove the mouse from the button the modal would just close. As if the button was still bound to onMouseLeave
.
Edit: I'm trying to do this from an external script, specifically a chrome extension.