diff --git a/resources/mmv/mmv.Config.js b/resources/mmv/mmv.Config.js index 3a87b1670..de5dbc721 100644 --- a/resources/mmv/mmv.Config.js +++ b/resources/mmv/mmv.Config.js @@ -65,7 +65,11 @@ CP.getFromLocalStorage = function ( key, fallback ) { var value = null; if ( this.localStorage ) { - value = this.localStorage.getItem( key ); + try { + value = this.localStorage.getItem( key ); + } catch ( e ) { + mw.log( 'Failed to fetch item ' + key + ' from localStorage', e ); + } } if ( value === null && fallback !== undefined ) { value = fallback; diff --git a/resources/mmv/mmv.head.js b/resources/mmv/mmv.head.js index 394f64757..5a304715e 100644 --- a/resources/mmv/mmv.head.js +++ b/resources/mmv/mmv.head.js @@ -25,11 +25,15 @@ // If the user disabled MediaViewer in his preferences, we do not set up click handling. // This is loaded before user JS so we cannot check wgMediaViewer. - if ( - mw.config.get( 'wgMediaViewerOnClick' ) !== true - || mw.user.isAnon() && window.localStorage && localStorage.getItem( 'wgMediaViewerOnClick' ) === false - ) { - return; + try { + if ( + mw.config.get( 'wgMediaViewerOnClick' ) !== true + || mw.user.isAnon() && window.localStorage && localStorage.getItem( 'wgMediaViewerOnClick' ) === false + ) { + return; + } + } catch ( e ) { // localStorage.getItem can throw exceptions + mw.log( 'Could not check value of wgMediaViewerOnClick in localStorage' ); } $document.on( 'click.mmv-head', 'a.image', function ( e ) { diff --git a/resources/mmv/ui/mmv.ui.metadataPanelScroller.js b/resources/mmv/ui/mmv.ui.metadataPanelScroller.js index 6a07865c4..481115c54 100644 --- a/resources/mmv/ui/mmv.ui.metadataPanelScroller.js +++ b/resources/mmv/ui/mmv.ui.metadataPanelScroller.js @@ -138,7 +138,11 @@ MPSP.initialize = function () { - this.hasOpenedMetadata = !this.localStorage || this.localStorage.getItem( 'mmv.hasOpenedMetadata' ); + try { + this.hasOpenedMetadata = !this.localStorage || this.localStorage.getItem( 'mmv.hasOpenedMetadata' ); + } catch ( e ) { // localStorage.getItem can throw exceptions + this.hasOpenedMetadata = true; + } }; /**