-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Should fetching local files always results in a TypeError? #186
Comments
I would be down to treating |
I took a look and it turns out that the native implementations of fetch don't like loading local files either. Chrome:
Firefox (only when I explicitly catch, otherwise it's silent)
|
Closing because the polyfill behaves the same as native browser implementations when loading local files. |
I don't think that's true. I think our polyfill allows loading local files, but native implementations don't. |
The following rejects with an fetch('file:///tmp/test.txt').catch(function(e) { console.log(e) }) Is something else being requested in this issue? I may be misunderstanding it. |
This code works on Safari when test html is loaded via <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch Tests</title>
</head>
<body>
<script>
nativeFetch = window.fetch
window.fetch = undefined
</script>
<script src="../fetch.js"></script>
<script>
fetch('../package.json')
.then(function(res){ return res.text() })
.then(function(text){ console.log('polyfill', text) })
</script>
</body>
</html> |
Even though Safari allows XMLHttpRequest using the But, we might not want to care about this mismatch. "Fixing" the type of the error thrown would be too much work since detecting |
Firefox does allow XMLHttpRequest and Fetch on local files if the page is a local file and and the requested file is in the same directory (or any number of subdirectories) relative to the page. |
Hi there,
When loading local files I bump into
TypeError: Network request failed
right away due to theresponse.status
of local requests being0
, thus getting rejected by fetch's initial status handling.In the README I see the portion on Handling HTTP error statuses, but that would only work if fetch's initial
xhr.onload
didn't reject with a TypeError first.Would it be reasonable to change fetch's initial status handling to something like this so that local fetches could make it through?
For context. I'm working on a project in which the same codebase runs:
status === 0
)Thanks!
The text was updated successfully, but these errors were encountered: