添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Question

I exported as HTML5 and tried to run it on my browser
has anyone faced this error before ?

worker.js onmessage() captured an uncaught exception: NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://127.0.0.1:4943/index.js' failed to load.
index.worker.js:28 Error: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://127.0.0.1:4943/index.js' failed to load.
worker sent an error! http://127.0.0.1:4943/index.worker.js:185: Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://127.0.0.1:4943/index.js' failed to load
              

I had ~similar issue with Windows 10, Godot 4.0/4.2, Python 3.12, latest Chrome/Brave/Firefox and the local test server script from: https://github.com/godotengine/godot/blob/master/platform/web/serve.py.

I slightly modified the script and now it works for me.

Notice: you don’t tell anything about your environment, so this may or may not work for you. If it doesn’t seem to work right away, be sure to disable cache in browser’s dev tools and (force) refresh the game page.

# Script for running a local test server for Godot web exports
# Slightly modified from: https://github.com/godotengine/godot/blob/master/platform/web/serve.py
# Fixes issue with .js files getting wrong MIME type (Godot 4.2, Windows 10, Python 3.12)
from http.server import HTTPServer, SimpleHTTPRequestHandler, test  # type: ignore
from pathlib import Path
import os
import sys
import argparse
import subprocess
class CORSRequestHandler(SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header("Cross-Origin-Opener-Policy", "same-origin")
        self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
        self.send_header("Access-Control-Allow-Origin", "*")
        super().end_headers()
# IMPORTANT: without this .js files will have incorrect MIME type (text/plain) and the game won't work
CORSRequestHandler.extensions_map = {
    # '.wasm': 'application/wasm',
    ".js": "text/javascript",
def shell_open(url):
    if sys.platform == "win32":
        os.startfile(url)
    else:
        opener = "open" if sys.platform == "darwin" else "xdg-open"
        subprocess.call([opener, url])
def serve(root, port, run_browser):
    os.chdir(root)
    if run_browser:
        # Open the served page in the user's default browser.
        print(
            "Opening the served URL in the default browser (use `--no-browser` or `-n` to disable this)."
        shell_open(f"http://localhost:{port}")
    test(CORSRequestHandler, HTTPServer, port=port)
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-p", "--port", help="port to listen on", default=8060, type=int
    parser.add_argument(
        "-r",
        "--root",
        help="path to serve as root (relative to `platform/web/`)",
        default=".",
        type=Path,
    browser_parser = parser.add_mutually_exclusive_group(required=False)
    browser_parser.add_argument(
        "-n",
        "--no-browser",
        help="don't open default web browser automatically",
        dest="browser",
        action="store_false",
    parser.set_defaults(browser=True)
    args = parser.parse_args()
    # Change to the directory where the script is located,
    # so that the script can be run from any location.
    os.chdir(Path(__file__).resolve().parent)
    serve(args.root, args.port, args.browser)