Open rayk opened 5 years ago
@sigmundch @terrylucas – care to take a look?
Hey guys @kevmoo @sigmundch any thoughts on this one. If not a hot item, let me and I will go back to good old XMLHttp..
I'm not sure on this one, it seems like dart:html
doesn't even have a definition for those types - @terrylucas, any clues?
dart:html
has a /*RequestInfo*/
comment on the parameter, is that type missing? Response
need to be declared somewhere? I don't see a class declaration for it?Hey guys (@kevmoo @sigmundch ), should we close this issue or cast it into something else. I think the situation is that there is isn't a complete implementation of fetch in dart:html
.
Thanks in advance.
We did our own thing so we could have one experience for browsers with and without fetch
– IIRC.
We might want to look at this again, especially given our plans WRT browser support - https://groups.google.com/a/dartlang.org/forum/#!topic/announce/x7eDinVT6fM
Still unable to use fetch because of this. I believe the future should return a Response object for further use. I am trying to fetch an image and get the blob data per https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful.
@MichealReed thanks for following up.
This is still not fixed in dart:html
, but we thought you would be able to workaround this by using the callMethod
and getProperty
methods in dart:js_util
.
For example:
import 'dart:js_util' as js_util;
...
main() {
...
var promise = js_util.callMethod(wgs, 'fetch', [...]);
var response = await js_util.promiseToFuture(promise);
if (js_util.getProperty(response, 'ok')) {
js_util.callMethod(response, 'blob', []));
}
}
There is a similar example near the end of @rayk original's message showing what they did for providing more detailed arguments to fetch
.
Would these workarounds unblock your use case?
I did not have any luck with getProperty and callMethod. I did find a different workaround by casting the response object to html.Body, but it would make sense for dart:html to implement the objects per spec.
still broken....
@sgehrman – make sure to 👍 the issue!
Still broken for me. Would love to see fetch return a Response object. Would help immensely for service workers in the browser, especially for chromium-based web extensions where the background script doesnt have direct access to XMLHttp (and I believe support for it was dropped recently).
Environment:
Issue Or Not Yes it's not behaving as described in the spec.
Area
WorkerGlobalScope.instance.fetch(dynamic input, [ Map inti ]) -> Future
Assumptions
...fetch(dynamic input, [ Map init ]) -> Future<Response>
Core Problem Fetch currently is returning an
Interceptor
and Dart does not appear to know about theResponse
type.Reproduction The simplest reproduction I have managed is the following.
Calling the get from a test gives us the following.
Note: the
[object Response]
is from the test:OK this is not a show stopper, we have
JSObject
we should able to fish out the properties and withgetProperty(dynamic o, dynamic property)
fromjs/js_utils
, for example:So I just fish out 'status' and assign it to
status
.Interestingly, with a bit digging, namely:
We are gifted with :
So not very helpful.
Expected Behaviour
Thanks in advance..