diff --git a/src/config.ts b/src/config.ts index 6a00e08f..7838104a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -254,6 +254,10 @@ const DEFAULTS = o({ "curl -fsSl https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/install.sh | bash", profiledir: "auto", + // Container settings + // If enabled, tabopen opens a new tab in the currently active tab's container. + tabopencontaineraware: "false", + // Performance related settings // number of most recent results to ask Firefox for. We display the top 20 or so most frequently visited ones. diff --git a/src/excmds.ts b/src/excmds.ts index 17f3c0bb..8f5463d6 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -87,7 +87,7 @@ // Shared import * as Messaging from "./messaging" -import { l, browserBg, activeTabId } from "./lib/webext" +import { l, browserBg, activeTabId, activeTabContainerId } from "./lib/webext" import state from "./state" import * as UrlUtil from "./url_util" import * as config from "./config" @@ -1244,7 +1244,10 @@ export async function tabopen(...addressarr: string[]) { } else if (address != "") url = forceURI(address) else url = forceURI(config.get("newtab")) - openInNewTab(url, { active }) + activeTabContainerId().then(containerId => { + if (containerId && config.get("tabopencontaineraware") === "true") openInNewTab(url, { active: active, cookieStoreId: containerId }) + else openInNewTab(url, { active }) + }) } /** Resolve a tab index to the tab id of the corresponding tab in this window. diff --git a/src/hinting.ts b/src/hinting.ts index 7a8b53f6..1f62a192 100644 --- a/src/hinting.ts +++ b/src/hinting.ts @@ -537,7 +537,7 @@ const HINTTAGS_saveable = ` [href]:not([href='#']) ` -import { openInNewTab } from "./lib/webext" +import { openInNewTab, activeTabContainerId } from "./lib/webext" /** if `target === _blank` clicking the link is treated as opening a popup and is blocked. Use webext API to avoid that. */ function simulateClick(target: HTMLElement) { @@ -550,7 +550,18 @@ function simulateClick(target: HTMLElement) { (target as HTMLAnchorElement).target === "_blank" || (target as HTMLAnchorElement).target === "_new" ) { - openInNewTab((target as HTMLAnchorElement).href, { related: true }) + // Try to open the new tab in the same container as the current one. + activeTabContainerId().then(containerId => { + if (containerId) + openInNewTab((target as HTMLAnchorElement).href, { + related: true, + cookieStoreId: containerId, + }) + else + openInNewTab((target as HTMLAnchorElement).href, { + related: true, + }) + }) } else { DOM.mouseEvent(target, "click") // DOM.focus has additional logic for focusing inputs @@ -563,10 +574,21 @@ function hintPageOpenInBackground(selectors = HINTTAGS_selectors) { hint.target.focus() if (hint.target.href) { // Try to open with the webext API. If that fails, simulate a click on this page anyway. - openInNewTab(hint.target.href, { - active: false, - related: true, - }).catch(() => simulateClick(hint.target)) + // Try to open the new tab in the same container as the current one. + activeTabContainerId().then(containerId => { + if (containerId) { + openInNewTab(hint.target.href, { + active: false, + related: true, + cookieStoreId: containerId, + }).catch(() => simulateClick(hint.target)) + } else { + openInNewTab(hint.target.href, { + active: false, + related: true, + }).catch(() => simulateClick(hint.target)) + } + }) } else { // This is to mirror vimperator behaviour. simulateClick(hint.target) diff --git a/src/lib/webext.ts b/src/lib/webext.ts index 25d414bf..c28ce2ad 100644 --- a/src/lib/webext.ts +++ b/src/lib/webext.ts @@ -67,6 +67,11 @@ export async function activeTabId() { return (await activeTab()).id } +//#background_helper +export async function activeTabContainerId() { + return (await activeTab()).cookieStoreId +} + /** Compare major firefox versions */ export async function firefoxVersionAtLeast(desiredmajor: number) { const versionstr = (await browserBg.runtime.getBrowserInfo()).version @@ -88,12 +93,17 @@ export async function firefoxVersionAtLeast(desiredmajor: number) { */ export async function openInNewTab( url: string, - kwargs: { active?; related? } = { active: true, related: false }, + kwargs: { active?; related?; cookieStoreId? } = { + active: true, + related: false, + cookieStoreId: undefined, + }, ) { const thisTab = await activeTab() const options: any = { active: kwargs.active, url, + cookieStoreId: kwargs.cookieStoreId, } // Be nice to behrmann, #342 diff --git a/src/manifest.json b/src/manifest.json index d45cd0ec..f5181a54 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -43,6 +43,8 @@ "bookmarks", "browsingData", "contextMenus", + "contextualIdentities", + "cookies", "clipboardWrite", "clipboardRead", "downloads", @@ -63,4 +65,4 @@ "strict_min_version": "54.0" } } -} \ No newline at end of file +}