Auto hibernate inactive tabs
-
Was looking for this myself but found nothing so made it myself.
Here's the code for the mod:
(function () { const HIBERNATE_TIMEOUT = 15 * 1000; // 15 seconds //const HIBERNATE_TIMEOUT = 15 * 1000; // 15 seconds //const HIBERNATE_TIMEOUT = 30 * 1000; // 30 seconds //const HIBERNATE_TIMEOUT = 60 * 1000; // 1 minute //const HIBERNATE_TIMEOUT = 2 * 60 * 1000; // 2 minutes //const HIBERNATE_TIMEOUT = 3 * 60 * 1000; // 3 minutes //const HIBERNATE_TIMEOUT = 4 * 60 * 1000; // 4 minutes //const HIBERNATE_TIMEOUT = 5 * 60 * 1000; // 5 minutes function hibernateInactiveTabs() { const tabs = chrome.tabs.query({ currentWindow: true, active: false }, (tabs) => { tabs.forEach((tab) => { const elapsedTime = Date.now() - tab.lastAccessed; if (elapsedTime >= HIBERNATE_TIMEOUT) { chrome.tabs.discard(tab.id); } }); }); } setInterval(hibernateInactiveTabs, HIBERNATE_TIMEOUT / 2); })();
This script will hibernate inactive tabs after 5 minutes (you can change the HIBERNATE_TIMEOUT constant to set a different interval, i added a couple of examples in the script).
To install this mod in Vivaldi:
-
Save the code above as a .js file, for example, vivaldi-hibernate-inactive-tabs.js.
-
Locate your Vivaldi's browser resources directory:
-
Windows: %localappdata%\Vivaldi\Application[VERSION]\resources\vivaldi
-
macOS: /Applications/Vivaldi.app/Contents/Frameworks/Vivaldi Framework.framework/Versions/[VERSION]/Resources/vivaldi
-
Linux: /opt/vivaldi/resources/vivaldi
-
Replace [VERSION] with the installed Vivaldi version.
-
In the resources\vivaldi folder, create a new folder named user_files if it doesn't exist.
-
Copy the vivaldi-hibernate-inactive-tabs.js file into the user_files folder.
-
Open the browser.html file located in the resources\vivaldi folder with a text editor (make a backup before editing).
-
Add the following line before the closing </body> tag:
<script src="user_files/vivaldi-hibernate-inactive-tabs.js"></script>
- Save the browser.html file and restart Vivaldi.
Now, Vivaldi should automatically hibernate inactive tabs after the specified timeout.
-
-
Great. But can we set it more easily? By Tampermonkey? I remember that Vivaldi supports js scripts as usual extensions, if you drop them into vivaldi://extensions/
-
Good job. This really should be a built in feature by now
-
@Aniexiety
Hi, nice mod, I want to use it in the snapshot build but tested this in the latest stable, too.
It does not work for me.
I copy the code and past it in a .js file.I mainly want to use it for workspaces but it doesn´t hibernate regular tabs, too.
Anything wrong with my setup?Vivaldi 5.8.2978.3, 5.7.2921.65 on Linux.
Cheers, mib
-
That would be a really useful feature. I have been always thinking about having that on Vivaldi, since some tabs do use resources on the background, and I do not want to do it manually when it is not needed to be in active tab.
-
@sjudenim Agree. It appears there are many similar feature requests. do you know which one might be closest to this one?
-
You actually don't need a mod for this, but you do need to enable an "experimental" flag:
vivaldi://flags/#high-efficiency-mode-available
Set to your preferred hibernation time. Restart.Then:
chrome://settings/performance
Enable Memory saver. Tabs will hibernate on a timer.Note that this flag is Enabled by default in Chrome 112, I don't know why it isn't available by default in Chromium 112. Maybe Google just wants to keep this feature a "secret" to only Chrome users...
All that's lacking is for Vivaldi to implement a Settings UI for it.
-
@Pathduck Thank you! This works very well. I'll need to make a note to turn these settings off if Vivaldi ever offers this feature natively.
-
@Aniexiety I don't believe this mod is actually working in its current state.
While
tab.lastAccessed
works in Firefox, it is not valid in Chromium based browsers.const elapsedTime = Date.now() - tab.lastAccessed;
results inNaN
.I am not sure if there is an equivilant API option, so you might need to write your own log of last accessed times to storage.
Edit: I also wouldn't suggest putting this file in the
user_files
directory. Files in that folder will show up in the Page Actions dialog. Enabling it as a Page Action won't do anything, so it probably shouldn't be there.You can create your own folder in
Vivaldi\Application[VERSION]\resources\vivaldi
or just put the js file in the same directory asbrowser.html
. -
Said:
I'll need to make a note to turn these settings off if Vivaldi ever offers this feature natively.
You will not have to turn it off. Because if Vivaldi implement a Settings UI for it, will only be making visible a feature that is already a native feature.
-
@Pathduck said in Auto hibernate inactive tabs:
You actually don't need a mod for this, but you do need to enable an "experimental" flag:
The flag seems not available in the newest snapshot?
-
@g_bartsch
Hi, this is not experimental anymore, Memory Saver is native now.
Chrome://settings/performanceCheers, mib
-
@mib2berlin Thank you Sir. I had found that by looking at the second link you posted.
But there is now no option to set a hibernate time?
-
@g_bartsch
Hi, iirc only Edge have this feature now, Chromium removed the flags to enable this.Cheers, mib
-
@mib2berlin Thank you.
I think it's here in Vivaldi working? No?
-
@g_bartsch
Yes this is working, I meant the hibernation time setting. -
@mib2berlin I hope Vivaldi will expose that setting. I'm glad hibernation is working but don't feel happy having no idea how long for it is.
-
vivaldi://flags/#memory-saver-multi-state-mode
To Enabled, Restart.Then in
chrome://settings/performance
You're welcome
-
Interestingly, the performance settings seem to live in
Local State
, meaning they are active for all profiles.
Probably because they are still linked to the experimental flag being set.For those brave enough, you can "fine-tune" the value in the JSON directly:
"performance_tuning": { "high_efficiency_mode": { "state": 2, "time_before_discard_in_minutes": 1 } },
-
@Pathduck said in Auto hibernate inactive tabs:
You're welcome
Indeed! Thank you so much; this is nice!!