Listen to Your Web Pages

Tom Hicks has put together a clever trick that pairs MutationObserver with the Web Audio API to turn DOM changes into sound. MutationObserver watches an element for changes to its attributes, text, or children; the Web Audio API supplies the tones. Drop the code into a page's console and you can hear essentially any DOM change as it happens.

const audioCtx = new (window.AudioContext || window.webkitAudioContext)()
const observer = new MutationObserver(function(mutationsList) {
  const oscillator = audioCtx.createOscillator()

  oscillator.connect(audioCtx.destination)
  oscillator.type = "sine"
  oscillator.frequency.setValueAtTime(
    Math.log(mutationsList.length + 5) * 880,
    audioCtx.currentTime,
  )

  oscillator.start()
  oscillator.stop(audioCtx.currentTime + 0.01)
})

observer.observe(document, {
  attributes: true,
  childList: true,
  subtree: true,
  characterData: true,
})  

Hicks is experimenting with other audio effects as well, such as a sweep-swoop sound. One existing browser extension, plink-plonk, already offers a version of this idea that includes sounds for network activity.

For anyone who wants to try it, the quickest route is a page with plenty of DOM activity.