From 0e62d914c13bc8b64d235fed999987d8ea50ba5d Mon Sep 17 00:00:00 2001 From: jebbs Date: Fri, 10 Jan 2020 16:34:46 +0800 Subject: [PATCH] runtime error do not interrupt promise chains --- scripts/background/messaging.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/background/messaging.js b/scripts/background/messaging.js index 9d2f34b..78a04e3 100644 --- a/scripts/background/messaging.js +++ b/scripts/background/messaging.js @@ -23,10 +23,11 @@ function sendMessage(tab, req, log, cond, interval) { } chrome.tabs.sendMessage(tab.id, req, r => { - if (chrome.runtime.lastError) { - reject(chrome.runtime.lastError.message); - return; - } + // check error but do nothing. + // do not interrupt promise chains even if error, or the task always fail when: + // a tab is newly created, and the content scripts won't have time to initialize + chrome.runtime.lastError; + let flag = !cond || cond(r); if (log) console.log(log, flag ? '(OK)' : '(failed)'); if (flag) {