Selenium + Node.js: is it possible to listen for reoccurring events?

I am working on a site that is heavily powered by AJAX/REST API calls, which broadcast events on completion/failure.

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 console.log() -- and keep that listener running to report any new occurrences of the "customEvent"

My latest implementation looks like this:

driver = await new Builder().forBrowser('chrome').build();
await driver.get('');


  document.addEventListener("customEvent", (e) => {
    return e;
then( (e) => { console.log( e ); } );

I've also tried executeAsyncScript()

The problems that I'm encountering:

  • This code just wants to run once (doesn't stay open)
  • It either doesn't catch the "customEvent" or it blocks the code from continuing, that would have triggered the event.