Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error to load pdf on foreign url with pdf.js #7153

Closed
gildassamuel opened this issue Apr 4, 2016 · 23 comments
Closed

error to load pdf on foreign url with pdf.js #7153

gildassamuel opened this issue Apr 4, 2016 · 23 comments

Comments

@gildassamuel
Copy link

Hello,
I have this error when i want to load pdf from foreign url

Error: file origin does not match viewer's
throw new Error('file origin does not match viewer's');

please help!

@yurydelendik
Copy link
Contributor

It's done on purpose, see #6916. Modify viewer.js to include your hosts origins in the HOSTED_VIEWER_ORIGINS list. Closing as answered.

@gildassamuel
Copy link
Author

Thanks @yurydelendik
But I don't know how this answer help me

@yurydelendik
Copy link
Contributor

But I don't know how this answer help me

Modify viewer.js to include your hosts origins in the HOSTED_VIEWER_ORIGINS list.

@gildassamuel
Copy link
Author

I did it but I do not know how to call my remote pdf file

@yurydelendik
Copy link
Contributor

I did it but I do not know how to call my remote pdf file

Please explain. Also can you provide the following information:

  • what is URL for the viewer including the file parameter?
  • what was changed in the viewer.js code?
  • how was configured CORS headers on the server that host PDF?

@gildassamuel
Copy link
Author

My pdf file is on cloudinary .
And when I put the access in DEFAULT_URL variable , I got error
Error : file viewer 's origin Does not match
throw new Error ( 'file viewer origin Does not match ' s ');

@gildassamuel
Copy link
Author

@gildassamuel
Copy link
Author

I resolve to comment this lines in viewer.js

if (fileOrigin !== viewerOrigin) {
throw new Error('file origin does not match viewer's');
}

@rrecurse
Copy link

rrecurse commented Jul 6, 2016

Don't comment out logic. Use console.log() to see if your fileOrigin and viewerOrigin match. Make sure at least one entry in your HOSTED_VIEWER_ORIGINS object matches the viewerOrigin and the "File origin does not match viewer" error will disapper.

Add this:

console.log('fileOrigin', fileOrigin);
console.log('viewerOrigin', viewerOrigin);

... right above:

if (fileOrigin !== viewerOrigin) {
throw new Error('file origin does not match viewer\'s');
}

I'd bet a nickel you're missing (or have) an added slash at the end of your URL like I did (discovered when console logging those two vars).

Hope this helps someone.

@yaliashkevich
Copy link

It would be nice to be able to configure HOSTED_VIEWER_ORIGINS array with regex/wildchars.

@AndrewRayCode
Copy link

AndrewRayCode commented Sep 28, 2017

In order to allow for non-hard-coded Mozilla domains, I have to modify the source code of a 10k line built file called viewer.js?

@mota57
Copy link

mota57 commented Oct 10, 2017

@gildassamuel you save my day!!

@james4388
Copy link

james4388 commented Nov 15, 2017

The proper fix is open viewer.js and append your file's host to HOSTED_VIEWER_ORIGINS
var HOSTED_VIEWER_ORIGINS = ['null', '.....'];

Don't remove checking code :|

@abrasat
Copy link

abrasat commented Nov 28, 2017

I have the same issue (file origin does not match viewer's) on UWP with local pdf file. What entry exactly must be added to HOSTED_VIEWER_ORIGINS for a local path ?

@cunnpole
Copy link

For anyone else using this within an app I had to add 'file://' to allow local paths to work.

var HOSTED_VIEWER_ORIGINS = [
'null',
'http://mozilla.github.io',
'https://mozilla.github.io',
'file://' //local viewer in app
];

@dominguetigs
Copy link

dominguetigs commented Mar 22, 2019

In my case I was locally coding and I had the same problem and I resolved by adding my local address:

var HOSTED_VIEWER_ORIGINS = [
       'null',
       'http://mozilla.github.io',
       'https://mozilla.github.io',
       'http://localhost:5000'
];

But don`t remove the checking code:

if (fileOrigin !== viewerOrigin) {
       throw new Error('file origin does not match viewer\'s');
}

@AlexanderGalas
Copy link

AlexanderGalas commented Jun 4, 2019

I think adding these 2 lines will be a good solution. Your local ip will be detected automatically (wherever you start your application)

  var LOCAL_AUTO_DETECT_ORIGIN = window.location.origin;

  var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];

  HOSTED_VIEWER_ORIGINS.push(LOCAL_AUTO_DETECT_ORIGIN);

@yarostbaklajana
Copy link

It's done on purpose, see #6916. Modify viewer.js to include your hosts origins in the HOSTED_VIEWER_ORIGINS list. Closing as answered.

helped me

@mdtaslimkhan
Copy link

mdtaslimkhan commented Jan 31, 2020

it a very bad problem, any how hant solved yet.

Access to fetch at 'https://dmain/file.pdf' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

@lk77
Copy link

lk77 commented Mar 25, 2020

Hello,

is there a reason for this ?

it's the browser responsability to care about cors policy, not pdfjs
i think this check should be removed.

i've added return;at the top of the validateFileURL function and it works fine now, i can load pdf from amazon s3.

@ErAz7
Copy link

ErAz7 commented Apr 16, 2020

as @IK77 mentioned, can you please provide a reason for this ?

@ErAz7
Copy link

ErAz7 commented Apr 16, 2020

well, I found this : #6916
@IK77

@peterzhanghui
Copy link

在我的情况下,我在本地编码,遇到了同样的问题,我通过添加本地地址来解决

var HOSTED_VIEWER_ORIGINS = [
       'null',
       'http://mozilla.github.io',
       'https://mozilla.github.io',
       'http://localhost:5000'
];

但是不要删除检查代码

if (fileOrigin !== viewerOrigin) {
       throw new Error('file origin does not match viewer\'s');
}

This is the correct answer to help me solve the problem, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests