2

I am trying to serve PDF files from a bucket on Amazon-S3, using PDF.js in the browser. I have amended the relevant CORS policy in S3. However, I am receiving the following error message in the browser:

PDF.js v2.2.71 (build: 80135378)
Message: file origin does not match viewer's

After a search, I have found several related questions, such as this question here, as this appears to be a relatively common issue. It is fairly obvious therefore that I need to allow Amazon S3 as a host origin. Therefore, I amend my viewer.js file to include the host, like so:

var HOSTED_VIEWER_ORIGINS = ['null', 
'http://mozilla.github.io', 
'https://mozilla.github.io', 
'https://thepdfbucket.s3.eu-west- 
2.amazonaws.com'];

However, if I do a hard reload and inspect sources, I can see that the error is thrown in webpack:///web/app.js:

Uncaught (in promise) Error: file origin does not match viewer's
at validateFileURL (app.js:1482)
at webViewerInitialized (app.js:1541)

If I examine app.js, I can see the HOSTED_VIEWER_ORIGINS array, mapped from the viewer.js file. However, it does not include the amended array, i.e. my addition of https://thepdfbucket.s3.eu-west-2.amazonaws.com.

I cannot get this to work. I believe I probably have a cache issue, however, I have cleared all the browser's cache, I have even built PDF.js again from github and tried to amend the viewer.js file, prior to compilation.

If I have amended the viewer.js file, and app.js is mapped from viewer.js, but it does not reflect the recent changes, my conclusion is that it must be using a cached file. How do I clear this cache, and get app.js to reflect the changes I have made?

I really would appreciate any help here, as I've spent the whole of yesterday on this issue, and I cannot get my head around how this all fits together.

Many Thanks.

Andrew Hardiman
  • 929
  • 1
  • 15
  • 30
  • I am also having the same problem. Are you found any solution for this? – mariappan k Feb 16 '21 at 09:25
  • @mariappank Hi, no I haven't. It is really frustrating me. I cannot find a solution anywhere, I have literally spent whole days on this. I shall keep looking however, and I will let you know if I find a solution. Good luck with it, I hope you find a solution also; if you could let me know if you do, or better still post the answer here for others also, I would be very grateful to you. – Andrew Hardiman Feb 16 '21 at 09:48
  • Hi, the above mentioned link it's working fine for me, I just commented that lines without adding HOSTED_VIEWER_ORIGINS it's working fine https://stackoverflow.com/questions/37378251/load-pdf-on-foreign-url-with-pdf-js – mariappan k Feb 16 '21 at 10:25

1 Answers1

0

I also ran into this problem and investigated. Version of PDF.js: pdfjs-3.3.122

The reason is that when debugging in the browser, the debug information is from viewer.js.map and not the actual working viewer.js source code.

The quickest way to debug is to delete viewer.js.map.

Perhaps the reason for the error is a mis-specified value. That was the case for me.

Incorrect: https://google.com/ Correct: https://google.com

Translated with www.DeepL.com/Translator (free version)