Texture loading works differently depending on whether offline support is enabled


So in my situation I’m loading the scenes from an external source that requires authentication using basic auth. The way I set this up is I set the CustomRequestHeaders’s Authorization to the wanted value something like this

BABYLON.WebRequest.CustomRequestHeaders.Authorization = `Bearer ${auth}`

Everything has worked fine and dandy, except if I disable offline support or am missing the manifest file (in a way these are essentially the same tho?), it seems like the image files are loaded differently (using HTMLImageElements instead of something else, didn’t trace this all the way through) and I start getting 401 errors on the textures while the scene file still loads ok.

Not sure if this is fully intended that the image loading is done differently when offline support is enabled (and manifest file exists), but it seems to be causing this error.

Hopefully that came out clearly :stuck_out_tongue:
Summa summarum

  • Loading scene’s textures that require HTTP authentication fail if either the manifest file is missing or offline support is disabled

hey! Can you share a repro maybe?

I’ll try and set up an environment for this, the one where it happens is one I can’t unfortunately share.

Had a quick look at the code and seems like the offline provider (which I’m guessing caches it as well?) uses WebRequest (makes sense for the auth to work then) to fetch the image where as with offline supported, like mentioned, tries to get it directly using and Image element.

Nevertheless I’ll come back once I have an environment up to share resources behind auth, but this won’t probably be till Monday.

Hey, I think I managed to repro it now by deploying a dummy server with basic auth enabled to heroku.

I’ve set up a repro in the playground. Initially the loading will probably fail with 401 due to offline support not being enabled so you might have to uncomment the line where offline support is enabled to get the texture to load.

After loading the texture successfully the first time it will fail again if you disable it explicitly.

Let me know if it works and if this helps.

Let me add @sebavan

@v0q I am always getting 401 no matter if the setting is enabled or not :frowning:

@sebavan Hmm it works for me, did the scene (box) load for you?

Do note that there are two commented out lines where the other disables offline support and the other enables it.

ohhh yes uncommenting the second one does the trick, I ll dig in ASAP

1 Like

So as a trick where the API is subject to change you could force image to be loaded from image bitmap as we do not support basic auth on images with engine._features.forceBitmapOverHTMLImageElement = true;

this is basically forcing you to the code path that works no matter the setup in use.


1 Like

Yeah that seems to work for me as well, as it is a 5.0.0 feature, and like you said subject to change still, I’ll try and come up with a solution for myself as I’m still using 4.2.0. But it’s nice to know that such a feature/support is coming.

I’ll mark this as solved from my end. Thanks

1 Like