HTML5 builds and using IHttpRequest

We have our game downloading .uasset from a server and instantiating them. This works great in the editor and non Html5 builds. But when we tried to do an HTML5 build, it doesn’t even appear to be making the request to the server. Is there an issue with using IHttpRequest with html5? Perhaps there is some cross domain file we need to have, much like flash or the unity player? Also, is there a way to output logs to the browser console to better debug?

Here is our code:

    TSharedRef<IHttpRequest> request = (&FHttpModule::Get())->CreateRequest();

	//Set url

	//Set delegates
	request->OnProcessRequestComplete().BindRaw<HttpRequest>(this, &HttpRequest::OnRequestComplete);
	request->OnRequestProgress().BindRaw<HttpRequest>(this, &HttpRequest::OnRequestProgressTick);
	//Start request

Thanks for the help!

A side note, there is a misspelling in a file that is getting created for the html5 build. “jstorage.js” is created, but it is looking for “jStorage.js”. This is only important with case sensitive servers, of course.

What build of UE are you using and what version of Emscripten are you using?

HTML5 is very buggy in UE4.4. I was using 4.4.3 and 1.21.0 and had all sorts of “out of memory” as well as the “jStorage” issue when viewing in Chrome debug console. I updated to 4.5 from Git this morning which now uses Emscripten 1.22 and I’ve had good success with small Basic Code C++ projects. I think it’s safe to say UE is not exactly ready for the Web Browser which is really a bummer since my use case requires web browser as deploying Win64 on clients computers is going to be a huge hassle. I’m hoping the UE HTML5 team can make this experience less annoying very soon.

Just make sure you zip your whole 4.4.1 project up and save to a good place before changing the build. I had a 4.4.3 project and was able to upgrade to 4.5 with no issues at all. Good Luck!

UE 4.4.1, enscripten 1.21.0 (the one required by 4.4.1).

I will update and see how that goes. We have a couple small engine code changes, so hopefully it isn’t too hard to upgrade…

FHTML5PlatformHttp implementation in UE doesn’t exist - I just tested pull request - which implements that and it works well - I will be checking in tomorrow in main. Meanwhile you can pull this request in your branch to make IHttpRequest work.

Thanks - I will fix the case!

re: Browser console logging - look for emscripten_log function in the emscripten SDK. you will see it in UE codebase too.

I do think you will run in cross origin issues if the game is not hosted on the same orgin as the uasset - you might have to send headers which allow cross origin on the server which hosts the ussset if its different from the server which hosts the game .js files.

Yes. IHTTPRequest implementation for HTML5 doesn’t exist right now. And this pull request implements exactly that. It needs to be merged in and I should be able to get it in main (master) soon.

I have done some basic testing and If you pull this request you should be able to use IHTTPReqest without any more changes. That being said - please do look through this PR and see if it serves your requirements - It only implements GET and POST for now.

I think optimizing the builds is something you will find useful. I posted a mini faq - HTML5 Capabilites - Community & Industry Discussion - Unreal Engine Forums - Might help.

So, just to be clear on what is happening, you are saying IHttpRequest doesn’t work with the current engine build, but the change you linked will add IHttpRequest support? So if I pull that, IHttpRequest will work with no additional changes?

All we do is basic stuff right now anyway. We currently request a .uasset file (and images), which get downloaded and put into a TArray binary array. I am guessing it supports that?

I think you are doing a GET - and yes it supports that.

Do you mind post an example code of downloading and saving the .uasset for use in the game?

Combining that code with 4.5, the engine built just fine. But when I tried to package HTML, it threw this error:

Runtime/Online/HTTP/Public/Interfaces/IHttpRequest.h:164:33: note: unimplemented pure virtual method 'GetResponse' in 'FHTML5HttpRequest'
virtual const FHttpResponsePtr GetResponse() const = 0;

Add that missing implementation - Its a simple Getter. e.g Look in CurlHTTP.cpp. That being said, the PR is in master now.

It isn’t that simple. It should be, but it isn’t. You have to first create the UAsset. We have an editor module do that for us. We have it compress it using ZLib, and save it to a uasset. We then download it, and push the uasset TArray < uint8 > through some decompression that saves all the parts of the uasset to the file system. We then instantiate the different pieces and connect them. It is a pain… Unity does have a much better implementation of this.

Ya, I figured that much out. Just thought I would point that out just in case you guys didn’t catch it yet.

Using this with 4.5, I get an error when running the html that was built. Attached is the console output for my Firefox 32bit. link text

I am not sure why logging itself is asserting - Meanwhile you can try removing logging and/or build shipping - I don’t have a re-pro case yet, I will add it as a todo.

Thanks for sharing this Anktikk, we are using it and it works quite well.

However, I would like to comment that setting Content-length" and “Connection” headers in XMLHTTPRequest is usually not allowed, because browsers automatically set it to avoid security issues.

See this post.