Your application is almost perfect, but unfortunately, the browser opens correctly, but the Unity game loading bar doesn't progress... I have the same problem with my custom application coded in Python... My only solution is to compile my Python code into an .exe application, which works but is pointless because I just want a launcher... If you want to take a look, here's my script:
import http.server
import socketserver
import threading
import webview
import os
import sys
import mimetypes
PORT = 8000
class UnityHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
path = self.path
if path.endswith(".js.gz"):
self.send_header("Content-Encoding", "gzip")
self.send_header("Content-Type", "application/javascript")
elif path.endswith(".wasm.gz"):
self.send_header("Content-Encoding", "gzip")
self.send_header("Content-Type", "application/wasm")
elif path.endswith(".data.gz"):
self.send_header("Content-Encoding", "gzip")
self.send_header("Content-Type", "application/octet-stream")
elif path.endswith(".js.br"):
self.send_header("Content-Encoding", "br")
self.send_header("Content-Type", "application/javascript")
elif path.endswith(".wasm.br"):
self.send_header("Content-Encoding", "br")
self.send_header("Content-Type", "application/wasm")
elif path.endswith(".data.br"):
self.send_header("Content-Encoding", "br")
self.send_header("Content-Type", "application/octet-stream")
super().end_headers()
def log_message(self, format, *args):
pass
def start_server():
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
else:
base_path = os.path.dirname(__file__)
web_dir = os.path.join(base_path, "web")
os.chdir(web_dir)
with socketserver.TCPServer(("127.0.0.1", PORT), UnityHandler) as httpd:
httpd.serve_forever()
def main():
threading.Thread(target=start_server, daemon=True).start()
webview.create_window(
title="Unity WebGL Game",
url=f"http://127.0.0.1:{PORT}/index.html",
width=1280,
height=720,
resizable=True
)
webview.start()
if __name__ == "__main__":
main()
