Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(play/export): allow blob: in script-src so optional native modules load

esengine6d8e339d53c9
diff --git a/desktop/electron/buildPlayRealm.ts b/desktop/electron/buildPlayRealm.ts
index 0158a2bf4..781a1d3f4 100644
--- a/desktop/electron/buildPlayRealm.ts
+++ b/desktop/electron/buildPlayRealm.ts
@@ -44,14 +44,16 @@ export const IMPORT_MAP_CSP_HASH = `sha256-${createHash('sha256').update(IMPORT_
// The inline import map is an inline <script>, so CSP must allow it — by HASH
// (not 'unsafe-inline', which would permit any inline script). 'unsafe-eval' is
-// for the emscripten glue; everything else is same-origin estella://.
+// for the emscripten glue; `blob:` in script-src lets an optional native module's
+// glue run as a blob-URL ES module (the loader imports it from a blob); everything
+// else is same-origin estella://.
const PLAY_HTML = `<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta
http-equiv="Content-Security-Policy"
- content="default-src 'self' estella:; script-src 'self' 'unsafe-eval' '${IMPORT_MAP_CSP_HASH}' estella:; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: estella:; font-src 'self' data: estella:; connect-src 'self' data: blob: estella:; worker-src 'self' blob:;"
+ content="default-src 'self' estella:; script-src 'self' 'unsafe-eval' blob: '${IMPORT_MAP_CSP_HASH}' estella:; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: estella:; font-src 'self' data: estella:; connect-src 'self' data: blob: estella:; worker-src 'self' blob:;"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>Estella Play</title>
diff --git a/desktop/electron/exportGame.ts b/desktop/electron/exportGame.ts
index 56452fe75..215f075ef 100644
--- a/desktop/electron/exportGame.ts
+++ b/desktop/electron/exportGame.ts
@@ -49,7 +49,7 @@ function indexHtml(title: string): string {
<meta charset="UTF-8" />
<meta
http-equiv="Content-Security-Policy"
- content="default-src 'self'; script-src 'self' 'unsafe-eval' '${IMPORT_MAP_CSP_HASH}'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' data: blob:; worker-src 'self' blob:;"
+ content="default-src 'self'; script-src 'self' 'unsafe-eval' blob: '${IMPORT_MAP_CSP_HASH}'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' data: blob:; worker-src 'self' blob:;"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>${title}</title>