简体   繁体   English

转储整个DOM树(包括事件监听器和变异观察器)

[英]Dump the whole DOM tree (including event listeners and mutation observers)

I have html page built by javascript at runtime. 我有运行时由javascript构建的html页面。 At some moment of time I want to create a backup of this page to be able to restore it later. 在某些时候,我想创建此页面的备份,以便以后能够恢复它。 The page is described by DOM, so it's logically to save the DOM itself. 该页面由DOM描述,因此逻辑上保存DOM本身。 The problem is - it seems there are no legit ways to do so. 问题是 - 似乎没有合法的方法可以做到这一点。

I only found XMLSerializer interface which can be used to serialize html only (so, that's not the right tool). 我只发现了XMLSerializer接口,它只能用于序列化html(所以,这不是正确的工具)。 But I need to save mutation observers and event listeners, such 'restored' page would behave as it's ancestor. 但是我需要保存变异观察者和事件监听器,这样的“恢复”页面就像它的祖先一样。

I also thought about recording to log file javascript operations over DOM. 我还考虑过在DOM上记录日志文件的javascript操作。 But the page that is building itself in runtime is huge and complicated, so such approach will cost a lot of time. 但是在运行时构建自己的页面庞大而复杂,因此这种方法将耗费大量时间。

Any ideas? 有任何想法吗?

All infos including listeners are stored in the window object. 包括侦听器在内的所有信息都存储在window对象中。 You can inspect it: console.log(window). 您可以检查它:console.log(窗口)。

To dump the window object just copy it and send it to an api to store it. 要转储窗口对象,只需复制它并将其发送到api即可存储它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM