From d05ed097423c08b6af4a9a8c4c35e81090cc0b2c Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Tue, 30 Oct 2018 14:42:33 +0000 Subject: [PATCH] Added startup bootloop crash protection Former-commit-id: 99314185e95591d593378b49b1270041f8cabbdb [formerly bdf19cb0b51ff31fedc57ded86c9071067d5bd39] Former-commit-id: 53da94c64ca856c1ecf81e154f04b30382c656b0 --- www/js/app.js | 7 +++++++ www/js/init.js | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/www/js/app.js b/www/js/app.js index c5f89e6b..73469fa3 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1724,6 +1724,10 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module' console.log("Initiating Document Ready timer..."); console.time("Time to Document Ready"); + //Set startup cookie to guard against boot loop + //Cookie will signal failure until article is fully loaded + document.cookie = 'lastPageLoad=failed;expires=Fri, 31 Dec 9999 23:59:59 GMT'; + //Void the localSearch variable to prevent invalid DOM references remainining [kiwix-js-windows #56] localSearch = {}; @@ -2313,6 +2317,9 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module' loadImages(); //loadJavascript(); //Disabled for now, since it does nothing - also, would have to load before images, ideally through controlled css loads above + + //Document has loaded except for images, so we can now change the startup cookie (and delete) [see init.js] + document.cookie = 'lastPageLoad=success;expires=Thu, 21 Sep 1979 00:00:01 UTC'; } } //End of injectHTML() diff --git a/www/js/init.js b/www/js/init.js index b2781d3a..17dd6daf 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -60,6 +60,14 @@ params['allowInternetAccess'] = params['allowInternetAccess'] || false; //Do not params['printIntercept'] = false; params['printInterception'] = false; +//Prevent app boot loop with problematic pages that cause an app crash +if (getCookie('lastPageLoad') == 'failed') { + params.lastPageVisit = ""; +} else { + //Cookie will signal failure until article is fully loaded + document.cookie = 'lastPageLoad=failed;expires=Fri, 31 Dec 9999 23:59:59 GMT'; +} + //Initialize checkbox, radio and other values document.getElementById('cssCacheModeCheck').checked = params.cssCache; document.getElementById('imageDisplayModeCheck').checked = params.imageDisplay;