webextension get favicon from bookmark [solved for now]

Talk about add-ons and extension development.
Post Reply
Brummelchen
Posts: 4480
Joined: March 19th, 2005, 10:51 am

webextension get favicon from bookmark [solved for now]

Post by Brummelchen »

this is what i need to replace:

Code: Select all

img.src = "chrome://favicon/" + url_;
but i did not found yet any how-to on MDN
https://developer.mozilla.org/en-US/Add ... nsions/API
the permission is

Code: Select all

"chrome://favicon/"
but firefox dont support this, neither a replacement.
and as far i read i cannot use the sdk api level:
https://developer.mozilla.org/en-US/Add ... es_favicon

converted extension is working that far but show no icons

any help appreciated, either link or a code snippet.
edit - maybe solved for now - there exist no replacement for sdk getfavicon:
https://developer.mozilla.org/en-US/Add ... Add-on_SDK
Low-level APIs

Add-on SDK WebExtensions
places/bookmarks bookmarks
places/favicon None
#-o


Update:
i just examined another (chrome+firefox) extension "group speed dial") which contains the request method

Code: Select all

https://plus.google.com/_/favicon?domain_url=${t}
which tries to get the favicon online.

Update2
plus.google is blocked due tracking protection and only root domain returns propper favicon (in most cases).

Code: Select all

        img.src = 'https://s2.googleusercontent.com/s2/favicons?domain_url=' + extractHostname(url);

Code: Select all

	extractHostname(url) {
		var hostname;
		//find & remove protocol (http, ftp, etc.) and get hostname

		if (url.indexOf("://") > -1) {
			hostname = url.split('/')[2];
		}
		else {
			hostname = url.split('/')[0];
		}

		//find & remove port number
		hostname = hostname.split(':')[0];
		//find & remove "?"
		hostname = hostname.split('?')[0];

		return hostname;
	},
Post Reply