Use fetch with keepalive: true instead of navigator.sendBeacon
This allows customizing the headers of the request. It has the same semantics as `navigator.sendBeacon` and it's the recommended alternative to `sendBeacon` for customizing the request: https://www.w3.org/TR/beacon/#introduction This commit also fixes `settings.requestHandler` not being called when using `settings.sendBeaconCommit`.
This commit is contained in:
31
dist/aicc.js
vendored
31
dist/aicc.js
vendored
@@ -1795,26 +1795,19 @@ var BaseAPI = /*#__PURE__*/function () {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
var headers = {
|
params = settings.requestHandler(params);
|
||||||
type: settings.commitRequestDataType
|
fetch(url, {
|
||||||
};
|
method: 'POST',
|
||||||
var blob;
|
body: params instanceof Array ? params.join('&') : JSON.stringify(params),
|
||||||
|
headers: _objectSpread(_objectSpread({}, settings.xhrHeaders), {}, {
|
||||||
if (params instanceof Array) {
|
'Content-Type': settings.commitRequestDataType
|
||||||
blob = new Blob([params.join('&')], headers);
|
}),
|
||||||
} else {
|
credentials: settings.xhrWithCredentials ? 'include' : undefined,
|
||||||
blob = new Blob([JSON.stringify(params)], headers);
|
keepalive: true
|
||||||
}
|
});
|
||||||
|
|
||||||
result = {};
|
result = {};
|
||||||
|
result.result = global_constants.SCORM_TRUE;
|
||||||
if (navigator.sendBeacon(url, blob)) {
|
result.errorCode = 0;
|
||||||
result.result = global_constants.SCORM_TRUE;
|
|
||||||
result.errorCode = 0;
|
|
||||||
} else {
|
|
||||||
result.result = global_constants.SCORM_FALSE;
|
|
||||||
result.errorCode = 101;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
api.processListeners('CommitError');
|
api.processListeners('CommitError');
|
||||||
|
|||||||
2
dist/aicc.js.map
vendored
2
dist/aicc.js.map
vendored
File diff suppressed because one or more lines are too long
8
dist/aicc.min.js
vendored
8
dist/aicc.min.js
vendored
File diff suppressed because one or more lines are too long
31
dist/scorm-again.js
vendored
31
dist/scorm-again.js
vendored
@@ -1795,26 +1795,19 @@ var BaseAPI = /*#__PURE__*/function () {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
var headers = {
|
params = settings.requestHandler(params);
|
||||||
type: settings.commitRequestDataType
|
fetch(url, {
|
||||||
};
|
method: 'POST',
|
||||||
var blob;
|
body: params instanceof Array ? params.join('&') : JSON.stringify(params),
|
||||||
|
headers: _objectSpread(_objectSpread({}, settings.xhrHeaders), {}, {
|
||||||
if (params instanceof Array) {
|
'Content-Type': settings.commitRequestDataType
|
||||||
blob = new Blob([params.join('&')], headers);
|
}),
|
||||||
} else {
|
credentials: settings.xhrWithCredentials ? 'include' : undefined,
|
||||||
blob = new Blob([JSON.stringify(params)], headers);
|
keepalive: true
|
||||||
}
|
});
|
||||||
|
|
||||||
result = {};
|
result = {};
|
||||||
|
result.result = global_constants.SCORM_TRUE;
|
||||||
if (navigator.sendBeacon(url, blob)) {
|
result.errorCode = 0;
|
||||||
result.result = global_constants.SCORM_TRUE;
|
|
||||||
result.errorCode = 0;
|
|
||||||
} else {
|
|
||||||
result.result = global_constants.SCORM_FALSE;
|
|
||||||
result.errorCode = 101;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
api.processListeners('CommitError');
|
api.processListeners('CommitError');
|
||||||
|
|||||||
2
dist/scorm-again.js.map
vendored
2
dist/scorm-again.js.map
vendored
File diff suppressed because one or more lines are too long
8
dist/scorm-again.min.js
vendored
8
dist/scorm-again.min.js
vendored
File diff suppressed because one or more lines are too long
31
dist/scorm12.js
vendored
31
dist/scorm12.js
vendored
@@ -1670,26 +1670,19 @@ var BaseAPI = /*#__PURE__*/function () {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
var headers = {
|
params = settings.requestHandler(params);
|
||||||
type: settings.commitRequestDataType
|
fetch(url, {
|
||||||
};
|
method: 'POST',
|
||||||
var blob;
|
body: params instanceof Array ? params.join('&') : JSON.stringify(params),
|
||||||
|
headers: _objectSpread(_objectSpread({}, settings.xhrHeaders), {}, {
|
||||||
if (params instanceof Array) {
|
'Content-Type': settings.commitRequestDataType
|
||||||
blob = new Blob([params.join('&')], headers);
|
}),
|
||||||
} else {
|
credentials: settings.xhrWithCredentials ? 'include' : undefined,
|
||||||
blob = new Blob([JSON.stringify(params)], headers);
|
keepalive: true
|
||||||
}
|
});
|
||||||
|
|
||||||
result = {};
|
result = {};
|
||||||
|
result.result = global_constants.SCORM_TRUE;
|
||||||
if (navigator.sendBeacon(url, blob)) {
|
result.errorCode = 0;
|
||||||
result.result = global_constants.SCORM_TRUE;
|
|
||||||
result.errorCode = 0;
|
|
||||||
} else {
|
|
||||||
result.result = global_constants.SCORM_FALSE;
|
|
||||||
result.errorCode = 101;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
api.processListeners('CommitError');
|
api.processListeners('CommitError');
|
||||||
|
|||||||
2
dist/scorm12.js.map
vendored
2
dist/scorm12.js.map
vendored
File diff suppressed because one or more lines are too long
6
dist/scorm12.min.js
vendored
6
dist/scorm12.min.js
vendored
File diff suppressed because one or more lines are too long
31
dist/scorm2004.js
vendored
31
dist/scorm2004.js
vendored
@@ -1670,26 +1670,19 @@ var BaseAPI = /*#__PURE__*/function () {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
var headers = {
|
params = settings.requestHandler(params);
|
||||||
type: settings.commitRequestDataType
|
fetch(url, {
|
||||||
};
|
method: 'POST',
|
||||||
var blob;
|
body: params instanceof Array ? params.join('&') : JSON.stringify(params),
|
||||||
|
headers: _objectSpread(_objectSpread({}, settings.xhrHeaders), {}, {
|
||||||
if (params instanceof Array) {
|
'Content-Type': settings.commitRequestDataType
|
||||||
blob = new Blob([params.join('&')], headers);
|
}),
|
||||||
} else {
|
credentials: settings.xhrWithCredentials ? 'include' : undefined,
|
||||||
blob = new Blob([JSON.stringify(params)], headers);
|
keepalive: true
|
||||||
}
|
});
|
||||||
|
|
||||||
result = {};
|
result = {};
|
||||||
|
result.result = global_constants.SCORM_TRUE;
|
||||||
if (navigator.sendBeacon(url, blob)) {
|
result.errorCode = 0;
|
||||||
result.result = global_constants.SCORM_TRUE;
|
|
||||||
result.errorCode = 0;
|
|
||||||
} else {
|
|
||||||
result.result = global_constants.SCORM_FALSE;
|
|
||||||
result.errorCode = 101;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
api.processListeners('CommitError');
|
api.processListeners('CommitError');
|
||||||
|
|||||||
2
dist/scorm2004.js.map
vendored
2
dist/scorm2004.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/scorm2004.min.js
vendored
2
dist/scorm2004.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1150,24 +1150,20 @@ export default class BaseAPI {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const headers = {
|
params = settings.requestHandler(params);
|
||||||
type: settings.commitRequestDataType,
|
fetch(url, {
|
||||||
};
|
method: 'POST',
|
||||||
let blob;
|
body: params instanceof Array ? params.join('&') : JSON.stringify(params),
|
||||||
if (params instanceof Array) {
|
headers: {
|
||||||
blob = new Blob([params.join('&')], headers);
|
...settings.xhrHeaders,
|
||||||
} else {
|
'Content-Type': settings.commitRequestDataType,
|
||||||
blob = new Blob([JSON.stringify(params)], headers);
|
},
|
||||||
}
|
credentials: settings.xhrWithCredentials ? 'include' : undefined,
|
||||||
|
keepalive: true,
|
||||||
|
});
|
||||||
result = {};
|
result = {};
|
||||||
if (navigator.sendBeacon(url, blob)) {
|
result.result = global_constants.SCORM_TRUE;
|
||||||
result.result = global_constants.SCORM_TRUE;
|
result.errorCode = 0;
|
||||||
result.errorCode = 0;
|
|
||||||
} else {
|
|
||||||
result.result = global_constants.SCORM_FALSE;
|
|
||||||
result.errorCode = 101;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
api.processListeners('CommitError');
|
api.processListeners('CommitError');
|
||||||
|
|||||||
Reference in New Issue
Block a user