-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for firefox contextual identities #120
base: master
Are you sure you want to change the base?
Conversation
@@ -26,7 +26,7 @@ | |||
}, | |||
"offline_enabled": true, | |||
|
|||
"permissions": ["alarms", "contextMenus", "idle", "notifications", "storage", "tabs"], | |||
"permissions": ["alarms", "contextMenus", "contextualIdentities", "cookies", "idle", "notifications", "storage", "tabs"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use [contextualIdentities] you need to include the "contextualIdentities" and "cookies" permissions in your manifest.json file.
Source: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/contextualIdentities
@@ -150,13 +150,14 @@ async function openExtensionTab(url) { | |||
|
|||
async function openTab(tab, windowId, automatic = false) { | |||
var windows = await getAllWindows(); | |||
var cookieStoreId = tab.cookieStoreId ? { cookieStoreId: tab.cookieStoreId } : {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing this property to chrome.tabs.create
or chrome.windows.create
causes an exception to be raised in browsers that don't support contextual identities.
I thought about using getBrowser() === 'firefox'
to conditionally pass this poperty, but I couldn't get the getBrowser
function to behave (it returned 'chrome'
even in Firefox) and I didn't want to mix other fixes with this PR.
@@ -138,7 +138,8 @@ async function snoozeInBackground(item, tab) { | |||
var title = !isHref ? tab.title : (item.linkText ? item.linkText : item.selectionText); | |||
var wakeUpTime = snoozeTime.valueOf(); | |||
var pinned = !isHref && tab.pinned ? tab.pinned : undefined; | |||
var assembledTab = Object.assign(item, {url, title, pinned, startUp, wakeUpTime}) | |||
var cookieStoreId = tab.cookieStoreId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cookieStoreId
property is present if browser is Firefox and the extension has "cookies" permission (source).
if (tab.incognito) { | ||
var w = windows.find(i => i.incognito) || await createWindow(undefined, t.incognito); | ||
await new Promise(r => chrome.tabs.create({url: tab.url, active: false, pinned: tab.pinned, windowId: w.id}, r)); | ||
await new Promise(r => chrome.tabs.create({url: tab.url, active: false, pinned: tab.pinned, ...cookieStoreId, windowId: w.id}, r)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tabs.create
takes the optional cookieStoreId
parameter in Firefox (source).
} else if (!windows || !windows.filter(w => !w.incognito).length) { | ||
await new Promise(r => chrome.windows.create({url: tab.url}, r)); | ||
await new Promise(r => chrome.windows.create({url: tab.url, ...cookieStoreId}, r)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
windows.create
takes the optional cookieStoreId
parameter in Firefox (source).
Implements #76.