Record and replay Javascript

前端 未结 6 986
时光取名叫无心
时光取名叫无心 2020-12-23 23:09

I know it is possible to record mouse movements, scrolling and keystrokes. But what about changes to the document? How can I record changes to the document?

Here is

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 23:32

    Lately, we can now use MutationObserver

    MutationObserver provides developers with a way to react to changes in a DOM. It is designed as a replacement for Mutation Events defined in the DOM3 Events specification.

    Slow demo, because the console.log message is huge.

    var mutationObserver = new MutationObserver(function(mutations) {
      mutations.forEach(function(mutation) {
        console.log(mutation)
      })
    })
    mutationObserver.observe(watchme, {
      attributes: true,
      characterData: true,
      childList: true,
      subtree: true,
      attributeOldValue: true,
      characterDataOldValue: true
    })
    Hello world!

提交回复
热议问题