From aac049d559e508af91d13ff7d25610a5464c12a5 Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Mon, 25 Dec 2017 19:37:59 -0800 Subject: [PATCH] Trim the log if new logs cannot be written to storage. Fix #1288. --- .../src/coffee/background.coffee | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/omega-target-chromium-extension/src/coffee/background.coffee b/omega-target-chromium-extension/src/coffee/background.coffee index 2e489c7..ab94fe4 100644 --- a/omega-target-chromium-extension/src/coffee/background.coffee +++ b/omega-target-chromium-extension/src/coffee/background.coffee @@ -4,14 +4,23 @@ Promise.longStackTraces() OmegaTargetCurrent.Log = Object.create(OmegaTargetCurrent.Log) Log = OmegaTargetCurrent.Log + +_writeLogToLocalStorage = (content) -> + try + localStorage['log'] += content + catch + # Maybe we have reached our limit here. See #1288. Try trimming it. + localStorage['log'] = content + Log.log = (args...) -> console.log(args...) - localStorage['log'] += args.map(Log.str.bind(Log)).join(' ') + '\n' + content = args.map(Log.str.bind(Log)).join(' ') + '\n' + _writeLogToLocalStorage(content) Log.error = (args...) -> console.error(args...) content = args.map(Log.str.bind(Log)).join(' ') localStorage['logLastError'] = content - localStorage['log'] += 'ERROR: ' + content + '\n' + _writeLogToLocalStorage('ERROR: ' + content + '\n') unhandledPromises = [] unhandledPromisesId = []