Drop the entire DOM tree (including event listeners and mutation observers)

I have an html page created by javascript at runtime. At some point, I want to back up this page in order to restore it later. The page is described by the DOM, so logically it is necessary to save the DOM itself. The problem is that there are no legal ways to do this.

I just found the XMLSerializer interface that can only be used to serialize html (so this is not the right tool). But I need to keep mutation observers and event listeners, such a "restored" page will behave like an ancestor.

I also thought about writing to a javascript file for DOM operations. But a page that builds itself at runtime is huge and complex, so this approach will cost a lot of time.

Any ideas?

+4
source share
1 answer

All information, including listeners, is stored in the window object. You can check it out: console.log (window).

To reset a window object, just copy it and send it to the api to save it.

0
source

All Articles