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!
It's done on purpose, see #6916. Modify viewer.js to include your hosts origins in the HOSTED_VIEWER_ORIGINS list. Closing as answered.
Thanks @yurydelendik
But I don't know how this answer help me
But I don't know how this answer help me
Modify viewer.js to include your hosts origins in the HOSTED_VIEWER_ORIGINS list.
I did it but I do not know how to call my remote pdf file
I did it but I do not know how to call my remote pdf file
Please explain. Also can you provide the following information:
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 ');
exemple of my url pdf http://res.cloudinary.com/image/upload/v1459791656/my_file.pdf
I resolve to comment this lines in viewer.js
if (fileOrigin !== viewerOrigin) {
throw new Error('file origin does not match viewer\'s');
}
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.
It would be nice to be able to configure HOSTED_VIEWER_ORIGINS array with regex/wildchars.
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?
@gildassamuel you save my day!!
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 :|
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 ?
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
];
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');
}
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);
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
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.
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.
as @IK77 mentioned, can you please provide a reason for this ?
well, I found this : https://github.com/mozilla/pdf.js/pull/6916
@IK77
Most helpful comment
I resolve to comment this lines in viewer.js
if (fileOrigin !== viewerOrigin) {
throw new Error('file origin does not match viewer\'s');
}