Mercurial > addons > firefox-addons > context-web-search
changeset 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 | 5582a3088b9a |
children | 72e2ab36f4fc |
files | background.js manifest.json.in |
diffstat | 2 files changed, 16 insertions(+), 2 deletions(-) [+] |
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}`);