title: How can I observe the whole body with MutationObserver?
body: <p>I want a certain function to be called whenever another script adds a <code>div</code> to the <code>body</code>.</p>
  
  <p>I tried: </p>
  
  <pre><code>var dom_observer = new MutationObserver(function(mutation) {
      console.log('function called');
  });
  var container = document.body;
  console.log(container);
  var config = { attributes: true, childList: true, characterData: true };
  dom_observer.observe(container, config);
  </code></pre>
  
  <p>I tried setting <code>container</code> to <code>document.body</code> (example above) and to <code>document.querySelector('body')</code>. In both cases, <code>console.log()</code> displayed <code>null</code> and I got the following error: <code>TypeError: Argument 1 of MutationObserver.observe is not an object.</code>. The callback function was not called when a <code>div</code> was added to the <code>body</code>.</p>
  
  <p>I tried setting it to <code>document.getElementsByTagName("body")[0]</code> and to <code>document.documentElement.childNodes[1]</code>. In both cases, <code>console.log()</code> displayed<code>undefined</code> and the callback function was still never called.</p>