From e9c730a6e26da297f350c6c7a03f3d5564e28d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zeus=20G=C3=B3mez=20Marmolejo?= Date: Tue, 30 Sep 2014 18:34:48 +0200 Subject: [PATCH 1/3] add support for chrome apps --- browser.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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; } From de8695b6be3dcc665aff3de5e32f49b5f158fd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zeus=20G=C3=B3mez=20Marmolejo?= Date: Wed, 8 Oct 2014 17:27:33 +0200 Subject: [PATCH 2/3] corrected PR for other browsers Sorry, this should work now. window.localStorage is undefined in chrome apps. --- browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser.js b/browser.js index aab31cac..c663ed8d 100644 --- a/browser.js +++ b/browser.js @@ -18,7 +18,7 @@ exports.useColors = useColors; var storage; -if (chrome.storage.local !== undefined) +if (chrome && chrome.storage) storage = chrome.storage.local; else storage = window.localStorage; From 3f97ec6f00fc8844d6ed2a567259e23bd3ebd11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zeus=20G=C3=B3mez=20Marmolejo?= Date: Fri, 17 Oct 2014 12:08:54 +0200 Subject: [PATCH 3/3] better checking for undefined value --- browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser.js b/browser.js index c663ed8d..81df4d03 100644 --- a/browser.js +++ b/browser.js @@ -18,7 +18,7 @@ exports.useColors = useColors; var storage; -if (chrome && chrome.storage) +if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined') storage = chrome.storage.local; else storage = window.localStorage;