Search code examples
webglgodot4sharedarraybuffer

How to Play a Godot 4 HTML Project Locally?


I have exported the web version of my Godot 4, it is in a folder on my local drive.

Because of the SharedArrayBuffer dependency I can not just double-click in the index.html file. If I do so I see this error:

Error The following features required to run Godot projects on the Web are missing: Cross Origin Isolation - Check web server configuration (send correct headers) SharedArrayBuffer - Check web server configuration (send correct headers)

How can I run it in local?


Solution

  • This python script allows you to open a simple web server running in port 8000:

    #!/usr/bin/env python3
    from http import server # Python 3
    
    class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
            def end_headers(self):
                    self.send_my_headers()
                    server.SimpleHTTPRequestHandler.end_headers(self)
    
            def send_my_headers(self):
                    self.send_header("Access-Control-Allow-Origin", "*")
                    self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
                    self.send_header("Cross-Origin-Opener-Policy", "same-origin")
    
    if __name__ == '__main__':
            server.test(HandlerClass=MyHTTPRequestHandler)
    

    Add this code in a file called server.py in the same folder or your web export (where the index.html is)

    Then go to the folder with the terminal and execute:

    > python3 server.py 
    

    Then in your browser you can write the URL:

    localhost:8000
    

    Source