Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Improve favicon extraction (#541)

Leendert de Borstad52ec5db1f0
diff --git a/browser-extensions/chrome/src/contentScript/Filter.ts b/browser-extensions/chrome/src/contentScript/Filter.ts
index 0d3d41035..f991d45b9 100644
--- a/browser-extensions/chrome/src/contentScript/Filter.ts
+++ b/browser-extensions/chrome/src/contentScript/Filter.ts
@@ -14,29 +14,27 @@ export function filterCredentials(credentials: Credential[], currentUrl: string,
);
// 2. Base URL match with fuzzy domain comparison if no exact matches
- if (filtered.length === 0) {
- filtered = credentials.filter(cred => {
- if (!cred.ServiceUrl) return false;
- try {
- const credUrlObject = new URL(cred.ServiceUrl);
- const currentUrlObject = new URL(baseUrl);
-
- // Extract root domains by splitting on dots and taking last two parts
- const credDomainParts = credUrlObject.hostname.toLowerCase().split('.');
- const currentDomainParts = currentUrlObject.hostname.toLowerCase().split('.');
-
- // Get root domain (last two parts, e.g., 'aliasvaul.net')
- const credRootDomain = credDomainParts.slice(-2).join('.');
- const currentRootDomain = currentDomainParts.slice(-2).join('.');
-
- // Compare protocols and root domains
- return credUrlObject.protocol === currentUrlObject.protocol &&
- credRootDomain === currentRootDomain;
- } catch {
- return false;
- }
- });
- }
+ filtered = credentials.filter(cred => {
+ if (!cred.ServiceUrl) return false;
+ try {
+ const credUrlObject = new URL(cred.ServiceUrl);
+ const currentUrlObject = new URL(baseUrl);
+
+ // Extract root domains by splitting on dots and taking last two parts
+ const credDomainParts = credUrlObject.hostname.toLowerCase().split('.');
+ const currentDomainParts = currentUrlObject.hostname.toLowerCase().split('.');
+
+ // Get root domain (last two parts, e.g., 'aliasvaul.net')
+ const credRootDomain = credDomainParts.slice(-2).join('.');
+ const currentRootDomain = currentDomainParts.slice(-2).join('.');
+
+ // Compare protocols and root domains
+ return credUrlObject.protocol === currentUrlObject.protocol &&
+ credRootDomain === currentRootDomain;
+ } catch {
+ return false;
+ }
+ });
// 3. Page title word match if still no matches
if (filtered.length === 0 && pageTitle.length > 0) {
diff --git a/browser-extensions/chrome/src/contentScript/Popup.ts b/browser-extensions/chrome/src/contentScript/Popup.ts
index 5212a12d9..b3c1aa537 100644
--- a/browser-extensions/chrome/src/contentScript/Popup.ts
+++ b/browser-extensions/chrome/src/contentScript/Popup.ts
@@ -1006,15 +1006,49 @@ function base64Encode(buffer: Uint8Array): string | null {
* Get favicon bytes from page.
*/
async function getFaviconBytes(document: Document): Promise<Uint8Array | null> {
- const favicon = document.querySelector('link[rel="icon"], link[rel="shortcut icon"]') as HTMLLinkElement;
- if (!favicon) return null;
+ // Get all possible favicon links, ordered by preference
+ const faviconLinks = [
+ // Explicit SVG icons
+ ...Array.from(document.querySelectorAll('link[rel="icon"][type="image/svg+xml"]')),
+ // High-res icons
+ ...Array.from(document.querySelectorAll('link[rel="icon"][sizes="192x192"], link[rel="icon"][sizes="128x128"]')),
+ // Apple touch icons (usually high quality)
+ ...Array.from(document.querySelectorAll('link[rel="apple-touch-icon"], link[rel="apple-touch-icon-precomposed"]')),
+ // Standard favicons
+ ...Array.from(document.querySelectorAll('link[rel="icon"], link[rel="shortcut icon"]')),
+ // Fallback to root favicon.ico
+ { href: `${window.location.origin}/favicon.ico` }
+ ] as HTMLLinkElement[];
+
+ // Remove duplicates based on href
+ const uniqueLinks = Array.from(new Map(faviconLinks.map(link => [link.href, link])).values());
+
+ // Try each favicon URL until we find one that works
+ for (const link of uniqueLinks) {
+ try {
+ const response = await fetch(link.href);
+ if (!response.ok) {
+ continue; // Try next link if this one fails
+ }
- try {
- const response = await fetch(favicon.href);
- const arrayBuffer = await response.arrayBuffer();
- return new Uint8Array(arrayBuffer);
- } catch (error) {
- console.error('Error fetching favicon:', error);
- return null;
+ const contentType = response.headers.get('content-type');
+ // Skip if content type indicates it's not an image
+ if (contentType && !contentType.startsWith('image/')) {
+ continue;
+ }
+
+ const arrayBuffer = await response.arrayBuffer();
+ // Skip if the file is too large (> 100KB) or empty
+ if (arrayBuffer.byteLength === 0 || arrayBuffer.byteLength > 102400) {
+ continue;
+ }
+
+ return new Uint8Array(arrayBuffer);
+ } catch (error) {
+ console.debug('Error fetching favicon:', link.href, error);
+ continue; // Try next link if this one fails
+ }
}
+
+ return null; // Return null if no favicon could be downloaded
}