<script>
async function playToTheEnd() {
  const video = document.querySelector('video');
  const result = new Promise(r => video.onended = r);
  video.play();
  return await result;
}

async function playOneFrame() {
  const video = document.querySelector('video');
  const result = new Promise(r => video.onpause = r);
  video.ontimeupdate = () => {
    video.pause();
    video.ontimeupdate = null;
  };
  video.play();
  return await result;
}

async function playNFrames(n) {
  for (let i = 0; i < n; i++)
 