Skip to content

fix: offline shortcut icon fallback#134

Merged
prem-k-r merged 3 commits intomainfrom
fix-offline-shortcut-icon
Mar 11, 2026
Merged

fix: offline shortcut icon fallback#134
prem-k-r merged 3 commits intomainfrom
fix-offline-shortcut-icon

Conversation

@prem-k-r
Copy link
Copy Markdown
Owner

@prem-k-r prem-k-r commented Jan 25, 2026

📌 Description

Display offline shortcut icon when offline and not icon in cache

🎨 Visual Changes (Screenshots / Videos)

🔗 Related Issues

✅ Checklist

  • I have read and followed the Contributing Guidelines.
  • My code follows the project's coding style and conventions.
  • I have tested my changes thoroughly to ensure expected behavior.
  • I have verified compatibility across Chrome and Firefox (additional browsers if applicable).
  • I have attached relevant visual evidence (screenshots/videos) if applicable.
  • I have updated the CHANGELOG.md under the appropriate categories with all my changes in this PR.

Overview

This PR refactors shortcut icon rendering in scripts/shortcuts.js to use explicit DOM element creation, centralizes shortcut DOM construction, adds favicon error fallback to a local offline icon, and sets empty alt attributes on dynamically created img elements to avoid noisy screen reader output. The change removes innerHTML-based templating for shortcuts and standardizes DOM-based insertion.

Changes

  • Introduced createShortcutElement(name, url, index) to build shortcut DOM nodes (link, logo container, logo node, and name span); renderShortcut delegates to it.
  • Replaced string-based rendering with DOM node creation across single and bulk rendering paths (settings entries still use innerHTML for the settings panel entry template).
  • getLogoHtml now returns DOM nodes:
    • Returns a GitHub img element for github.com (img.alt = "").
    • Wraps preset SVG strings and returns their first element.
    • Loads favicons via IMG elements with img.alt = "" and an error handler that falls back to ./svgs/offline.svg when loading fails.
  • Added empty alt attributes to all dynamically created img elements for accessibility.
  • Minor flow adjustments to ensure consistent DOM insertion and replacement when rendering or updating shortcuts.

Impact

  • Removes innerHTML usage for main shortcut rendering, improving security and maintainability.
  • Improves offline UX by showing a local offline shortcut icon when favicons are unavailable or the app is offline.
  • Small accessibility improvement: img elements include empty alt attributes to prevent unnecessary screen reader announcements.
  • No exported/public API changes.

Files Modified

  • scripts/shortcuts.js: internal refactor and favicon fallback (+44/−26)

Notes

  • No screenshots or changelog entries were provided.
  • Checklist items in the PR description are present but not marked complete.

Replaces innerHTML-based shortcut rendering with direct DOM manipulation for improved security and maintainability. Updates getLogoHtml to return DOM elements instead of HTML strings, and adjusts all usages accordingly.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 25, 2026

📝 Walkthrough

Walkthrough

Replaced HTML string templating in scripts/shortcuts.js with explicit DOM construction for shortcut elements. getLogoHtml() now returns DOM nodes (images or wrapped SVGs) and rendering functions (createShortcutElement, renderShortcut, renderAllShortcuts) build and append nodes via DOM APIs, with favicon error handlers.

Changes

Cohort / File(s) Summary
DOM-based shortcut rendering
scripts/shortcuts.js
Replaced string-based HTML construction with DOM element creation. Introduced createShortcutElement(name, url, index). getLogoHtml() now returns DOM nodes (GitHub <img>, wrapped preset SVGs, favicon <img> with error handler). renderShortcut and renderAllShortcuts assemble and append nodes using DOM APIs instead of innerHTML/template literals.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes the Description and Related Issues sections, but lacks Visual Changes (screenshots/videos) and all checklist items are unchecked, including critical items like testing and changelog updates. Mark completed checklist items with [x], particularly testing and changelog updates. Provide screenshots or videos demonstrating the offline icon fallback functionality if user-visible changes were made.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: offline shortcut icon fallback' accurately and concisely summarizes the main change in the PR—implementing offline shortcut icon fallback functionality.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@scripts/shortcuts.js`:
- Around line 257-282: Add decorative accessibility attributes to all created
logo elements: for every HTMLImageElement instance (the GitHub shortcut img and
the Google favicon img) set img.alt = "" and img.setAttribute("aria-hidden",
"true"); and for the preset SVG case, after creating wrapper and before
returning wrapper.firstElementChild, if that node is an Element set
wrapper.firstElementChild.setAttribute("aria-hidden", "true") and
wrapper.firstElementChild.setAttribute("focusable", "false") (optional) so
screen readers ignore these decorative logos.

Comment thread scripts/shortcuts.js
Extracted shortcut element creation into a new createShortcutElement function to reduce code duplication and improve maintainability. Updated renderShortcut and shortcut list rendering to use the new helper.
Added empty alt attributes to dynamically created img elements for accessibility and to prevent screen readers from reading unnecessary content.
@prem-k-r prem-k-r added the bugfix Fixes existing bugs or regressions label Jan 27, 2026
@prem-k-r prem-k-r requested a review from itz-rj-here January 27, 2026 17:23
@prem-k-r prem-k-r added the under-review Currently being reviewed. Please wait for feedback. label Jan 27, 2026
@itz-rj-here
Copy link
Copy Markdown
Collaborator

Uhhh I have a trip tomorrow. Well. Let's see if i can check now.

@prem-k-r
Copy link
Copy Markdown
Owner Author

@itz-rj-here waiting for your approval before merging

Copy link
Copy Markdown
Collaborator

@itz-rj-here itz-rj-here left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine with no issues

@itz-rj-here
Copy link
Copy Markdown
Collaborator

image

@prem-k-r prem-k-r removed the under-review Currently being reviewed. Please wait for feedback. label Mar 11, 2026
@prem-k-r
Copy link
Copy Markdown
Owner Author

Works fine with no issues

Thanks! Hopefully you have verified for offline case too.

@prem-k-r prem-k-r merged commit 6cfacd6 into main Mar 11, 2026
3 checks passed
@prem-k-r prem-k-r deleted the fix-offline-shortcut-icon branch March 11, 2026 15:01
@itz-rj-here
Copy link
Copy Markdown
Collaborator

Works fine with no issues

Thanks! Hopefully you have verified for offline case too.

Lol i literally turned off the wifi 💀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes existing bugs or regressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants