Skip to content

Commit

Permalink
Add image/ to icon types to prevent errors on websites with invalid…
Browse files Browse the repository at this point in the history
… icon types (fixes #405)
  • Loading branch information
filips123 committed Nov 10, 2023
1 parent 1bd1a8c commit 29789db
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions extension/src/content.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
const isAppleMaskIcon = link => link.getAttribute('rel').toLowerCase().includes('mask-icon')

function getIconType (link) {
const type = link.getAttribute('type')
if (type) return type.includes('/') ? type : `image/${type}`
else return isAppleMaskIcon(link) ? 'image/svg+xml' : null
}

function getIconPurpose (link) {
return isAppleMaskIcon(link) ? 'monochrome' : 'any'
}

// Obtain the initial web app manifest URL
const manifestElement = document.querySelector('link[rel=manifest]')
const manifestUrl = manifestElement ? new URL(manifestElement.getAttribute('href'), document.baseURI) : null
Expand All @@ -24,8 +34,8 @@ browser.runtime.onMessage.addListener((message, _, sendResponse) => {
.filter(link => link.getAttribute('rel')?.toLowerCase().includes('icon'))
.map(link => ({
src: new URL(link.getAttribute('href'), document.baseURI).href,
type: link.getAttribute('type') || (isAppleMaskIcon(link) ? 'image/svg+xml' : null),
purpose: isAppleMaskIcon(link) ? 'monochrome' : 'any',
type: getIconType(link),
purpose: getIconPurpose(link),
sizes: link.getAttribute('sizes') || ''
}))
}
Expand Down

0 comments on commit 29789db

Please sign in to comment.