Fetch throws exception if happens simultaneously with IMG resource |
|||
Issue description
Chrome Version : 59.0.3071.115
OS Version: OS X 10.12.6
Other browsers tested:
Add OK or FAIL after other browsers where you have tested this issue:
Safari 5: OK
What steps will reproduce the problem?
1. Try to load the following HTML page: (note, img url is exactly the same as fetch url)
<img src="https://source.unsplash.com/240x240/?dog"/>
<script>
(async() => {
let {status} = await fetch('https://source.unsplash.com/240x240/?dog');
console.log(status);
})();
</script>
Expected: "200" is in the devtools console
Actual: fetching throws the following error:
Fetch API cannot load https://images.unsplash.com/photo-1489861984294-6a0427175a27?ixlib=rb-0.3.5…ntropy&cs=tinysrgb&w=240&h=240&fit=crop&s=7f5fdc7a0954ccb935424ccff67f361b. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
(index):5 Uncaught (in promise) TypeError: Failed to fetch
This works fine in Safari. If the IMG url is changed in any way, e.g. to request 200x200 image instead of 240x240, no exception is thrown.
,
Aug 8 2017
I serve the demo page under http://localhost:8080 with python's SimpleHTTPServer
,
Aug 8 2017
Thank you for providing more feedback. Adding requester "yhirano@chromium.org" to the cc list and removing "Needs-Feedback" label. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Aug 8 2017
This happens because the server adds an access-control-allow-origin header only when the request contains an origin header. Since the response doesn't have Vary: origin, a UA can use a cached response without access-control-allow-origin for a request with origin. Closing as WontFix. Please see issue 718352 .
,
Aug 8 2017
OK, so as far as I understand, this is an issue with the server returning incorrect headers. If <img> loads before fetch, the fetch will fail. What I don't understand is why repeating that fetch multiple times eventually resolves? https://jsbin.com/nujihir/2/edit?html,output
,
Aug 9 2017
Because the redirect location changes over time, I guess. |
|||
►
Sign in to add a comment |
|||
Comment 1 by yhirano@chromium.org
, Aug 8 2017