haxe
haxe copied to clipboard
Http.requestURL throws exception on JS in 4.x
Test case:
class Test {
static function main() {
var url="https://worldtimeapi.org/api/timezone/America/Los_Angeles";
var result = haxe.Http.requestUrl( url );
trace(result);
}
}
try.haxe: https://try.haxe.org/#095cB22F
This code runs as expected in 3.4.7, but 4.x will result in InvalidAccessError: Failed to set the 'responseType' property on 'XMLHttpRequest': The response type cannot be changed for synchronous requests made from a document. (In JS).
Tested on Chrome and firefox.
As a general note: the async path works fine, so this isn't particularly high priority outside of niche cases where sync requests are preferable
This is an interesting one, little tidbit from a related discussion at WebKit: https://bugs.webkit.org/show_bug.cgi?id=72154#c0
Synchronous XMLHttpRequest in the window (not worker) context is an abomination, but we have to support it for compat reasons. For new response types, though, we don't have this legacy constraint. Mozilla has floated the idea of not supporting any new response types in sync XHR as a way to encourage authors to stick to asynchronous mode and I think it's a great idea.
It's possible to work around this by converting the string to an arraybuffer for this case but I'd worry about mime types and servers sending back unexpected results when it's requesting a string rather than plain bytes https://stackoverflow.com/a/63920556
If someone makes a PR to work around that would be great but I'd be tempted to solve this by @:deprecating this function and instead waiting for async support to land in haxe so you can await haxe.Http.requestUrl( url ) instead