Cannot import DRACO compressed mesh in a Web Worker

We do some on-the-fly Recast navmesh generation in Web Workers, loading up a NullEngine and importing the mesh on the worker thread.

If the mesh has DRACO compression, SceneLoader.ImportMeshAsync fails with error “document is not defined”.

Traces to tools.GetAbsoluteURL (via DracoCompression constructor) - which tries to call document.createElement to use an anchor element to perform URL manipulation

1 Like

@bghgary could you have a look ?

Interesting, I don’t know if we’ve tried to load models in a web worker before with a null engine. Seems interesting. :slight_smile:

In a web worker, there is no way to get the absolute url from a relative url, so I guess we have to update the code to assume the url is already absolute if document doesn’t exist. Will this work for you? Are you hosting your own Draco compression files and can you point to the absolute url?

As a workaround, maybe try defining something like this before calling ImportMeshAsync to trick it into doing nothing instead of throwing an exception:

var document = { createElement: () => {}; } }

I’ll look into fixing it properly.


Yeah we did that pseudo polyfill to get it working.

I think you could do url resolution that would work in both main thread & worker i like this:

    public static GetAbsoluteUrl(url: string): string {
        return new URL(url, location.href).href;

1 Like

Do you mind filing an issue on GitHub for tracking? Thanks.

Never mind. I fixed it here: Update Tools.GetAbsoluteUrl to work in web workers by bghgary · Pull Request #11429 · BabylonJS/Babylon.js (


This should be resolved now. Please let us know if it works or not.

1 Like