gpt4 book ai didi

python - Chrome 中的嵌入器不允许生成 Wasm 代码

转载 作者:行者123 更新时间:2023-12-04 17:26:43 28 4
gpt4 key购买 nike

我将在 Unity 中构建的 WebGL 游戏嵌入到我在 Flask 中构建的 Web 应用程序中。我在后端使用 CSP 用于安全目的,但即使在包含 wasm-eval 之后也是如此。我的 CSP 中的指令,我只在 Chrome 中继续收到这些错误:

UnityLoader.js:4 failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder

printErr @ UnityLoader.js:4
UnityLoader.js:4 CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
at blob:http://localhost:5000/510c750f-1181-4d80-926f-dc71e527c16b:8:31195

Uncaught (in promise) abort({}) at Error
at jsStackTrace (blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:22295)
at Object.stackTrace (blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:22466)
at Object.onAbort (http://localhost:5000/static/desert_run/Build/UnityLoader.js:4:11118)
at abort (blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:446869)
at blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:31316
我不确定我需要修复什么,以及 unsafe-eval script-src 的指令也不起作用。这是我的 CSP 和我在 _init_.py 中用于在后端实现它的代码:
from flask import Flask, url_for, current_app
from flask_talisman import Talisman

csp = {
"default-src": [
"'self'",
'https://www.youtube.com',
'blob:',
'wasm-eval'
],
'script-src': [ "'self'",
'blob:',
'wasm-eval',
'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js',
'https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js',
'https://ajax.cloudflare.com/cdn-cgi/scripts/7089c43e/cloudflare-static/rocket-loader.min.js']
}
talisman = Talisman()
app = Flask(__name__)

def create_app():
talisman.init_app(app)
talisman.content_security_policy = csp
talisman.content_security_policy_report_uri = "/csp_error_handling"
return app

最佳答案

我遇到了类似的问题,但可以通过添加 'unsafe-eval' 来修复它。进script-src列表,因此您应该执行以下操作:

csp = {
"default-src": [...],
"script-src": [
"'self'",
"blob:",
"'unsafe-eval'",
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js",
...
],
}
以下是我用来为 Unity WebGL 提供服务的所有指令和值我服务器上的游戏:
csp = {
"default": ["'self'"],
"img-src": ["'self'"],
"style-src": ["'self'"],
"script-src": ["'self'", "blob:", "'unsafe-inline'", "'unsafe-eval'"],
"worker-src": ["'self'", "blob:"],
}

关于python - Chrome 中的嵌入器不允许生成 Wasm 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62763453/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com