7

I wanted to learn how to dynamically update the favicon using the Google Chrome browser and I've noticed that the browser seems to throttle how often you can update the favicon per second and that sort of makes things look sloppy. The test page I've made for this is:

http://staticadmin.com/countdown.html

Which is simply a scrolling message displaying the results of a countdown. I added an input field to tweak how many pixels per second are moved by the script and I've eyeballed the max to be about 5 frames per second smoothly in Google Chrome and I have not tested it in any other browsers.

My question is what is the maximum frequency, are there any ways to change it, and is there a particular reason behind it?

NOTE: I've also noticed that this value changes based on window focus as well. It seems to drop to about 1 update per second when the browser's window isn't in focus and returns to "max" when you return.

rfoo
  • 1,160
  • 1
  • 12
  • 27
  • 3
    sounds like your're trying to do something it's not designed for. the 1fps on blur tabs is because chrome throttles setIntervals to 1Hz on a blurred tab. – dandavis Aug 25 '14 at 00:51
  • Not sure if this is of any help, but take a look: http://stackoverflow.com/questions/6183463/when-using-setinterval-if-i-switch-tabs-in-chrome-and-go-back-the-slider-goes – ctwheels Aug 25 '14 at 16:17
  • In browsers that support it you could simply go with a .gif favicon. – Etheryte Aug 25 '14 at 17:19
  • You could make a GIF with CANVAS and just have that as favicon. No need for refreshing. Maybe? – Rudie Aug 25 '14 at 19:41
  • @Rudie: You can't make an *animated* GIF through Canvas alone... but [JavaScript is certainly capable enough](https://jnordberg.github.io/gif.js/). – rvighne Aug 26 '14 at 02:19
  • @rvighne You can't make anything on canvas without JS... Of course you need JS. But to make a dynamic favicon, you'll definitely need canvas. – Rudie Aug 26 '14 at 17:03

1 Answers1

1

The truth is, Chrome (and any reasonable browser) does not expect the favicon to ever change. They don't even show animations up there (only the first frame is frozen and displayed), though there's this feature request. The fact that you can change it at all through the DOM is somewhat of a hack. That's why the framerate is unpredictable, it's not even close to being optimized for that.

Chrome (and other browsers) throttle setInterval and friends to 1 Hz when the tab is blurred, which is why the animation becomes even worse when you switch tabs. It doesn't know that your interval is acting on a currently visible UI element.

There is no way to change this behavior, nor the maximum frequency, through JavaScript. Sorry.

rvighne
  • 20,755
  • 11
  • 51
  • 73
  • There absolutely must be a way, so this is not a good answer. It's not a good answer anyway, but if you keep this, people won't even try. – Rudie Aug 26 '14 at 17:04
  • @Rudie: Who says there must be a way? I have never found any and I tried to reflect that truth in my answer. If you are more knowledgeable than I, then make another answer and I'll upvote you. – rvighne Aug 26 '14 at 23:28
  • I say there must be a way. Just me. But I don't know it. But sometimes when I see a cool question without answer, I fiddle and make something. An answer thay say "it can't be done" is not an answer, and it stops people from thinking about it. – Rudie Aug 27 '14 at 11:55
  • @Rudie: Your webpage is ruled by the browser, and to make it work you'll need to change the browser (as there is currently no JavaScript API to control framerates of favicons separately). That's not easy, but if you star the feature request I linked to or just be active at Chromium, then you may be able to and make it happen. But that part's not really on-topic here. – rvighne Aug 28 '14 at 03:38
  • You don't need a separate API for everything.... You can choose your favicon and you can create images with CANVAS, so what else do you need? A static GIF will update more than once a second, won't it? So you can create a dynamic GIF that does that too? If that's not true, forget everything I said. – Rudie Aug 28 '14 at 10:21
  • @Rudie: You *can* dynamically create an animated GIF and put it in the favicon, but most browsers will only display the first frame, ignoring the animation. – rvighne Aug 31 '14 at 16:55