adaptlearning / adapt-contrib-xapi

TinCan/xAPI extension for the Adapt Framework
GNU General Public License v3.0
12 stars 28 forks source link

Plugin fails before sending last "actor terminated course" statement #105

Closed lars-moch closed 2 years ago

lars-moch commented 2 years ago

I implemented the bugfix from issue #103 but instead got an error in this line.

It looked like the same issue as in issue #103, plus a problem with the "result" parameter, which is optional and could be undefined. I tried with this code:

if (result && (Object.keys(result).length > 0)) {

And it seemed to work.

But when I close the course, I get this error in the browser console:

react_devtools_backend.js:4061 ERROR: adapt-contrib-xapi: DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://cloud.scorm.com/lrs/45MN2ZJO0D/sandbox/statements': Synchronous XHR in page dismissal. See https://www.chromestatus.com/feature/4664843055398912 for more details.
    at Object._.XHR_request (https://cloud.scorm.com/sandbox/content/courses/45MN2ZJO0D/xapi-test-course_20220302_1000044cfd8223-cc08-4e37-a49c-358a07d86fb2/0/libraries/xapiwrapper.min.js:3:33505)
    at t.sendStatement (https://cloud.scorm.com/sandbox/content/courses/45MN2ZJO0D/xapi-test-course_20220302_1000044cfd8223-cc08-4e37-a49c-358a07d86fb2/0/libraries/xapiwrapper.min.js:3:21672)
    at XAPI._callee17$ (https://cloud.scorm.com/sandbox/content/courses/45MN2ZJO0D/xapi-test-course_20220302_1000044cfd8223-cc08-4e37-a49c-358a07d86fb2/0/adapt/js/adapt.min.js:11022:43)
    at s (https://cloud.scorm.com/sandbox/content/courses/45MN2ZJO0D/xapi-test-course_20220302_1000044cfd8223-cc08-4e37-a49c-358a07d86fb2/0/libraries/bowser.js:2:105708)
    at Generator._invoke (https://cloud.scorm.com/sandbox/content/courses/45MN2ZJO0D/xapi-test-course_20220302_1000044cfd8223-cc08-4e37-a49c-358a07d86fb2/0/libraries/bowser.js:2:105496)
    at Generator.forEach.t.<computed> [as next] (https://cloud.scorm.com/sandbox/content/courses/45MN2ZJO0D/xapi-test-course_20220302_1000044cfd8223-cc08-4e37-a49c-358a07d86fb2/0/libraries/bowser.js:2:106131)
    at asyncGeneratorStep (https://cloud.scorm.com/sandbox/content/courses/45MN2ZJO0D/xapi-test-course_20220302_1000044cfd8223-cc08-4e37-a49c-358a07d86fb2/0/adapt/js/adapt.min.js:50:26)
    at _next (https://cloud.scorm.com/sandbox/content/courses/45MN2ZJO0D/xapi-test-course_20220302_1000044cfd8223-cc08-4e37-a49c-358a07d86fb2/0/adapt/js/adapt.min.js:72:11)
    at https://cloud.scorm.com/sandbox/content/courses/45MN2ZJO0D/xapi-test-course_20220302_1000044cfd8223-cc08-4e37-a49c-358a07d86fb2/0/adapt/js/adapt.min.js:79:9
    at new Promise (<anonymous>)

When I look at the Statements in the LRS, there is no "actor terminated course" statement (I get that if I test with version 0.8.3 of the xApi plugin).

I am using framework 5.18.5, and the course is authored in AT 0.10.5.

The course is very minimal. The content is only the default content when you create a new course (one page with one block with a text component). The only installed extension is the adapt-contrib-xapi with the above-mentioned updates and it uses all default settings (except for the Activity ID and Endpoint).

I have tested in SCORM Cloud sandboxed LRS.

cahirodoherty-learningpool commented 2 years ago

From an initial investigation, this looks like a bug in the isCors policy.

For a url https://cloud.scorm.com/lrs/ABC123/ I get back isCORS true because of the condition

location.hostname.toLowerCase() !== urlparts[2]

as this equates to 'cloud.scorm.com' !== 'cloud.scorm.com/lrs/abc123/'

The regex for urlparts is at fault