Thegreatsuspender: Request: Use chrome.tabs.discard feature

Created on 30 Nov 2016  路  18Comments  路  Source: greatsuspender/thegreatsuspender

Next changes have many pros, for example, it fixes history issue / makes extension more lightweight, stable and faster.

  1. Instead of suspend tabs, discard tabs using native chrome.tabs.discard.
  2. Discard only query(discardable: true, ... tabs.
  3. List discarded tabs by query(discard: true, ...)
  4. Implement discarding only if RAM is less than plus/or timer arguments.
  5. Remove tab restore feature (Chrome can restore tabs automatically after focus gain).
  6. Remove hook page/themes/screenshot feature.

I already implement this changes for myself. It took 5 minutes, but makes extension really lightweight and super stable/same useful.

Most helpful comment

OK. Sorry about the delay but it's ready!
Here's the github project page: https://github.com/deanoemcke/thegreatdiscarder
And on the chrome webstore: https://chrome.google.com/webstore/detail/the-great-discarder/jlipbpadkjcklpeiajndiijbeieicbdh

Please let me know of any bugs you find. Or ideas you might have for improvement.
Because tab discarding is so invisible, it's hard to even tell that the extension is doing anything except that tabs that are discarded will reload when they gain focus.
If you want to see what's really going on, there's a profiler page you can use by going to the url: chrome-extension://<extension_id>/html/profiler.html

And in addition to the pros that @arturkohut mentioned in the OP, i've removed the use of content scripts, and also converted the main script to an event page instead of a persistent background page. So there should be real gains in performance of the extension as well.

All 18 comments

I've actually already worked on this idea and have decided to implement it as a new project. It's just about finished and does exactly what you've described above - only, but doing it in a new project i've been able to rewrite the code from the ground up.
I'll post details shortly but hope to have it in the webstore in a week or so.

Oh man, it's sounds great! This is such an awesome idea.
Let me know if I can help you with testing.

Nope, chrome.tabs.discard still isn't supported on Linux.

Hi. It has been more than 2 weeks since your last reply. Any news?

@arturkohut almost there (well i was about 1 week ago) but then i got busy. i was hoping to finish it off over the christmas holidays. hope you don't mind waiting another week?

OK. Sorry about the delay but it's ready!
Here's the github project page: https://github.com/deanoemcke/thegreatdiscarder
And on the chrome webstore: https://chrome.google.com/webstore/detail/the-great-discarder/jlipbpadkjcklpeiajndiijbeieicbdh

Please let me know of any bugs you find. Or ideas you might have for improvement.
Because tab discarding is so invisible, it's hard to even tell that the extension is doing anything except that tabs that are discarded will reload when they gain focus.
If you want to see what's really going on, there's a profiler page you can use by going to the url: chrome-extension://<extension_id>/html/profiler.html

And in addition to the pros that @arturkohut mentioned in the OP, i've removed the use of content scripts, and also converted the main script to an event page instead of a persistent background page. So there should be real gains in performance of the extension as well.

Such a great news!
I just found that you doesn't check free RAM before discard tab?
It will be cool, if you add param to the settings page - "Don't discard if free RAM is more than...".

Yes. I'm looking into that - it's been a request for The Great Suspender for a while. The only API available in chrome production seems to be chrome.system.memory. Although I'm not sure this will give the information we need. Do you know much about what exactly availableCapacity is? Or whether there's another API I can use?
I did find this which seems to suggest it's not exactly what we're after? https://bugs.chromium.org/p/chromium/issues/detail?id=463374

I already made this function for myself in The Great Suspender.
First of all, I requested chrome.system.memory rights in the manifest file.
And second, I placed next code to background.js

`function requestTabSuspension(tab, force) {
force = force || false;

    //safety check
    if (typeof(tab) === 'undefined') return;

    //make sure tab is not special or already suspended
    if (isSuspended(tab) || isSpecialTab(tab)) return;

    //if forcing tab suspend then skip other checks
    if (force) {
        confirmTabSuspension(tab);

    //otherwise perform soft checks before suspending
    } else {

        //check whitelist
        if (isExcluded(tab)) {
            return;
        }
        //check internet connectivity
        if (gsUtils.getOption(gsUtils.ONLINE_CHECK) && !navigator.onLine) {
            return;
        }
        //check if computer is running on battery
        if (gsUtils.getOption(gsUtils.BATTERY_CHECK) && chargingMode) {
            return;

        } else {
            // Check if free memory is less than 768 MB
            chrome.system.memory.getInfo(function(info) {
                if (info.availableCapacity < (768 * 1024 * 1024)) {
                    confirmTabSuspension(tab);
                }
            });
        }
    }
}`

I used it for about one month along with tabs.discard, and it works perfect. My PC works fast no matter how many tabs is open, and if I have open only 5 tabs, the extension just do nothing.
If I press to manually discard all tabs, it will be work without checking free memory.

But I also like your new The Great Tab Discarder, because it unload background page from memory.
So it will be good, if you try to put this function into your code.

Unfortunately, I don't think that info.availableCapacity is a reliable measure of memory used. From my testing, it can range from 50mb to 250mb regardless of how many tabs I have open, or how much memory chrome is actually using.

It's actually a free system memory, not a used.
In my case, availableCapacity always provide same results as Windows Task Manager.
Maybe it works an another way in UNIX, if you're using that.

So, there is no option to discard a specific tab? Only auto discarding?

@sldx If I was going to enable specific tab discarding, I would need to work out a new interface for doing so, as it is not possible to discard a tab that is currently being viewed. I could reintroduce the 'discard current tab' option in the popup menu, but it would need to select a different tab before it could discard the current one. This is not that intuitive for me, and I question how useful it is to be able to discard a specific tab. What is your use case for this feature?

You can add option - "Discard previously active tab" or "Discard tabs to the right/left".
@deanoemcke @sldx

I used the Suspender till now, with a 12h timeout for suspension. But sometimes I'd suspend a tab because I intended to easily come back to it later, and not have it eat resources in the meantime (especially google docs). I actually used the keyboard shortcut for that, it was pretty handy.

I like the "select next tab to the right" option, that's what you'd do anyway since the tab is suspended now.

OK. I have reimplemented the 'discard current tab' functionality.
I've decided to switch to the last active tab when this happens. It seems the most naturally intuitive for me, and is the least likely tab to have already been discarded (preventing a page reload when this happens).
New version will be on the chrome webstore shortly.
Thanks for the feed back you guys.

Even better. Thx for making it ;)

Was this page helpful?
0 / 5 - 0 ratings