KhronosGroup/glTF-Validator

Handle reliance on 'window' object as optional

haywirez opened this issue · 2 comments

Right now, the package fails validation when trying to use in node apps or service workers where window is not available:

Uncaught ReferenceError: window is not defined
    at index.js:33:72 in node_modules/gltf-validator/gltf_validator.dart.js
    at index.js:15:50 in __require2
    at index.js:20881:17

Would be nice to address this if possible! My use case involves server-side validation.

Please provide more information about the execution and/or development environment. The published npm package works correctly in server-side apps when invoked with the example code from here.

@lexaknyazev glTF Validator has been working for me in a Node.js environment (example). However, I'm not able to use it in a Web Worker either, getting the same error mentioned above. Here's a simplified example:

https://stackblitz.com/edit/donmccurdy-gltf-validator-worker?file=src/validator-worker.js

The project can be downloaded from there with the small button in the sidebar.

It appears that glTF Validator (or the Dart/JS build process?) is checking for a global variable (which would indicate a Node.js environment) and then depending on window if that is not found. In a Web Worker the global variable is called self, which works in the browser's main thread as well.

For applications like https://gltf.report/, it would be helpful to run validation in a Web Worker, as this can otherwise stall the main thread for a noticeable amount of time while the user is applying changes to a scene.