-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
ie11 file origin does not match viewer's origin #9498
Comments
The URL polyfill in src/shared/compatibility.js overrides the This is therefore not an issue with the default viewer. I also ran <script>delete URL.prototype.origin</script>
<script src=pdf.js></script>
<script>document.write(new URL(location.href).origin)</script> and the test passed (localhost was being printed, instead of Did you load pdf.js before pdf.viewer.js? |
You're right. I tested my use case with pdf.js included and it works perfectly. But.. the online demo https://mozilla.github.io/pdf.js/web/viewer.html include pdf.js and I didn't notice. Mea culpa. |
Still doesn't work on IE11, I have a second problem. Yesterday I tried : But when a parameter is added inside pdf.viewer.js, it doesn't seems to work. if (new URL(e, window.location.href).origin !== t){
console.log('new URL(e, window.location.href).origin', new URL(e, window.location.href).origin);
// result : new URL(e, window.location.href).origin null
console.log('e', e);
// result : e blob:E953C0C2-1552-4A49-9A50-54F7753827B2
console.log('t', t);
// result : t https://myurl
console.log("file origin does not match viewer's")
}
|
That "problem" is not IE-specific. We could allow diff --git a/web/app.js b/web/app.js
index e1891650..fe442c85 100644
--- a/web/app.js
+++ b/web/app.js
@@ -1501,11 +1501,12 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
// Hosted or local viewer, allow for any file locations
return;
}
- let fileOrigin = new URL(file, window.location.href).origin;
+ let inputFileUrl = new URL(file, window.location.href);
// Removing of the following line will not guarantee that the viewer will
// start accepting URLs from foreign origin -- CORS headers on the remote
// server must be properly configured.
- if (fileOrigin !== viewerOrigin) {
+ if (inputFileUrl.origin !== viewerOrigin &&
+ inputFileUrl.protocol !== 'blob:') {
throw new Error('file origin does not match viewer\'s');
}
} catch (ex) { @yurydelendik Is Side note: There are other URLs that can be loaded without CORS, such as |
Ideally, yes. Not sure about IE11 though -- its issue with URL.createObjectURL not generating origin. (BTW, can blob's be cross origin?) We moved HTTP transport to the API side, and if there is a need, we can special case such schemas as |
So actually, this problem is IE-specific.
Firefox, Chrome, Safari, Opera, Edge do match the standards. Internet Explorer does not, it creates URLs that look like
No, |
Thank you for your expertise and the fix ; you are reactive, I really appreciate it :) |
Closing since this is fixed by the PR above. |
Hi,
PDF.JS : latest release (v1.9.426)
Tested on IE11 (11.192.16299.0)
Use case : I get pdf js sources and I do a gulp minified.
When I open my viewer, it works on all Browser except Internet explorer.
I got this error : "file origin does not match viewer's origin"
Inside pdf.viewer.js script (yeah, i read minified js =P), the part
if(new URL(e,window.location.href).origin!==t)throw new Error("file origin does not match viewer's")
Throw an error
because
new URL(window.location.href).origin is undefined
I saw on an issue where you explained that you use a polyfill for javaScript URL object (#9358) but it doesn't seems to work on internet explorer 11.
To help you, I tried this one https://github.com/lifaon74/url-polyfill/blob/master/url-polyfill.js which seems to work great on IE11.
I'll do a temporary work around to avoid this error on my own project (literally skip throw error).
The text was updated successfully, but these errors were encountered: