-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
wasm: Unhandled Promise Rejection: Error: url parse
on cross-origin no-cors
response
#1401
Comments
I'm not familiar enough with the |
@seanmonstar Since I'm not a web dev, I haven't run into this before. Here's a quick reproduction from JS to show the response:
This will log a value that looks like Response {
body: null,
bodyUsed: false,
headers: Headers {append: function, delete: function, get: function, has: function, set: function, …},
ok: false,
redirected: false,
status: 0,
statusText: "",
type: "opaque",
url: "",
} Looking up the details of Ultimately, the reason why this happens doesn't matter, just the fact that it's a legitimate state does. The quick fix is to change the The downside of course is that a no-cors request to a different origin now always returns an error. Granted, we don't actually know what the status of the request is, but ideally we'd have a structured representation of this fact. I don't see how we can get that though without making no-cors requests distinct at the type level. This could be done by adding typestate to |
having this issue on the reqwest_wasm version here https://github.com/samdenty/reqwest . any workaround? |
any updates on this? i use reqwest in my library and this issue makes it not work in wasm |
now using this version of reqwest and not reqwest_wasm and still having the same issue. |
@lilyball Won't this mean that no-cors requests still throw an error? The goal should be skipping url parsing or whatever is causing the error and still returning whatever the response was. Do you have a suggestion for how to do that ? |
@duckfromdiscord The response is fully opaque, so the only useful information to be gained here is "this response is opaque". I do agree that doing this as part of the error sucks, but putting it into Making it as a separate error with a simple test function, and fully documenting this (especially on Also FWIW, I've moved on from the project that motivated filing this issue and so I don't have anything invested in it anymore. I would like to see it fixed but the manner in which it's fixed won't affect me. |
+1 we're also running into this issue Repro in #1401 (comment) seems pretty straightforward to me. Primary question for me is how to expose this in the |
Bump, any work around for this found? Blocking any use of this in a WASM context. |
My information and knowledge is the same. I welcome a fix to the issue. I don't use WASM myself, so it would require someone else to investigate and find a flexible fix. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I'm not sure that's a fully accurate description. reqwest isn't specifically designed for a multi-threaded runtime. It's designed for any async runtime. The JavaScript runtime happens to fit quite well. So reqwest is able to wrap fetch. This specific issue is not about whether reqwest should be using fetch. It's about an exception that is thrown under certain conditions. Let's keep it focused to that. |
I've added this to my list of issues to keep an eye on, if I ever find time, but in the meantime, here's my mental sketch on the sequence of work that needs to happen:
|
Also, speaking as a user of |
@seanmonstar this isn't fixable on WASM side. It's a browser policy. {
"mode": "no-cors"
} seems kinda useless for browsers. I fixed my request by removing no-cors and by setting up the cors header on the http server. Reference: https://tpiros.dev/blog/what-is-an-opaque-response/ |
If I issue a request to another origin that does not understand CORS, and I set
fetch_mode_no_cors()
, I end up with the following in my console:It looks like the issue is the line
I can see in my browser console that the request was fine. Attempting to reproduce this request in JavaScript using the
fetch()
API shows that I get an opaque response whose url is an empty string.Failure to parse the URL should not throw an unhandled exception. It's hard to debug (and it leaks the stack), and this is an error that will always happen for opaque filtered responses.
Additional Context
I am not a web dev. I know very little about CORS. The fact that I get back an opaque filtered request is something I learned while trying to debug this.
target:
wasm32-unknown-unknown
The text was updated successfully, but these errors were encountered: