← Back to Discord Forum

how to listen for events in a global JS window object

Hi, we are successfully login a user using in a form with JS and node with the click of a button, and then trying to wait for an event 'login' message sent to a global JS variable window.EV but we are never receiving the event message and the test enters in a loop and never ends.

const isLoginOk = await page.evaluate(() => {
  return new Promise(function (resolve) {
       window.EV.Event.on(window.EV.Event.LOGIN_SUCCESS, (ev) => {           // <<----------   event is never received, never enters here
          console.log('LOGIN SUCCESS');


await loginSubmitButon.click();

This thread is trying to answer question "Why is the 'login' event message sent to a global JS variable window.EV not being received, causing a test to enter into a loop and never end?"

1 reply

solved it by clicking the button after setting the global listener, and not clicking the button outside of the Promise, so it always resolves.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.