how to process fetch response from an ‘opaque’ type?

Essentially, you cannot access response body from an opaque request.

Adding mode: ‘no-cors’ won’t magically make things work. Browsers by
default block frontend code from accessing resources cross-origin. If
a site sends Access-Control-Allow-Origin in its responses, then
browsers will relax that blocking and allow your code to access the
response.

But if a site doesn’t send the Access-Control-Allow-Origin header in
its responses, then there’s no way your frontend JavaScript code can
directly access responses from that site. In particular, specifying
mode: ‘no-cors’ won’t fix that (in fact it’ll just make things worse).

From https://stackoverflow.com/a/43268098/1666071

And also from fetch documentation:

no-cors — Prevents the method from being anything other than HEAD, GET
or POST, and the headers from being anything other than simple
headers. If any ServiceWorkers intercept these requests, they may not
add or override any headers except for those that are simple headers.
In addition, JavaScript may not access any properties of the resulting
Response.
This ensures that ServiceWorkers do not affect the semantics
of the Web and prevents security and privacy issues arising from
leaking data across domains.

https://developer.mozilla.org/en-US/docs/Web/API/Request/mode

Leave a Comment