From 2730d5954bf68d8a840f778d2f6923c4e2890058 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 20 Nov 2014 01:36:06 -0200 Subject: [PATCH] fix spurious warning in console --- meta/crx/vapi-background.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/meta/crx/vapi-background.js b/meta/crx/vapi-background.js index ab27ce1..68aa7f0 100644 --- a/meta/crx/vapi-background.js +++ b/meta/crx/vapi-background.js @@ -180,14 +180,19 @@ vAPI.tabs.remove = function(tabId) { /******************************************************************************/ vAPI.tabs.injectScript = function(tabId, details, callback) { - if ( typeof callback !== 'function' ) { - callback = function(){}; - } - + var onScriptExecuted = function() { + // Must check `lastError` or else this may happen in the console: + // Unchecked runtime.lastError while running tabs.executeScript: The tab was closed. + if ( chrome.runtime.lastError ) { + } + if ( typeof callback === 'function' ) { + callback(); + } + }; if ( tabId ) { - chrome.tabs.executeScript(tabId, details, callback); + chrome.tabs.executeScript(tabId, details, onScriptExecuteds); } else { - chrome.tabs.executeScript(details, callback); + chrome.tabs.executeScript(details, onScriptExecuted); } };