Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

htmlfiles: Handle localStorage not accessible #945

Merged
merged 1 commit into from Feb 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note - didn't look like there was any better way of testing this as merely accessing the variable caused the error. So, try/catch seemed to be the only option

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