Skip to content
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

Fix #89 endless loop between container and no container since 3.4.0 #90

Merged
merged 2 commits into from Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Tabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class Tabs {
return this.tabs.create(options);
}

update(tabId, options = {}) {
return this.tabs.update(tabId, options);
}

remove(tabId) {
return this.tabs.remove(tabId);
}
Expand Down
25 changes: 18 additions & 7 deletions src/containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@ import ContextualIdentity, {NO_CONTAINER} from './ContextualIdentity';
import Tabs from './Tabs';
import PreferenceStorage from './Storage/PreferenceStorage';

const createTab = (url, newTabIndex, currentTabId, cookieStoreId, openerTabId) => {
const createTab = (url, newTabIndex, currentTabId, openerTabId, cookieStoreId) => {
Tabs.get(currentTabId).then((currentTab) => {
Tabs.create({
const createOptions = {
url,
index: newTabIndex,
cookieStoreId,
active: currentTab.active,
openerTabId: openerTabId,
};
// Passing the openerTabId without a cookieStoreId
// creates a tab in the same container as the opener
if (cookieStoreId && openerTabId) {
createOptions.openerTabId = openerTabId;
}
Tabs.create(createOptions).then((createdTab) => {
if (!cookieStoreId && openerTabId) {
Tabs.update(createdTab.id, {
openerTabId: openerTabId,
});
}
});
PreferenceStorage.get('keepOldTabs').then(({value}) => {
if(!value){
if (!value) {
Tabs.remove(currentTabId);
}
}).catch(() => {
Expand Down Expand Up @@ -47,11 +58,11 @@ function handle(url, tabId) {

const openerTabId = currentTab.openerTabId;
if (hostIdentity.cookieStoreId === NO_CONTAINER.cookieStoreId && tabIdentity) {
return createTab(url, currentTab.index + 1, currentTab.id, undefined , openerTabId);
return createTab(url, currentTab.index + 1, currentTab.id, openerTabId);
}

if (hostIdentity.cookieStoreId !== currentTab.cookieStoreId && hostIdentity.cookieStoreId !== NO_CONTAINER.cookieStoreId) {
return createTab(url, currentTab.index + 1, currentTab.id, hostIdentity.cookieStoreId, openerTabId);
return createTab(url, currentTab.index + 1, currentTab.id, openerTabId, hostIdentity.cookieStoreId);
}

return {};
Expand All @@ -63,13 +74,13 @@ export const webRequestListener = (requestDetails) => {
if (requestDetails.frameId !== 0 || requestDetails.tabId === -1) {
return {};
}

return handle(requestDetails.url, requestDetails.tabId);
};

export const tabUpdatedListener = (tabId, changeInfo) => {
if (!changeInfo.url) {
return;
}
console.log(tabId, 'url changed', changeInfo.url);
return handle(changeInfo.url, tabId);
};