Search code examples
javascriptapifirefoxfirefox-addon

Firefox Javascript api extension for topsites thumbs


I'm trying to make a simple Firefox extension that lists topSites() in an HTML page which will act as newtab page.

var gettingTopSites = browser.topSites.get({includeFavicon: true});
gettingTopSites.then((res) => {
 console.log(res[0]); 
})
// The output of log:
/**
Object { type: "url", url: "https://www.facebook.com/", title: "Facebook", favicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA4klEQVRYhWNwytnk6ZS+5bFT+qb/9MVbHjvlbPJkGBjLEY5gGDjLIXjUATR3gEvmZvo6wCd/2/8l2279v3zn7f+PX37+//////8/f//9f/3+O+0dUNh77P/bjz/+4wI0dYBP/rb/r959x2k5zR2wdPttvJbT3AFnr79GsezD55//Kyad+O+Rs5U+ifD1e9Tgr51+iih9VHMAOnAlkP1o7gBi9Y06gGwHkApevPk2sA44dfXVwDpg7d57A+uACUsvDbNEOOqAUQeMOmDUAVR0AHU6p+Q5YMtjBmp1z0l3AKR7DgApZF4e3+fcXwAAAABJRU5ErkJggg==" }
*/

As the above example, using topSites.get() method, I just able to get Favicons, but I need to get thumb image of the site too. The thumb images that looks like the default Firefox home page topsites. I could not able to find any option that gets the thumb image. Is there another javascript api that may get site thumb?


Solution

  • There is a request bug for the feature: 1246693 - Provide WebExtension Thumbnail API but it is still "open". Currently Firefox doesn't provide any API to access thumbnail stored by Firefox itself. Instead you need to create them by yourself with HTML canvas.