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

Cannot view local files in Chrome extension with fetch API #9361

Closed
Rob--W opened this issue Jan 13, 2018 · 5 comments
Closed

Cannot view local files in Chrome extension with fetch API #9361

Rob--W opened this issue Jan 13, 2018 · 5 comments

Comments

@Rob--W
Copy link
Member

Rob--W commented Jan 13, 2018

I have built the latest version of the extension, and tried to open a local PDF file. It won't open, the console shows the following error:

pdf.js:8302 Fetch API cannot load file:///path/to/file.pdf. URL scheme must be "http" or "https" for CORS request.

To fix this, the Chrome extension must only use PDFFetchStream for http(s) schemes, and PDFNetworkStream for other schemes (file, ftp).

@mukulmishra18
Copy link
Contributor

I don't think this is just a chrome specific issue. We can't use fetch to open local file as we do with XHR. So maybe firefox will also give same issue while opening local files?

@Rob--W
Copy link
Member Author

Rob--W commented Jan 13, 2018

@mukulmishra18 When you talk about "Firefox", are you referring to the built-in viewer of Firefox?
(The current Firefox add-on of the project does not work in the latest Firefox (57) because it is not written using the WebExtensions API.)

@mukulmishra18
Copy link
Contributor

When you talk about "Firefox", are you referring to the built-in viewer of Firefox?

Yes, right.

@Rob--W
Copy link
Member Author

Rob--W commented Jan 13, 2018

But the built-in viewer in Firefox doesn't use fetch, does it? The logic responsible for switching to the fetch implementation is disabled for the Firefox build: https://github.com/mozilla/pdf.js/blob/master/src/pdf.js#L32-L41

@mukulmishra18
Copy link
Contributor

Oh! I got it. Sorry.

Rob--W added a commit to Rob--W/pdf.js that referenced this issue Jan 13, 2018
The `fetch` API is only supported for http(s), even in Chrome extensions.
Because of this limitation, we should use the XMLHttpRequest API when the
requested URL is not a http(s) URL.

Fixes mozilla#9361
ltetzlaff pushed a commit to ltetzlaff/pdf.js that referenced this issue Apr 24, 2018
The `fetch` API is only supported for http(s), even in Chrome extensions.
Because of this limitation, we should use the XMLHttpRequest API when the
requested URL is not a http(s) URL.

Fixes mozilla#9361
movsb pushed a commit to movsb/pdf.js that referenced this issue Jul 14, 2018
The `fetch` API is only supported for http(s), even in Chrome extensions.
Because of this limitation, we should use the XMLHttpRequest API when the
requested URL is not a http(s) URL.

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

No branches or pull requests

3 participants