Cross origin requests are denied by chrome when importing mesh from .glb file

When I try to import mesh by BABYLON.SceneLoader.ImportMesh() at localhost using chrome, I get this error

Access to XMLHttpRequest at ‘file:///C:/(my_project_path)/assets/rigged-low-poly-male.glb’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

I think this error is for security purpose and can’t be disabled easily.

So, I want to ask you, How do you usually develop your script? You don’t use localhost and always use remote server? to avoid this cross origin error when importing meshes.

Thank you for reading.
miyabi

using a local webserver should work,
but the file path you’re using is not allowed, javascript can’t read hdd paths.

file:///C:/(my_project_path)/assets/rigged-low-poly-male.glb’

should instead be

/assets/rigged-low-poly-male.glb’

and the folder containing your files should then be the webservers WWW/htdocs/public folder

I’ll do it!
Thank you for fast reply aWeirdo!

1 Like

I made a sample server some time ago, maybe it’ll be useful if you prefer nodejs :slight_smile:
https://doc.babylonjs.com/resources/running_a_local_webserver_for_babylonjs

I used Chrome Web Server.
This is another option that works :grinning:

May the Force be with you!

1 Like

If you’re using VS Code, the Live-Server plugin works great. Just right click the index.html file and choose open with live server

https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer

1 Like

Haha… Didn’t think about that… But, it works… yay…
Thanks for the help

1 Like