Skip to content

Commit 48c73b8

Browse files
AbdealiLoKonedbat
authored andcommitted
htmlfiles: Handle localStorage not accessible
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.
1 parent 0f82d27 commit 48c73b8

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGES.rst

+6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ Unreleased
3030

3131
- Windows 3.8 wheels were incorrectly built, but are now fixed. (`issue 949`_)
3232

33+
- HTML report couldn't be sorted if localStorage wasn't available. This is now
34+
fixed: sorting works even though the sorting setting isn't retained. (`issue
35+
944`_ and `pull request 945`_). Thanks, Abdeali Kothari.
36+
3337
.. _issue 943: https://github.com/nedbat/coveragepy/issues/943
38+
.. _issue 944: https://github.com/nedbat/coveragepy/issues/944
39+
.. _pull request 945: https://github.com/nedbat/coveragepy/pull/945
3440
.. _issue 949: https://github.com/nedbat/coveragepy/issues/949
3541

3642

CONTRIBUTORS.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extended and maintained by Ned Batchelder.
44
Other contributions, including writing code, updating docs, and submitting
55
useful bug reports, have been made by:
66

7+
Abdeali Kothari
78
Adi Roiban
89
Agbonze O. Jeremiah
910
Albertas Agejevas

coverage/htmlfiles/coverage_html.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ coverage.index_ready = function ($) {
172172
// Look for a localStorage item containing previous sort settings:
173173
var sort_list = [];
174174
var storage_name = "COVERAGE_INDEX_SORT";
175-
var stored_list = localStorage.getItem(storage_name);
175+
var stored_list = undefined;
176+
try {
177+
stored_list = localStorage.getItem(storage_name);
178+
} catch(err) {}
176179

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

223226
// Watch for page unload events so we can save the final sort settings:
224227
$(window).unload(function () {
225-
localStorage.setItem(storage_name, sort_list.toString())
228+
try {
229+
localStorage.setItem(storage_name, sort_list.toString())
230+
} catch(err) {}
226231
});
227232
};
228233

0 commit comments

Comments
 (0)