I want to allow the user to download and open a PDF file in a new window.
The first request sent to the server receives a status code of 200 but after the file was downloaded the request failed with net :: ERR_HTTP2_PROTOCOL_ERROR 200
After the first request other requests working fine(from cache)
my code:
const openPdf= (url) => {
const headers = new Headers({
...some application headers,
});
return fetch(`www.example.com`, {
method: 'GET',
headers,
credentials: 'include',
}).then(res => res.blob()).then(blob => {
const file = new Blob([blob], {
type: "application/pdf"
});
const fileURL = URL.createObjectURL(file);
window.open(fileURL);
})
}