“ontimeupdate” not working in my javascript

I am trying to output the time of the video duration as it progresses using the ontimeupdate event handler on the video but it doesn’t work.

I added a console.log in the code as well to test but it doesn’t work.

This is the html code

<video id="poster" class="w-100 h-100 image-align" autoplay muted loop src="<?= word("URL_VIDEO") ?>" loading="lazy"></video>

<span id="poster-duration" class="ms-4 text-white">00:00</span>

Here is my script

window.addEventListener('load', function() {
  var poster = document.getElementById('poster');

  poster.ontimeupdate = function(){
    document.getElementById('poster-duration').innerText = addO(Math.floor(poster.duration/60)) + ':' + addO(Math.round(poster.duration%60));
    console.log("hello")
  };

  function addO(n){
    if( n.toString().length < 2 ){
      return '0'+n;
    }

    return n;
  }

  // ...
})();