runtime error do not interrupt promise chains

This commit is contained in:
2020-01-10 16:34:46 +08:00
parent c504942144
commit 0e62d914c1

View File

@ -23,10 +23,11 @@ function sendMessage(tab, req, log, cond, interval) {
} }
chrome.tabs.sendMessage(tab.id, req, r => { chrome.tabs.sendMessage(tab.id, req, r => {
if (chrome.runtime.lastError) { // check error but do nothing.
reject(chrome.runtime.lastError.message); // do not interrupt promise chains even if error, or the task always fail when:
return; // a tab is newly created, and the content scripts won't have time to initialize
} chrome.runtime.lastError;
let flag = !cond || cond(r); let flag = !cond || cond(r);
if (log) console.log(log, flag ? '(OK)' : '(failed)'); if (log) console.log(log, flag ? '(OK)' : '(failed)');
if (flag) { if (flag) {