Skip to content
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

Update getSiteIcon logic #75

Closed
wants to merge 1 commit into from
Closed

Update getSiteIcon logic #75

wants to merge 1 commit into from

Conversation

whymarrh
Copy link
Contributor

@whymarrh whymarrh commented Jul 21, 2020

This change updates the getSiteIcon logic in two ways:

  1. Use img elements for testing resource existence rather than fetch

    The previous implementation of resourceExists was using the same-origin mode for fetch, but that would break when a site used another domain for their icons, static.example.com or images.example.com, for example. There isn't a fetch mode that works here. There's no guarantee that the 2nd origin in question is correctly configured for CORS—so that's cors and same-origin out. navigate doesn't apply and no-cors hides the status and statusText so we can't confirm that.[1]

  2. Handle multiple link elements with rel=icon

    It is very possible and even recommended that there are multiple icons, and if we're going to check that they actually exist, we should fallback to the other images listed.

    e.g.:

    <link rel="icon" type="image/png" href="https://cdn.yourwebsite.com/favicon-16x16.png" sizes="16x16">
    <link rel="icon" type="image/png" href="https://cdn.yourwebsite.com/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="https://cdn.yourwebsite.com/favicon-96x96.png" sizes="96x96">
    

There is a subtle functionality change here in that the element matching head > link[rel="shortcut icon"] will be checked first, but that isn't important, nor should it be.

This change updates the `getSiteIcon` logic in two main ways:

1. Use `img` elements for testing resource existence rather than `fetch`

    The previous implementation of `resourceExists` was using the `same-origin`
    mode for fetch but that would break when a site used another domain for
    their icons, `static.example.com` or `images.example.com`, for example. There
    isn't a fetch mode that works here. There's no guarantee that the 2nd origin
    in question is correctly configured for CORS—so that's `cors` and
    `same-origin` out. `navigate` isn't applicable here. and `no-cors` hides the
    `status` and `statusText` so we can't confirm that. [1]

2. Handle multiple link elements with `rel=icon`

    It is very possible and even recommended that there are multiple icons, and
    if we're going to check that they actually exist, we should fallback to the
    other images listed.

    e.g.:

       <link rel="icon" type="image/png" href="https://cdn.yourwebsite.com/favicon-16x16.png" sizes="16x16">
       <link rel="icon" type="image/png" href="https://cdn.yourwebsite.com/favicon-32x32.png" sizes="32x32">
       <link rel="icon" type="image/png" href="https://cdn.yourwebsite.com/favicon-96x96.png" sizes="96x96">

There is a subtle functionality change here in that the element
matching `head > link[rel="shortcut icon"]` will be checked first, but that
isn't important, nor should it be.

  [1]:https://fetch.spec.whatwg.org/#concept-request-mode
@whymarrh
Copy link
Contributor Author

Merged #76 and #78 instead

@whymarrh whymarrh closed this Jul 21, 2020
@whymarrh whymarrh deleted the fix-site-metadata branch July 21, 2020 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant