diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-05 20:35:04 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-05 20:57:52 -0400 |
commit | ec110fa1b7299a947ea3eabc0e2c46094408c8ba (patch) | |
tree | 93acc29fcb6541e24bdfe6af1f64ef54b272f669 /ext/bg | |
parent | 1c767711bb553fa828596f95f8ed9e91a3e13b5d (diff) |
Add some validation to options loading
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/js/options.js | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index d903250e..976f8e55 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -323,10 +323,23 @@ function optionsVersion(options) { function optionsLoad() { return new Promise((resolve, reject) => { - chrome.storage.local.get(null, store => resolve(store.options)); + chrome.storage.local.get(['options'], store => { + const error = chrome.runtime.lastError; + if (error) { + reject(error); + } else { + resolve(store.options); + } + }); }).then(optionsStr => { - return optionsStr ? JSON.parse(optionsStr) : {}; - }).catch(error => { + if (typeof optionsStr === 'string') { + const options = JSON.parse(optionsStr); + if (typeof options === 'object' && options !== null && !Array.isArray(options)) { + return options; + } + } + return {}; + }).catch(() => { return {}; }).then(options => { return optionsVersion(options); @@ -334,7 +347,7 @@ function optionsLoad() { } function optionsSave(options) { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { chrome.storage.local.set({options: JSON.stringify(options)}, resolve); }).then(() => { apiOptionsSet(options); |