Skip to content

Commit

Permalink
Merge pull request #158 from adaptlearning/issue/#1619
Browse files Browse the repository at this point in the history
Implemented detection of when storage limit exceeded
  • Loading branch information
moloko authored Jul 4, 2017
2 parents 6959d0a + 60c3240 commit 56ad962
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions required/offline_API_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ function createResetButton(API) {
});
}

function storageWarning() {
var Adapt;
var notificationMethod = alert;
this.__storageWarningTimeoutId = null;
if (require) Adapt = require('coreJS/adapt');
if (Adapt && Adapt.config && Adapt.config.has('_spoor')) {
if (Adapt.config.get('_spoor')._advancedSettings &&
Adapt.config.get('_spoor')._advancedSettings._suppressErrors === true) {
notificationMethod = console.error;
}
}
notificationMethod('Warning: possible cookie storage limit exceeded - tracking may malfunction');
}

var API = {

Expand Down Expand Up @@ -68,7 +81,18 @@ var API = {
LMSStore: function(force) {
if (window.ISCOOKIELMS === false) return;
if (!force && API.cookie("_spoor") === undefined) return;
API.cookie("_spoor", JSON.stringify(this.data));

var stringified = JSON.stringify(this.data);

API.cookie("_spoor", stringified);

// a length mismatch will most likely indicate cookie storage limit exceeded
if (API.cookie("_spoor").length != stringified.length) {
// defer call to avoid excessive alerts
if (this.__storageWarningTimeoutId == null) {
this.__storageWarningTimeoutId = setTimeout(function() {storageWarning.apply(API);}, 1000);
}
}
},
LMSFetch: function() {
if (window.ISCOOKIELMS === false) {
Expand Down Expand Up @@ -146,7 +170,18 @@ var API_1484_11 = {
LMSStore: function(force) {
if (window.ISCOOKIELMS === false) return;
if (!force && API_1484_11.cookie("_spoor") === undefined) return;
API_1484_11.cookie("_spoor", JSON.stringify(this.data));

var stringified = JSON.stringify(this.data);

API_1484_11.cookie("_spoor", stringified);

// a length mismatch will most likely indicate cookie storage limit exceeded
if (API_1484_11.cookie("_spoor").length != stringified.length) {
// defer call to avoid excessive alerts
if (this.__storageWarningTimeoutId == null) {
this.__storageWarningTimeoutId = setTimeout(function() {storageWarning.apply(API_1484_11);}, 1000);
}
}
},
LMSFetch: function() {
if (window.ISCOOKIELMS === false) {
Expand Down

0 comments on commit 56ad962

Please sign in to comment.