Randomised video background webflow

I’m trying to get a randomised video background for my webflow site. I’ve tried doing it in with Javascript pulling in the following links:

“https://s3.amazonaws.com/webflow-prod-assets/63e4f3713963c5649a7bb382/63f787b42f81b8648e70feda_Goldfish.mp4” 10% of the time

“https://s3.amazonaws.com/webflow-prod-assets/63e4f3713963c5649a7bb382/63f787fb4b2937100792cf14_Black%20Texture.mp4” 45% of the time

and

“https://s3.amazonaws.com/webflow-prod-assets/63e4f3713963c5649a7bb382/63eb5f178ae8e42595f1d524_Fish%20TV.mp4” 45% of the time

This is the code I’ve tried – this was put in section of the custom code in Webflow.

(function() {
  var videoUrls = [
    {
      url: "https://s3.amazonaws.com/webflow-prod-assets/63e4f3713963c5649a7bb382/63f787fb4b2937100792cf14_Black%20Texture.mp4",
      probability: 0.45
    },
    {
      url: "https://s3.amazonaws.com/webflow-prod-assets/63e4f3713963c5649a7bb382/63f787b42f81b8648e70feda_Goldfish.mp4",
      probability: 0.1
    },
    {
      url: "https://s3.amazonaws.com/webflow-prod-assets/63e4f3713963c5649a7bb382/63eb5f178ae8e42595f1d524_Fish%20TV.mp4",
      probability: 0.45
    }
  ];

  var backgroundVideo = document.querySelector('.bg-video');

  // Create an array with one element for each video URL, where each element's value
  // is the URL repeated a number of times proportional to its probability
  var videoUrlsWeighted = videoUrls.reduce(function(acc, curr) {
    var weightedArray = Array(Math.round(curr.probability * 100)).fill(curr.url);
    return acc.concat(weightedArray);
  }, []);

  function playRandomVideo() {
    // Choose a random video URL from the weighted array
    var randomIndex = Math.floor(Math.random() * videoUrlsWeighted.length);
    var randomUrl = videoUrlsWeighted[randomIndex];

    // Set the background video to the chosen URL
    backgroundVideo.style.backgroundImage = 'url(' + randomUrl + ')';
  }

  // Play a random video when the page loads
  playRandomVideo();

  // Play a new random video after the current video has finished
  backgroundVideo.addEventListener('ended', function() {
    playRandomVideo();
  });
  
  // Set the videos to loop
  backgroundVideo.loop = true;
})();