From 59d32e6f2fb638d66e29e7832055d5fffce8cd74 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 24 Nov 2017 18:39:15 +0300 Subject: [PATCH] inline and simplify closeTab() --- background/background.js | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/background/background.js b/background/background.js index 7bff2213..9a55da33 100644 --- a/background/background.js +++ b/background/background.js @@ -347,7 +347,11 @@ function onRuntimeMessage(request, sender, sendResponseInternal) { return KEEP_CHANNEL_OPEN; case 'closeTab': - closeTab(sender.tab.id, request).then(sendResponse); + chrome.tabs.remove(request.tabId || sender.tab.id, () => { + if (chrome.runtime.lastError) { + sendResponse(new Error(chrome.runtime.lastError.message)); + } + }); return KEEP_CHANNEL_OPEN; case 'openEditor': @@ -355,23 +359,3 @@ function onRuntimeMessage(request, sender, sendResponseInternal) { return; } } - - -function closeTab(tabId, request) { - return new Promise(resolve => { - if (request.tabId) { - tabId = request.tabId; - } - chrome.tabs.remove(tabId, () => { - const {lastError} = chrome.runtime; - if (lastError) { - resolve({ - success: false, - error: lastError.message || String(lastError) - }); - return; - } - resolve({success: true}); - }); - }); -}