Mercurial > addons > firefox-addons > context-web-search
diff background.js @ 3:f77dab12bb52
Add support for contextual identities
Create new tab with the same contextual identity as the current tab and open
the search results in newly created tab. Accessing the tab's cookieStoreId
property requires the "cookies" permission.
author | Guido Berhoerster <guido+cws@berhoerster.name> |
---|---|
date | Thu, 31 Oct 2019 16:22:48 +0100 |
parents | 2050741e9711 |
children | d5f5d016facd |
line wrap: on
line diff
--- a/background.js Tue Oct 23 12:58:27 2018 +0200 +++ b/background.js Thu Oct 31 16:22:48 2019 +0100 @@ -103,10 +103,23 @@ browser.menus.onClicked.addListener(async (info, tab) => { let query = typeof info.selectionText !== 'undefined' ? info.selectionText.trim() : info.linkText.trim(); + // create a new tab with the same contextual identity as the current tab + let newTab; + try { + newTab = await browser.tabs.create({ + active: true, + cookieStoreId: tab.cookieStoreId, + openerTabId: tab.id + }); + } catch (e) { + console.log(`Failed to create new tab: ${e.message}`); + return; + } try { await browser.search.search({ query: query, - engine: info.menuItemId + engine: info.menuItemId, + tabId: newTab.id }); } catch (e) { console.log(`Failed to search for "${query}": ${e.message}`);