-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented suggested changes for PR#3079 #3360
Conversation
This PR is based on Flow-Launcher#3079 Show favicons as Bookmarks icons, originally by @z1nc0r3. Since it seems inactive, I’ve picked it up please let me know if anything is wrong with it or if additional changes need to be made.
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.
See ❌ Event descriptions for more information. If the flagged items are 🤯 false positivesIf items relate to a ...
|
📝 WalkthroughWalkthroughThe changes update the BrowserBookmark plugin by introducing a static dictionary to cache favicon URLs based on domain names. The Changes
Sequence Diagram(s)sequenceDiagram
participant Q as Query Method
participant G as GetFaviconPath Method
participant C as faviconCache
participant S as Google Favicon Service
Q->>G: Call GetFaviconPath(url)
G->>G: Extract domain from URL
alt Domain found in cache
G->>C: Retrieve cached favicon URL
C-->>G: Return favicon URL
else Domain not in cache
G->>S: Construct new favicon URL using Google's service
S-->>G: Return new favicon URL
G->>C: Cache the new favicon URL
end
G-->>Q: Return favicon URL (or default on error)
Suggested labels
Suggested reviewers
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs (1)
109-137
: The GetFaviconPath implementation is well structured but could be more robust.The method effectively extracts domains, caches results, and has good error handling. There are a few potential improvements to consider:
- The method doesn't handle URLs without protocols (e.g., "example.com" instead of "https://example.com")
- Consider using
Uri.TryCreate
instead of a try-catch for better performance when parsing malformed URLs- The cache has no size limit or expiration policy, which could potentially use excess memory over time
private string GetFaviconPath(string url) { try { + // Add protocol if missing + if (!url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && + !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) + { + url = "https://" + url; + } + + // Use TryCreate instead of throwing exceptions + if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) + { + return @"Images\bookmark.png"; + } - var uri = new Uri(url); var domain = uri.Host; if (faviconCache.TryGetValue(domain, out var cachedFaviconUrl)) { return cachedFaviconUrl; } else { var encodedDomain = Uri.EscapeDataString(domain); var faviconUrl = $"https://www.google.com/s2/favicons?domain={encodedDomain}&sz=64"; // Store the favicon URL in the cache faviconCache[domain] = faviconUrl; return faviconUrl; } } catch (Exception ex) { Log.Exception("Main", "Failed to generate favicon URL", ex); // Fallback to default icon return @"Images\bookmark.png"; } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Report (PR)
🔇 Additional comments (3)
Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs (3)
22-22
: Good addition of a favicon cache for performance optimization.Adding a cache for favicon URLs will prevent repeated generation of the same URLs for frequently accessed domains, improving performance.
73-73
: Excellent enhancement replacing hardcoded icons with dynamic favicons.Using the domain's favicon instead of a generic bookmark icon provides a better visual experience for users, making it easier to identify different bookmarks at a glance.
Also applies to: 95-95
122-123
:❓ Verification inconclusive
Consider alternatives to Google's favicon service for better reliability.
While Google's favicon service works well, it's an external dependency that could change or be unavailable. You might want to consider:
- Adding a local caching mechanism for actual favicon images
- Having multiple fallback services if one fails
- Implementing your own favicon retrieval directly from the websites
🌐 Web query:
What are the alternatives to Google's favicon service?
💡 Result:
Here are the top alternatives to Google's Favicon API for retrieving website icons in 2025:
Leading API-Based Solutions
1. FaviconExtractor
- Supports sizes from 16x16 to 512x512, including SVG generation
- Uses DuckDuckGo as a fallback source for reliability
- Simple integration with HTML snippets or API calls:
[1][3][10]<img src="https://faviconextractor.com/api/favicon?url=example.com&size=64">2. Grabicon
- Optimized for speed and customization
- Retrieves high-quality icons via GET requests:
[1][3]curl https://grabicon.com/icon?url=example.com&size=1283. Statvoo's Favicon API
- Offers multiple size parameters (up to 128x128)
- Robust fallback mechanisms and detailed documentation [1][10]
DuckDuckGo/Yandex Direct Links
For quick implementation without API keys:<!-- DuckDuckGo --> <img src="https://icons.duckduckgo.com/ip3/example.com.ico"> <!-- Yandex (supports multiple domains) --> <img src="https://favicon.yandex.net/favicon/google.com/example.com">[3][7][12]
Specialized Tools
Icon Horse
- Combines automatic retrieval with premium features like:
- Fallback icon generation
- Anti-hotlinking protection
- Usage analytics
[3][4]Favicone
- JSON metadata support and smart icon detection
- Checks HTML, manifest files, and traditional .ico locations:
[6]curl https://favicone.com/example.com?json
Self-Hosted Options
favicon-proxy (GitHub)
- Solves CORS issues for browser-based apps
- Deployable via Heroku or Docker:
[12]fetch('https://your-proxy-domain/example.com')
Feature FaviconExtractor Grabicon Icon Horse DuckDuckGo Max Resolution 512px 256px 512px 32px Custom Size Support Yes Yes Yes No Fallback System Multi-source Basic Advanced None SVG Generation Yes No Premium No Cost Free/Open-Source Freemium Premium Free For most projects needing reliability and customization, FaviconExtractor and Icon Horse provide the best balance of features. Developers requiring simple integration often prefer DuckDuckGo's direct URLs, while enterprise applications benefit from Statvoo's API capabilities. Self-hosted solutions like favicon-proxy excel in environments with strict CORS policies[1][3][6][12].
Citations:
- 1: https://ithy.com/article/best-favicon-api-alternatives-6j6f7vrw
- 2: https://www.iconj.com
- 3: https://dev.to/derlin/get-favicons-from-any-website-using-a-hidden-google-api-3p1e
- 4: https://www.producthunt.com/products/free-favicon-maker/alternatives
- 5: https://www.inmotionhosting.com/support/website/how-to-create-a-favicon-for-your-website/
- 6: https://github.com/fransallen/favicone
- 7: https://blog.jim-nielsen.com/2021/displaying-favicons-for-any-domain/
- 8: https://www.hostinger.com/tutorials/how-to-add-favicon-to-website
- 9: https://groups.google.com/a/chromium.org/g/chromium-extensions/c/C136OdBtXpI
- 10: https://ithy.com/article/best-favicon-api-alternatives-4gr9e7vp
- 11: https://www.ionos.com/tools/favicon-generator
- 12: https://github.com/keeweb/favicon-proxy
- 13: https://www.favicon.cc/?action=icon&file_id=19026
- 14: https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs
- 15: https://forum.infinityfree.com/t/how-do-i-add-a-favicon/96710
- 16: https://developers.google.com/search/docs/appearance/favicon-in-search
- 17: https://support.classy.org/s/article/how-to-set-up-domain-masking
- 18: https://help.turbify.com/s/article/SLN29376
Action: Evaluate and implement a more robust favicon retrieval strategy
While your current implementation using Google’s favicon service works, relying solely on it introduces an external dependency that may become unreliable over time. Consider the following enhancements:
- Local Caching: Implement a caching mechanism to store fetched favicons locally, reducing repeated external calls.
- Fallback Services: Integrate additional sources such as:
- FaviconExtractor – supports multiple sizes (up to 512px) and offers fallback via DuckDuckGo.
- Grabicon – optimizes speed and customization.
- DuckDuckGo Direct Endpoints – simple URL-based retrieval.
- Self-Hosted Options: For example, using a favicon-proxy to handle CORS and service stability.
- Direct Retrieval: Optionally, implement logic to extract favicons directly from websites, bypassing external APIs altogether.
These adjustments can improve reliability and reduce the risk of service disruption.
else | ||
{ | ||
var encodedDomain = Uri.EscapeDataString(domain); | ||
var faviconUrl = $"https://www.google.com/s2/favicons?domain={encodedDomain}&sz=64"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since quite a lot of our users are in China, where Google is banned, do we have another option for favicon api? I did a bit research and can't find a reliable one. So what about making it customizable or a toggle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VictoriousRaptor I'm trying to find a way to retrieve bookmark data from local storage.
Even though I don’t know much about programming, I can tell that this approach shouldn’t be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@onesounds If your moving forward with PR #3361 would you like me to close this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ZainGill45 I'll close it. Thanks for the PR.
Continuing in #3361 |
This PR is based on #3079 Show favicons as Bookmarks icons, originally by @z1nc0r3. Since it seems inactive, I’ve picked it up please let me know if anything is wrong with it or if additional changes need to be made.