Skip to content

Commit a762b5e

Browse files
Add a tab observer to show hidden tabs as there are many tab creation routes. Uses a queue to prevent multiple triggers. Fixes #765
1 parent 3cc4034 commit a762b5e

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

webextension/js/background/backgroundLogic.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ const backgroundLogic = {
5252
},
5353

5454
async openTab(options) {
55-
const userContextId = ("userContextId" in options) ? options.userContextId : 0;
56-
const cookieStoreId = backgroundLogic.cookieStoreId(userContextId);
57-
// Unhide all hidden tabs
58-
this.showTabs({
59-
cookieStoreId
60-
});
6155
return this.openNewTab(options);
6256
},
6357

webextension/js/background/messageHandler.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const messageHandler = {
33
// We use this to catch redirected tabs that have just opened
44
// If this were in platform we would change how the tab opens based on "new tab" link navigations such as ctrl+click
55
LAST_CREATED_TAB_TIMER: 2000,
6+
unhideQueue: [],
67

78
init() {
89
// Handles messages from webextension code
@@ -87,20 +88,6 @@ const messageHandler = {
8788
}
8889
});
8990

90-
browser.tabs.onCreated.addListener((tab) => {
91-
// This works at capturing the tabs as they are created
92-
// However we need onFocusChanged and onActivated to capture the initial tab
93-
if (tab.id === -1) {
94-
return {};
95-
}
96-
});
97-
98-
browser.tabs.onRemoved.addListener((tabId) => {
99-
if (tabId === -1) {
100-
return {};
101-
}
102-
});
103-
10491
browser.tabs.onActivated.addListener((info) => {
10592
assignManager.removeContextMenu();
10693
browser.tabs.get(info.tabId).then((tab) => {
@@ -127,14 +114,27 @@ const messageHandler = {
127114
});
128115
}, {urls: ["<all_urls>"], types: ["main_frame"]});
129116

130-
// lets remember the last tab created so we can close it if it looks like a redirect
131-
browser.tabs.onCreated.addListener((details) => {
132-
this.lastCreatedTab = details;
117+
browser.tabs.onCreated.addListener((tab) => {
118+
// lets remember the last tab created so we can close it if it looks like a redirect
119+
this.lastCreatedTab = tab;
120+
if (tab.cookieStoreId) {
121+
this.unhideContainer(tab.cookieStoreId);
122+
}
133123
setTimeout(() => {
134124
this.lastCreatedTab = null;
135125
}, this.LAST_CREATED_TAB_TIMER);
136126
});
127+
},
137128

129+
async unhideContainer(cookieStoreId) {
130+
if (!this.unhideQueue.includes(cookieStoreId)) {
131+
this.unhideQueue.push(cookieStoreId);
132+
// Unhide all hidden tabs
133+
await backgroundLogic.showTabs({
134+
cookieStoreId
135+
});
136+
this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1);
137+
}
138138
},
139139

140140
async onFocusChangedCallback(windowId) {

0 commit comments

Comments
 (0)