function whenDocumentReady() {
    if (document.readyState == 'complete')
      return Promise.resolve();

    return new Promise(function(resolve) {
      document.addEventListener('readystatechange', function f() {
        if (document.readyState == 'complete') {
          document.removeEventListener('readystatechange', f);
          resolve();
        }
      });
    });
  }
/**
   * @return {!Promise} A signal that the document is ready. Need to wait for
   *     this, otherwise the custom ExtensionOptions element might not have been
   *     registered yet.
   */
@return {!Promise} A signal that the document is ready. Need to wait for
this, otherwise the custom ExtensionOptions element might not have been
registered yet.
@return { !Promise } A signal that the document is ready . Need to wait for this otherwise the custom ExtensionOptions element might not have been registered yet .
function whenDocumentReady() {
    if (document.readyState == 'complete')
      return Promise.resolve();
    return new Promise(function(resolve) {
      document.addEventListener('readystatechange', function f() {
        if (document.readyState == 'complete') {
          document.removeEventListener('readystatechange', f);
          resolve();
        }
      });
    });
  }
function whenDocumentReady ( ) { if ( document . readyState == 'complete' ) return Promise . resolve ( ) ; return new Promise ( function ( resolve ) { document . addEventListener ( 'readystatechange' , function f ( ) { if ( document . readyState == 'complete' ) { document . removeEventListener ( 'readystatechange' , f ) ; resolve ( ) ; } } ) ; } ) ; }
@return {!Promise} A signal that the document is ready.
@return { !Promise } A signal that the document is ready .