Trying to make a cross-origing fetch request with the no-cors mode I found out it is not possible in this case to send any data to the server as a body:
const url = 'http://cross-origin-example.com/post';
const request = new Request(url, {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'text/plain',
},
body: 'boo',
});
fetch(url, request).then((response) => console.log(response));
In Chrome, such a request will not be sent at all throwing the following error:
Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': If request is made from ReadableStream, mode should be"same-origin" or "cors"
Firefox make the request reach the server but with the body missing.
I know when using the no-cors mode the JS code gets an opaque response, which effectively conceals the result of fetching. However, on what basis the browsers do not allow attach body in this case? Is it standardized behavior (in fact, I failed to find such a restriction somewhere in the fetch spec) or just a browser extra limitation?