# HG changeset patch # User Guido Berhoerster # Date 1572535368 -3600 # Node ID f77dab12bb52bb989f5bb3ac2887d24e22dd95b5 # Parent 5582a3088b9a69fc39d3885c84854acdf3360164 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. diff -r 5582a3088b9a -r f77dab12bb52 background.js --- 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}`); diff -r 5582a3088b9a -r f77dab12bb52 manifest.json.in --- a/manifest.json.in Tue Oct 23 12:58:27 2018 +0200 +++ b/manifest.json.in Thu Oct 31 16:22:48 2019 +0100 @@ -18,7 +18,8 @@ }, "permissions": [ "menus", - "search" + "search", + "cookies" ], "background": { "scripts": [ "background.js" ]