chromium/third_party/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-dialog-element/resources/common.js

function waitUntilLoadedAndAutofocused() {
  return new Promise(function(resolve) {
      var loaded = false;
      var autofocused = false;
      window.addEventListener('load', function() {
          loaded = true;
          if (autofocused)
              resolve();
      }, false);
      document.addEventListener('focusin', function() {
          if (autofocused)
              return;
          autofocused = true;
          if (loaded)
              resolve();
      }, false);
    });
}