-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
Use img
elements for testing resource existence rather than fetch
#78
Conversation
4cef2bf
to
f353851
Compare
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.
I think this makes a lot of sense!
To follow up on questions in #77, I'm not positive why the same-origin
restriction was added in the first place, likely out of an (over?)abundance of caution.
The whole point of resourceExists
is to only send an href
to the extension that actually points to something we can use. We have a similar fallback mechanism in the extension for when these links inevitably go stale, but I don't see any harm in doing some basic validation in the page so as to avoid sending complete garbage to the extension/mobile.
All of this said, let's rename resourceExists
to imageExists
in light of its new, more specific use?
f353851
to
5c09a72
Compare
The previous implementation of `resourceExists` was using the `same-origin` mode for fetch but that breaks when a site uses another domain for their icons— `static.example.com` or `images.example.com`, for example. There isn't a fetch mode that works here: [1] - `same-origin`: doesn't work for the reasons described - `cors`: there's no guarantee that the 2nd origin in question is correctly configured for CORS—a quick check on two sites confirmed this - `navigate`: isn't applicable here - `no-cors` hides the `status` and `statusText` so we can't use those With that, this loads the resources as images and tests whether that works. This will essentially be a `no-cors` request but with the status exposed through `onload`+`onerror`, which will suffice for our use case. [1]:https://fetch.spec.whatwg.org/#concept-request-mode
5c09a72
to
00f2a39
Compare
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.
:guy_fieri_chef_kiss:
Closes #77
The previous implementation of
resourceExists
was using thesame-origin
mode for fetch but that breaks when a site uses another domain for their icons—static.example.com
,assets.example.com
, orimages.example.com
, for example.There isn't a fetch mode that works here:[1]
same-origin
doesn't work for the reasons describedcors
there's no guarantee that the 2nd origin in question is correctly configured for CORS—a quick check on two sites confirmed thisnavigate
isn't applicable hereno-cors
hides thestatus
andstatusText
so we can't use thoseWith that, this PR loads the resources as images and tests whether that works. This will essentially be a
no-cors
request but with the status exposed throughonload
+onerror
, which will suffice for our use case.