From 27303b57715753fc0651d92ea9f75082306491e1 Mon Sep 17 00:00:00 2001 From: Blake Winton Date: Tue, 15 Sep 2015 13:39:06 -0700 Subject: [PATCH] See if the tab exists before creating a new one. --- background.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/background.js b/background.js index 2ffdb4b..5e66bfd 100644 --- a/background.js +++ b/background.js @@ -6,6 +6,12 @@ chrome.browserAction.setBadgeText({text: '(ツ)'}); chrome.browserAction.setBadgeBackgroundColor({color: '#eae'}); chrome.browserAction.onClicked.addListener(function(aTab) { - chrome.tabs.create({'url': 'http://chilloutandwatchsomecatgifs.com/', 'active': true}); + chrome.tabs.query({'url': 'http://chilloutandwatchsomecatgifs.com/'}, (tabs) => { + if (tabs.length === 0) { + // There is no catgif tab! + chrome.tabs.create({'url': 'http://chilloutandwatchsomecatgifs.com/', 'active': true}); + } else { + // Do something here… + } + }); }); -