Details on the Favicon API

3,080 views
Skip to first unread message

Pavel Aronovich

unread,
Apr 10, 2023, 9:23:40 AM4/10/23
to Chromium Extensions
Hi,

Please describe the internal mechanism for obtaining favicon:
https://developer.chrome.com/docs/extensions/mv3/favicon/

The question is related to what is the difference from this method:

Thanks.

Patrick Kettner

unread,
Apr 10, 2023, 9:30:03 AM4/10/23
to Pavel Aronovich, Chromium Extensions
the `favicons` permission is to access the current favicon on the a tab, the difference between that and the link you gave is that the link only works for public/universal favicons. The permission can give an extension access to a favicon that provides additional information (e.g. an unread count on gmail). 

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/8c5d61cb-d7a3-43e1-9fae-098f21713f8fn%40chromium.org.

Pavel Aronovich

unread,
Apr 10, 2023, 9:34:59 AM4/10/23
to Chromium Extensions, Patrick Kettner, Chromium Extensions, Pavel Aronovich
How then to explain this example:

That is, it is getting a favicon for any site.

понедельник, 10 апреля 2023 г. в 16:30:03 UTC+3, Patrick Kettner:

Patrick Kettner

unread,
Apr 10, 2023, 9:38:39 AM4/10/23
to Pavel Aronovich, Chromium Extensions
Like most of the samples, they are relatively contrived to keep the code easy to understand.

Pavel Aronovich

unread,
Apr 10, 2023, 9:40:04 AM4/10/23
to Chromium Extensions, Patrick Kettner, Chromium Extensions, Pavel Aronovich
Does it make any sense to use this favicon receiving API or use the old method. And for this I want to understand what the difference is.

понедельник, 10 апреля 2023 г. в 16:38:39 UTC+3, Patrick Kettner:

Patrick Kettner

unread,
Apr 10, 2023, 9:45:08 AM4/10/23
to Pavel Aronovich, Chromium Extensions
I apologize I was not more clear.

You gave two examples. One is using the favicon permission, which I believe you are referring to as the "favicon receiving API". This is the method that is used in the sample you linked to. This is useful if you want to know the exact favicon used in a specific tab that is loaded. Many change their favicon based on the state of a person using their site. It may show information like the number of unread messages (as in the gmail example I gave originally), a different color theme, or any other kind of customization. 
The other example (i.e. https://www.google.com/s2/favicons?domain=google.com) which I believe you are calling "the old method", does not have the ability to access the state of a user's tab. It is just loading a url. So if there is any customization of the favicon, then you are not going to be able to get it using this method.

Does that make sense?

Pavel Aronovich

unread,
Apr 10, 2023, 9:48:36 AM4/10/23
to Chromium Extensions, Patrick Kettner, Chromium Extensions, Pavel Aronovich
I need to get a favicon of any site. It has nothing to do with the tab. Just about this is the example given above. It turns out I can replace the old method with a new one. I want to understand why I should do this.

понедельник, 10 апреля 2023 г. в 16:45:08 UTC+3, Patrick Kettner:

Patrick Kettner

unread,
Apr 10, 2023, 9:52:17 AM4/10/23
to Pavel Aronovich, Chromium Extensions
I am not sure if I understand your question, but you do not need to use the new `favicon` permission. If you just need the image of a public favicon, you can fetch it via `https://www.google.com/s2/favicons?domain=URL` or any other service.

PhistucK

unread,
Apr 10, 2023, 10:06:00 AM4/10/23
to Pavel Aronovich, Chromium Extensions, Patrick Kettner
I would say mainly because that Google favicon-fetching service is not necessarily a supported way of getting favicons.
You seem to be piggybacking on an exposed, yet undocumented/unofficial service that may change or break at any moment, unlike the Chrome extension API, which is the documented, supported and stable way of getting the favicon.

PhistucK


Pavel Aronovich

unread,
Apr 10, 2023, 11:52:57 AM4/10/23
to Chromium Extensions, PhistucK, Chromium Extensions, Patrick Kettner, Pavel Aronovich
Yes, this is an argument. 
But my question was simple. How this API works, how exactly it gets the favicon of the site by URL.

понедельник, 10 апреля 2023 г. в 17:06:00 UTC+3, PhistucK:

Pavel Aronovich

unread,
Apr 10, 2023, 12:01:18 PM4/10/23
to Chromium Extensions, Pavel Aronovich, PhistucK, Chromium Extensions, Patrick Kettner
Interestingly, this kind of request from the extension console (SW, Popup) does not work: 

chrome-extension://MY_EXTENSION_ID/_favicon/?pageUrl=https%3A%2F%2Fwww.google.com&size=32

Uncaught SyntaxError: Unexpected token ':'

понедельник, 10 апреля 2023 г. в 18:52:57 UTC+3, Pavel Aronovich:

Patrick Kettner

unread,
Apr 10, 2023, 12:12:31 PM4/10/23
to Pavel Aronovich, Chromium Extensions, PhistucK
In what way are you trying to load the url (as an img src, `fetch`(), injected into a page, etc)? have you added the favicon permission to your manifest? 

Pavel Aronovich

unread,
Apr 10, 2023, 12:42:46 PM4/10/23
to Chromium Extensions, Patrick Kettner, Chromium Extensions, PhistucK, Pavel Aronovich
I'm sorry, this URL works through fetch.
But still, how does he get a favicon by URL?

понедельник, 10 апреля 2023 г. в 19:12:31 UTC+3, Patrick Kettner:

Patrick Kettner

unread,
Apr 10, 2023, 12:53:47 PM4/10/23
to Pavel Aronovich, Chromium Extensions, PhistucK
Are you asking how the chromium api works?

hrg...@gmail.com

unread,
Apr 10, 2023, 12:55:58 PM4/10/23
to Chromium Extensions, Pavel Aronovich, Patrick Kettner, Chromium Extensions, PhistucK
Advantages of the favicon API:
  • Gets the icons from the browser's internal cache of favicons, therefore it doesn't need an internet connection
  • It can get the favicon of all URLs present in the user's bookmarks
  • It can get the favicon of all open tabs and closed tabs

Disadvantages
  • If a URL is not in the browser's internal cache, it will return a generic favicon

Pavel Aronovich

unread,
Apr 10, 2023, 1:03:19 PM4/10/23
to Chromium Extensions, hrg...@gmail.com, Pavel Aronovich, Patrick Kettner, Chromium Extensions, PhistucK
Thanks. That's exactly what I wanted to know.

понедельник, 10 апреля 2023 г. в 19:55:58 UTC+3, hrg...@gmail.com:

Simeon Vincent

unread,
Apr 10, 2023, 3:25:31 PM4/10/23
to Pavel Aronovich, Chromium Extensions, hrg...@gmail.com, Patrick Kettner, PhistucK
Reply all
Reply to author
Forward
0 new messages