Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

1.7 KB
Raw Blame
<!doctype html>
<html>
<body>
  <div id="target">alpha</div>
  <script>
    const target = document.getElementById('target');

    function observeErrorName(options) {
      try {
        new MutationObserver(() => {}).observe(target, options);
        return 'ok';
      } catch (error) {
        return error && error.name ? error.name : String(error);
      }
    }

    window.moInvalidNoSignals = observeErrorName({ subtree: true });
    window.moInvalidAttributeOldValue = observeErrorName({ attributes: false, attributeOldValue: true });
    window.moInvalidAttributeFilter = observeErrorName({ attributes: false, attributeFilter: ['data-a'] });
    window.moInvalidCharacterDataOldValue = observeErrorName({ characterData: false, characterDataOldValue: true });

    let attributeRecords = null;
    const attributeObserver = new MutationObserver((records) => {
      attributeRecords = records;
      attributeObserver.disconnect();
    });
    attributeObserver.observe(target, { attributeOldValue: true });
    target.setAttribute('data-auto', '1');
    target.setAttribute('data-auto', '2');

    let textRecords = null;
    const textObserver = new MutationObserver((records) => {
      textRecords = records;
      textObserver.disconnect();
    });
    textObserver.observe(target.firstChild, { characterDataOldValue: true });
    target.firstChild.data = 'beta';

    Promise.resolve().then(() => {
      window.moAutoAttributes = attributeRecords && attributeRecords.length === 2 &&
        attributeRecords[0].oldValue === null &&
        attributeRecords[1].oldValue === '1';
      window.moAutoCharacterData = textRecords && textRecords.length === 1 &&
        textRecords[0].oldValue === 'alpha';
    });
  </script>
</body>
</html>