From b94b88e6898492e2b1b6632bfb941a560f586f73 Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Sun, 26 Nov 2017 23:22:20 +0100 Subject: [PATCH] Fix share current tab function to handle given tab in parameter --- src/background.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/background.js b/src/background.js index 3227082..9c61344 100644 --- a/src/background.js +++ b/src/background.js @@ -17,21 +17,16 @@ function openInPopup(url) { * Share Current Tab * @return {void} - */ -function shareCurrentTab() { - browser.tabs.query({ - active: true, - currentWindow: true, - }).then((tabs) => { - const url = tabs[0].url; - const title = tabs[0].title || url; - browser.storage.local.get('url').then((storage) => { - if(storage.url){ - const shareUrl = `${storage.url}?post=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&source=bookmarklet`; - openInPopup(shareUrl); - }else{ - browser.runtime.openOptionsPage() - } - }); +function shareCurrentTab(tab) { + const url = tab.url; + const title = tab.title || url; + browser.storage.local.get('url').then((storage) => { + if(!storage.url){ + browser.runtime.openOptionsPage(); + return; + } + const shareUrl = `${storage.url}?post=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&source=bookmarklet`; + openInPopup(shareUrl); }); }