diff --git a/js/request-queue.js b/js/request-queue.js index 5b367e1..5cb70eb 100644 --- a/js/request-queue.js +++ b/js/request-queue.js @@ -19,6 +19,19 @@ H5P.RequestQueue = (function ($, EventDispatcher) { this.itemName = 'requestQueue'; }; + /** + * Check whether localStorage is accessible. + * @return {boolean} True, if window.localStorage is accessible, else false. + */ + RequestQueue.prototype.isLocalStorageAccessible = function () { + try { + return (window.localStorage) ? true : false; + } + catch (event) { + return false; + } + }; + /** * Add request to queue. Only supports posts currently. * @@ -27,7 +40,7 @@ H5P.RequestQueue = (function ($, EventDispatcher) { * @returns {boolean} */ RequestQueue.prototype.add = function (url, data) { - if (!window.localStorage) { + if (!this.isLocalStorageAccessible()) { return false; } @@ -56,7 +69,7 @@ H5P.RequestQueue = (function ($, EventDispatcher) { * @returns {boolean|Array} Stored requests */ RequestQueue.prototype.getStoredRequests = function () { - if (!window.localStorage) { + if (!this.isLocalStorageAccessible()) { return false; } @@ -74,7 +87,7 @@ H5P.RequestQueue = (function ($, EventDispatcher) { * @returns {boolean} True if the storage was successfully cleared */ RequestQueue.prototype.clearQueue = function () { - if (!window.localStorage) { + if (!this.isLocalStorageAccessible()) { return false; } @@ -89,7 +102,7 @@ H5P.RequestQueue = (function ($, EventDispatcher) { */ RequestQueue.prototype.resumeQueue = function () { // Not supported - if (!H5PIntegration || !window.navigator || !window.localStorage) { + if (!H5PIntegration || !window.navigator || !this.isLocalStorageAccessible()) { return false; }