question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular 2/ExpressJS - Refused to get unsafe header “Accept-Ranges”

See original GitHub issue

Using a webapp with NodeJS and ExpressJS as a server (CORS not configured) and Angular 2 for the client. I read here and there that I should enable CORS… I’m not sure where I should enable it and why should I enable CORS. The server is running in localhost.

Configuration:

  • Web browser and its version: Chrome 53.0.2785.143
  • Operating system and its version: Windows 10
  • PDF.js version: 1.5.118 and 1.6.210
  • Is an extension: -

Steps to reproduce the problem:

  1. Make a local server with NodeJS and ExpressJS
  2. Make an Angular 2 app
  3. Use an html input to upload any pdf
  4. Read the pdf with FileReader (with .readAsDataURL)
  5. Try to open the pdf with pdf.js as follow:
PDFJS.disableWorker = true;
PDFJS.getDocument(reader.result).then(function getPdf(pdf) {
        pdf.getPage(1).then(function getPage(page) {

        })
})

What is the expected behavior? (add screenshot) Not getting an error…

What went wrong? (add screenshot) Getting the following error:

pdf.worker.js:43268  -   Refused to get unsafe header "Accept-Ranges"

Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
crebuhcommented, Oct 28, 2016

Any example on how to convert from a URL to an Uint8Array if this is even possible?

@natcohen did you found a solution for the problem?

0reactions
mukulmishra18commented, Nov 12, 2016

@yurydelendik i have implemented extra check for http protocol and it works fine for a simple webapp on my local machine. Please find the PR linked below and point me out if i made some mistake.

https://github.com/mozilla/pdf.js/pull/7803

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refused to get unsafe header "Accept-Ranges" error from pdf ...
You need to set. Access-Control-Allow-Headers : Accept-Ranges ... JS: Render PDF using an ArrayBuffer or Blob instead of URL.
Read more >
Access-Control-Allow-Headers - HTTP - MDN Web Docs
The Access-Control-Allow-Headers response header is used in response to a ... Accept-Post · Accept-Ranges · Access-Control-Allow-Credentials ...
Read more >
OWASP Secure Headers Project
OWASP Secure Headers Project on the main website for The OWASP Foundation. ... ma=2592000; v="46,43" accept-ranges: none vary: Accept-Encoding ...
Read more >
Windows Analysis Report Past DUE statement.xlsx
Source: angular.js.2.dr, String found in binary or memory: http://angularjs. ... Source: material_css_min.css.2.dr, angular.js.2.dr ... Accept-Ranges: bytes
Read more >
WhatsNew 2.0 | Ktor Framework
Ktor 2.0.3 fails with "IOException: Client provided less bytes than content ... HttpClient - -> Accept-Ranges: none 11:33:50.536 [main] INFO ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found