Skip to content

Commit

Permalink
htmlfiles: Handle localStorage not accessible
Browse files Browse the repository at this point in the history
In some cases, if based on the browser's settings - localStorage
is not accessible, fallback and don't save the sort-columns into
localStorage.
While the UX is a little inconvenient, at least the page doesn't
break - sorting on columns is still possible, but not retained
between pages.
  • Loading branch information
AbdealiLoKo committed Feb 24, 2020
1 parent 6f4c0dc commit ac71d86
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions coverage/htmlfiles/coverage_html.js
Expand Up @@ -172,7 +172,10 @@ coverage.index_ready = function ($) {
// Look for a localStorage item containing previous sort settings:
var sort_list = [];
var storage_name = "COVERAGE_INDEX_SORT";
var stored_list = localStorage.getItem(storage_name);
var stored_list = undefined;
try {
stored_list = localStorage.getItem(storage_name);
} catch(err) {}

if (stored_list) {
sort_list = JSON.parse('[[' + stored_list + ']]');
Expand Down Expand Up @@ -222,7 +225,9 @@ coverage.index_ready = function ($) {

// Watch for page unload events so we can save the final sort settings:
$(window).unload(function () {
localStorage.setItem(storage_name, sort_list.toString())
try {
localStorage.setItem(storage_name, sort_list.toString())
} catch(err) {}
});
};

Expand Down

0 comments on commit ac71d86

Please sign in to comment.