title: document.caretPositionFromPoint grabbing too high
body: <p>I'm working on an update to <a href="https://github.com/brettz9/jump-to-anchor" rel="nofollow noreferrer">my &quot;jump-to-anchor&quot; add-on</a> which is a Firefox add-on to let you right-click somewhere in a doc to (hopefully) get the closest anchor above the click point.</p>
  <p>After submitting the add-on, I realized I could improve the algorithm by finding the actual text node where clicked, and look up from there (instead of the first children of the current clicked element). However, in my tests (against a page I happened to be reading, <a href="https://www.rfc-editor.org/rfc/rfc5323#section-2.3.2" rel="nofollow noreferrer">https://www.rfc-editor.org/rfc/rfc5323#section-2.3.2</a> ), the text node grabbed via <a href="https://developer.mozilla.org/en-US/docs/Web/API/document.caretPositionFromPoint" rel="nofollow noreferrer"><code>document.caretPositionFromPoint</code></a> is higher than expected.</p>
  <pre><code>var x = 0, y = 0;
  window.addEventListener('click', function (e) {
      if (e.button === 2) { // Avoid grabbing for the actual selection // Doesn't seem to execute on the final context menu click anyways
          x = e.pageX;
          y = e.pageY;
      }
  });
  self.on('click', function () { // , data
      // I added the next two lines just in case the user clicked off screen
      x = x &gt; window.mozInnerScreenX ? window.mozInnerScreenX : (x &lt; 0 ? 0 : x);
      y = y &gt; window.mozInnerScreenY ? window.mozInnerScreenY : (y &lt; 0 ? 0 : y);
      var caretPosition = document.caretPositionFromPoint(x, y);
      var node = caretPosition.offsetNode;
  
      // Doesn't grab the right node.nodeValue here always--seems to grab too high up
  
      // (Then search the node for an anchor, or recursively check the deepest child of the previous element sibling on up and keep looking for previous element siblings.)
  });
  </code></pre>
  <p>Sound like a bug?</p>
  <p><strong>UPDATE:</strong></p>
  <p>Steps to reproduce:</p>
  <ol>
  <li>Install the XPI from <a href="https://github.com/brettz9/jump-to-anchor/tree/document.caretPositionFromPoint" rel="nofollow noreferrer">https://github.com/brettz9/jump-to-anchor/tree/document.caretPositionFromPoint</a> (or use <code>cfx xpi</code> with SDK to install from source)</li>
  <li>Go to <a href="https://www.rfc-editor.org/rfc/rfc5323#section-2.3.2" rel="nofollow noreferrer">https://www.rfc-editor.org/rfc/rfc5323#section-2.3.2</a></li>
  <li>Try right-clicking within section 2.3.3 (note: 2.3.3) and see it often go all the way up to the &quot;#page-10&quot; anchor instead of the &quot;#section-2.3.3&quot; anchor.</li>
  </ol>
  <p>(In the current code at Github, I have the <code>e.button === 2</code> check commented out, but the result is the same.)</p>