diff --git a/browser.js b/browser.js index ce6369f1..aab31cac 100644 --- a/browser.js +++ b/browser.js @@ -12,6 +12,17 @@ exports.save = save; exports.load = load; exports.useColors = useColors; +/** + * Use chrome.storage.local if we are in an app + */ + +var storage; + +if (chrome.storage.local !== undefined) + storage = chrome.storage.local; +else + storage = window.localStorage; + /** * Colors. */ @@ -118,9 +129,9 @@ function log() { function save(namespaces) { try { if (null == namespaces) { - localStorage.removeItem('debug'); + storage.removeItem('debug'); } else { - localStorage.debug = namespaces; + storage.debug = namespaces; } } catch(e) {} } @@ -135,7 +146,7 @@ function save(namespaces) { function load() { var r; try { - r = localStorage.debug; + r = storage.debug; } catch(e) {} return r; }