Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-68896

SCORM error in Chrome because of "XHR in page dismissal" policy change

    XMLWordPrintable

    Details

    • Affected Branches:
      MOODLE_38_STABLE

      Description

      After recent update of Chrome, tracking of course pages in SCORM is not been saved.

      I added a comment on MDL-67175 , because the solution made there is not working properly with last chromiun browsers, but as it's closed, I've created a new one.

      I think it could be solved editing mod/scorm/request.js, moving the new added block inside the catch, and removing the if clause, because the initializacion of the global var "window.mod_scorm_is_window_closing" is not working.

      And I've tested that if I remove the IF and let the block as is before the try/catch, other features stop working. So it should be in the catch and act only if the sync xhr fails.

      I also add some code to exclude not chromiun browsers, just in case.

          try {
              httpReq.send(param);
          } catch (e) {
       
              var pieces = navigator.userAgent.match(/Chrom(?:e|ium)\/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/);
              if (pieces != null && pieces.length == 5) {
                      pieces = pieces.map(piece => parseInt(piece, 10));
                      ChromeVersion = pieces[1];
                      if (ChromeVersion > 80 && FormData) {
       
                              var vars = param.split('&'),
                              i = 0,
                              pair,
                              key,
                              value,
                              formData = new FormData();
       
                              for (i = 0; i < vars.length; i++) {
                                  pair = vars[i].split('=');
                                  key = decodeURIComponent(pair[0]);
                                  value = decodeURIComponent(pair[1]);
                                  formData.append(key, value);
                              }
                              // We'll also inform it that we are unloading, potentially useful in the future.
                              formData.append('unloading', '1');
       
                              // The results is true or false, we don't get the response from the server. Make it look like it was a success.
                              navigator.sendBeacon(url, formData);
                              // This is what a success looks like when it comes back from the server.
                              return "true\n0";
                      }
              }
              return false;
      }
       

       

        Attachments

        1. module.js
          39 kB
        2. request.js
          5 kB
        3. test.zip
          7.43 MB

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              virgiliorey Virgilio Rey Lorenzana
              Participants:
              Component watchers:
              Damyon Wiese, Dan Marsden, Matteo Scaramuccia, Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
              Votes:
              5 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated: