title: Selenium + Node.js: is it possible to listen for reoccurring events?
body: <p>I am working on a site that is heavily powered by AJAX/REST API calls, which broadcast events on completion/failure.</p>
  
  <p>What I am trying to accomplish is to listen for these document events and trigger a function in Selenium (Node.js) -- right now I'm settling for a <code>console.log()</code> -- and keep that listener running to report any new occurrences of the "customEvent"</p>
  
  <p>My latest implementation looks like this:</p>
  
  <pre><code>driver = await new Builder().forBrowser('chrome').build();
  await driver.get('http://www.google.com/');
  </code></pre>
  
  <p>...</p>
  
  <pre><code>driver.executeScript(`
    document.addEventListener("customEvent", (e) =&gt; {
      return e;
    })`).
  then( (e) =&gt; { console.log( e ); } );
  </code></pre>
  
  <p>I've also tried <code>executeAsyncScript()</code></p>
  
  <p>The problems that I'm encountering:</p>
  
  <ul>
  <li>This code just wants to run once (doesn't stay open)</li>
  <li>It either doesn't catch the "customEvent" or it blocks the code from continuing, that would have triggered the event.</li>
  </ul>