rNeomy / tab-suspender

Automatically suspend (hibernate) inactive tabs to free up system resources; This project is discontinued in favor of https://add0n.com/tab-discard.html
http://add0n.com/tab-suspender.html
Mozilla Public License 2.0
112 stars 32 forks source link

Fix #2: Properly load faded favicon on suspended tab #12

Closed christarazi closed 7 years ago

christarazi commented 7 years ago

This pull request fixes issue #2 where the favicon only loads as the default coffee icon. Now the original favicon is loaded (with fade effect).

Some technical details: To do this, I needed a way to pass the favicon image source so that I can use it in data/suspend/index.js. I figured out that I could pass the favicon URL from common.js. Not sure if this is the best way to do it, but it seemed the most straightforward. I also took some inspiration from The Great Suspender Chrome extension.

Let me know if there's anything else you'd like to see. I am happy to discuss this.

christarazi commented 7 years ago

note that this only works when tab is redirected from an existing tab where the favIcon URL is already resolved and is available to the background page. How about tabs that are created from the season restore function

This is actually already working because session-restore just saves the URL of the suspended tab, which already has the favicon encoded as a URI.

or the new feature where a suspended tab gets opened from a link?

I just added a commit for this one.


Could you elaborate on the cookie functionality? And from what I can gather, you'd only like it to to be for Firefox?

christarazi commented 7 years ago

Come to think of it, I don't see the need for storing the final URI in document.cookie. I don't see any tangible benefits it would bring, especially given the added complexity of utilizing cookies based on the type of browser, returning the correct cookie value for the site (requires parsing), etc. Plus we have to store the favicon URI in the URL regardless, in case there isn't a corresponding cookie value set for the tab.

What do you think @rNeomy?

rNeomy commented 7 years ago

ok then. Please fix the issues and prepare a new pull request. We can check the result and play with it.

christarazi commented 7 years ago

I pushed the changes that you requested.

In regards to opening a new tab in suspended state feature:

For Chrome family browsers: If the site has already been visited (in the cache), then chrome://favicon will load the correct favicon and fade it.

If the site is not in the cache, then chrome://favicon will not be able to load the favicon. According to this Stackoverflow answer, chrome://favicon loads favicons only from cache. So there isn't much we can do here, unless we load the page and then perform suspend. However, that defeats the purpose of this feature.

For Firefox: There isn't any favicon API that can load cached favicons as far as I know. So the default favicon will load here. Only when the user suspends the tab or after the timer, will the proper favicon be loaded and faded out.

Let me know what you think.

Update: here's a thread tracking the progress of a favicon API for Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1315616

rNeomy commented 7 years ago

@christarazi thanks. We should switch to chrome://favicon when it is available on Firefox then.