@explorerthegeneral I just tested it, and other than needing to update an event handler to bring it up to date with 5.1.2567.73 (see original post for updated code), it should hibernate background tabs in all open windows.
GIF showing it working
hibernating.gif
One thing that the mod won't do is hibernate the active tab of any given window (even if it isn't focused). This is more a limitation of Vivaldi than a conscious choice I made while writing the mod. However, this behavior does make sense. Any active tab will need to be loaded again instantly, so it doesn't make much sense to allow hibernation for active tabs.
But it got me thinking, looking at the code (and I'm no coder), it looks like it could be modified to loop through all the windowId's rather than just the currently active one.
It is looping over all tabs rather than windows. The beginning section with the mention of the current windowId is for one of the config parameters. Here is a more thoroughly commented section of the relevant code to better explain it's function:
function hibernateBackgroundTabs() {
// This section is needed for the SKIP_ACTIVE_TAB_STACK_TABS config parameter
// ================ START ================
// figure out the ID of the active window to allow fetching the active tab
vivaldi.windowPrivate.getCurrentId((currentWindowId) => {
// get the active tab
chrome.tabs.query({ active: true, windowId: currentWindowId }, (activeTab) => {
activeTab = activeTab[0];
// see if the active tab is in a tab stack, and if so, get the stack ID
let activeTabStackID = (regex.exec(activeTab.extData) || [false])[0];
// ================= END =================
// get tabs from all normal (not devTool or popup) windows
chrome.tabs.query({ windowType: "normal" }, (tabs) => {
// loop through all tabs and check if it should be hibernated or not based off of parameters of the tab and mod config
tabs.forEach((tab) => {
if (tab.discarded) return; // already discarded, so can skip it
if (tab.windowId === currentWindowId && tab.active) return; // skip active tab; apparently not needed; Vivaldi already handles
if (SKIP_SELECTED_TABS && tab.highlighted) return; // skip selected tabs if configured to do so
// skip tabs in the same tab stack as the active tab if configured to do so
if (SKIP_ACTIVE_TAB_STACK_TABS && activeTabStackID) {
let stackID = (regex.exec(tab.extData) || [""])[0];
if (stackID === activeTabStackID) return;
}
chrome.tabs.discard(tab.id);
});
});
});
});
}