Skip to content
Advertisement

PDF.js CORS issue

I’m having an issue with PDF.js and CORS configuration.

From domain A I’m loading PDF.js into an iframe with a file as parameter (full path to the server, which will return a pdf document). PDF.js will create a request to the server at domain B with origin: domain A. The server at domain B returns the pdf document with header Access-Control-Allow-Origin: domain A, so far so good.

In my network tab I see the request to the server, which is returning a 200 status OK, but PDF.js is throwing an error Unexpected server response (0) while retrieving PDF <url>.

The question is, what’s going on here, CORS seems to be ok, but I can’t really get any more info from PDF.js what the real reason is the PDF is failing to load. Is there anyone who encountered the same?

Advertisement

Answer

Finally found the problem. My server was not passing the Access-Control-Allow-Credentials: true header to the response, which was needed (xhr request was sent with xhr.withCredential).

CORS is now working properly.

Found the solution at: https://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement