Skip to content

Commit

Permalink
Fix active tab event bugged (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny authored Jun 7, 2021
1 parent 23710f5 commit d51a194
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "open-new-tab-after-current-tab",
"version": "0.3.0",
"version": "0.4.0",
"description": "Opens new tab after the active tab, instead of last position.",
"homepage": "https://narno.dev/Open-New-Tab-After-Current-Tab/",
"author": "Arnaud Ligny",
Expand Down
29 changes: 14 additions & 15 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,23 @@ chrome.runtime.onInstalled.addListener(details => {
});
// On window focused
chrome.windows.onFocusChanged.addListener(windowId => {
// @see https://developer.chrome.com/extensions/windows#property-WINDOW_ID_NONE
if (windowId !== -1 && windowId !== -2) {
chrome.tabs.getSelected(chrome.tabs.windowId, tab => {
console.log(windowId + ' - chrome.windows.onFocusChanged - set currentIndex = tab.index: ' + tab.index);
currentIndex[windowId] = tab.index;
});
}
setTimeout(() => { // https://www.reddit.com/r/chrome_extensions/comments/no7igm/chrometabsonactivatedaddlistener_not_working/
if (windowId !== -1 && windowId !== -2) { // @see https://developer.chrome.com/docs/extensions/reference/windows/#properties
chrome.tabs.query({windowId, active: true}, tabs => {
console.log(tabs[0].windowId + ' - chrome.windows.onFocusChanged - set currentIndex = tab.index: ' + tabs[0].index);
currentIndex[tabs[0].windowId] = tabs[0].index;
});
}
}, 300);
});
// On tab activated
chrome.tabs.onActivated.addListener(activeInfo => {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
} else {
chrome.tabs.get(activeInfo.tabId, tab => {
console.log(tab.windowId + ' - chrome.tabs.onActivated - set currentIndex = tab.index: ' + tab.index);
currentIndex[tab.windowId] = tab.index;
chrome.tabs.onActivated.addListener(activeInfo => { // eslint-disable-line no-unused-vars
setTimeout(() => {
chrome.tabs.query({active: true, lastFocusedWindow: true, currentWindow: true}, tabs => {
console.log(tabs[0].windowId + ' - chrome.tabs.onActivated - set currentIndex = tab.index: ' + tabs[0].index);
currentIndex[tabs[0].windowId] = tabs[0].index;
});
}
}, 300);
});
// On tab manually moved
chrome.tabs.onMoved.addListener(eventOnMoved);
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Open New Tab After Current Tab",
"description": "__MSG_extDescription__",
"version": "0.3.0",
"version": "0.4.0",
"homepage_url": "https://narno.dev/Open-New-Tab-After-Current-Tab/",
"author": "Arnaud Ligny",
"background": {
Expand Down

0 comments on commit d51a194

Please sign in to comment.