From 6126784f4089ab08a50e926606d2567e7f838565 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20Guti=C3=A9rrez?= <carlos@pressbooks.com>
Date: Thu, 27 Feb 2020 00:07:47 -0600
Subject: [PATCH] Update request-queue.js

Wrap window.localStorage checks into a try/catch block in order to prevent errors when third party cookies are disabled by the browser.
---
 js/request-queue.js | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/js/request-queue.js b/js/request-queue.js
index 5b367e1..95e6c8d 100644
--- a/js/request-queue.js
+++ b/js/request-queue.js
@@ -27,7 +27,11 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
    * @returns {boolean}
    */
   RequestQueue.prototype.add = function (url, data) {
-    if (!window.localStorage) {
+    try {
+      if (!window.localStorage) {
+        return false;
+      }
+    } catch(err) {
       return false;
     }
 
@@ -56,7 +60,11 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
    * @returns {boolean|Array} Stored requests
    */
   RequestQueue.prototype.getStoredRequests = function () {
-    if (!window.localStorage) {
+    try {
+      if (!window.localStorage) {
+        return false;
+      }
+    } catch(err) {
       return false;
     }
 
@@ -74,7 +82,11 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
    * @returns {boolean} True if the storage was successfully cleared
    */
   RequestQueue.prototype.clearQueue = function () {
-    if (!window.localStorage) {
+    try {
+      if (!window.localStorage) {
+        return false;
+      }
+    } catch(err) {
       return false;
     }
 
@@ -89,7 +101,11 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
    */
   RequestQueue.prototype.resumeQueue = function () {
     // Not supported
-    if (!H5PIntegration || !window.navigator || !window.localStorage) {
+    try {
+      if (!H5PIntegration || !window.navigator || !window.localStorage) {
+        return false;
+      }
+    } catch(err) {
       return false;
     }