Skip to content

Instantly share code, notes, and snippets.

@protomorph
Created May 14, 2023 21:24
Show Gist options
  • Save protomorph/a07aae77ba47f069b7a8535bfbbd5b97 to your computer and use it in GitHub Desktop.
Save protomorph/a07aae77ba47f069b7a8535bfbbd5b97 to your computer and use it in GitHub Desktop.

Revisions

  1. protomorph created this gist May 14, 2023.
    17 changes: 17 additions & 0 deletions observe-mutations.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@

    function observeMutations (element, callback, options) {
    const observer = new MutationObserver(mutations =>
    mutations.forEach(m => callback(m))
    )

    observer.observe(element, Object.assign({
    childList: true,
    attributes: true,
    attributeOldValue: true,
    characterData: true,
    characterDataOldValue: true,
    subtree: true,
    }, options))

    return observer
    }