xAPIWrapper icon indicating copy to clipboard operation
xAPIWrapper copied to clipboard

Statements no longer sent when browser (Chrome) closed

Open danielghost opened this issue 5 years ago • 2 comments

Now that Chrome has finally deprecated synchronous XHR in Chrome 80, any statements triggered when the browser closes will be lost, as asynchronous calls will not be resolved in time. This is important if using terminated type statements, and is actually a requirement if following the cmi5 profile.

Not sure whether other browsers will follow, but should the wrapper look to use the Beacon API (with a Polyfill for IE11) to handle the communication?

danielghost avatar Apr 06 '20 18:04 danielghost

Doesn't look like the Beacon API can be used as you cannot customise the headers as required for xAPI. You can instead use the Fetch API with the keepalive flag. Where the Fetch API is not supported, e.g. IE11, the current XHR requests can still be used and sent synchronously for any statements sent when the browser is closed.

danielghost avatar May 12 '20 15:05 danielghost

It is possible to use the Beacon API here, by relying on the old IE fallback mechanism in the LRS ("Alternate Request Syntax"), which allows headers to be passed in the body of the request and the method to be passed in the query string, see https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#alt-request-syntax

-EDIT- It looks like the Chrome folks finally half-fixed fetch's keepalive (https://bugs.chromium.org/p/chromium/issues/detail?id=810466), so that might work for some scenarios, but apparently not in real CORS scenarios requiring preflight, so Beacon it is.

ysrn avatar Oct 11 '21 15:10 ysrn