player.js icon indicating copy to clipboard operation
player.js copied to clipboard

Event callbacks silently breaking when 'Uncaught ReferenceError' exceptions are thrown inside the body of event callbacks

Open alexqfredrickson opened this issue 9 years ago • 2 comments

Expected Behavior

Given the code below, I would expect a Uncaught ReferenceError exception to be thrown on the progressFlag reference, which is undefined.

Actual Behavior

The Uncaught ReferenceError is swallowed and no error is displayed to the console. The data object is never logged to the console, so some hapless developer who mistyped some variable inside the event callback to erroneously believe that something is wrong with the iframe or player references, or something else in the code.

Steps to Reproduce

  1. Create an HTML page, reference jQuery, stick a basic embed on the page (with id="video-iframe"), and reference the following JavaScript code:

     var iframe = $('#video-iframe');
    
     if (iframe[0]) {
    
     var player = new Vimeo.Player(iframe),
         progressFlags = {
             "percentMark00": false,
             "percentMark25": false,
             "percentMark50": false,
             "percentMark75": false
         };
    
     player.on("timeupdate", function (data) {
         var videoStarted = !progressFlag.percentMark00 && data.percent >= 0.000 && data.percent < 0.250,
             video25Percent = !progressFlag.percentMark25 && data.percent >= 0.250 && data.percent < 0.500,
             video50Percent = !progressFlag.percentMark50 && data.percent >= 0.500 && data.percent < 0.750,
             video75Percent = !progressFlag.percentMark75 && data.percent >= 0.750 && data.percent < 1.000;
    
         console.log(data);
     });
    

    };

  2. Fire up Google Chrome, play the video, and look for the timeupdate event data in the console. Nothing there!

  3. Fix the typo:

         var videoStarted = !progressFlags.percentMark00 && progressData.percent >= 0.000 && progressData.percent < 0.250,
             video25Percent = !progressFlags.percentMark25 && progressData.percent >= 0.250 && progressData.percent < 0.500,
             video50Percent = !progressFlags.percentMark50 && progressData.percent >= 0.500 && progressData.percent < 0.750,
             video75Percent = !progressFlags.percentMark75 && progressData.percent >= 0.750 && progressData.percent < 1.000;
    
  4. Fire up the site again, and now data is being displayed in the console.

alexqfredrickson avatar Feb 27 '17 16:02 alexqfredrickson

Also been stung by this, also with a ReferenceError, but the problem isn't constrained to just this. It seems any errors are completely swallowed up in the event listener callbacks.

It doesn't appear that they are reported through the player.on('error') callback either. This suggests that it is not possible to actually detect if there is anything going wrong with your callback code.

This is very unexpected behaviour and is not very user friendly. I would suggest propagating these errors back up to the user, or at least having some way for us to retrieve the error in some other callback.

ntsim avatar Apr 15 '17 12:04 ntsim

Hi @alexqfredrickson, the Uncaught ReferenceError is surfaced now due to a fix in our latest release. You can see the error in this JSFiddle(https://jsfiddle.net/07td7uL4/40/). Closing this issue but feel free to reopen if the issue was not correctly fixed.

rebecca-sich avatar Feb 27 '18 13:02 rebecca-sich