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(minigame): a WeChat development build reaches the editor, and its replays come back

esengine6ccecc5f3367
diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.ts
index 336cf1316..126a7853a 100644
--- a/pipeline/src/export/exportMiniGame.ts
+++ b/pipeline/src/export/exportMiniGame.ts
@@ -668,6 +668,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
// build must not leave the config pointing at a directory with no index.js.
hasOpenData: !!openDataEntry && errors.length === 0,
openDataRoot: OPEN_DATA_DIR,
+ debugChannel: !!debugChannel,
});
for (const { file, content } of configFiles) {
await writeFile(path.join(absOut, file), content);
diff --git a/pipeline/src/export/miniGameExportProfile.ts b/pipeline/src/export/miniGameExportProfile.ts
index a25d2bee3..cae435967 100644
--- a/pipeline/src/export/miniGameExportProfile.ts
+++ b/pipeline/src/export/miniGameExportProfile.ts
@@ -52,6 +52,9 @@ export interface MiniGameConfigContext {
* from a constant so a project-authored profile emits the same name the
* pipeline actually wrote to. */
openDataRoot: string;
+ /** A development build that dials the editor: the host has to let a socket reach
+ * an address no domain list names. */
+ debugChannel?: boolean;
}
/**
@@ -345,7 +348,12 @@ export const wechatExportProfile: MiniGameExportProfile = {
appid: ctx.appid, // set in Project Settings → Packaging → WeChat (else fill in devtools)
// bigPackageSizeSupport: devtools preview of a >4MB main package (upload
// still enforces the limit — move heavy content to subpackages/ to ship).
- setting: { es6: false, minified: false, bigPackageSizeSupport: true },
+ setting: {
+ es6: false, minified: false, bigPackageSizeSupport: true,
+ // DevTools refuses a socket to an unlisted address ("url not in domain
+ // list"), and the editor is one: a LAN IP no console can register.
+ ...(ctx.debugChannel ? { urlCheck: false } : {}),
+ },
compileType: 'game',
...(ctx.includeSuffixes.length > 0
? { packOptions: { include: ctx.includeSuffixes.map((value) => ({ type: 'suffix', value })) } }
diff --git a/pipeline/tests/export-wechat.test.ts b/pipeline/tests/export-wechat.test.ts
index 5586db2a4..4fb0891bf 100644
--- a/pipeline/tests/export-wechat.test.ts
+++ b/pipeline/tests/export-wechat.test.ts
@@ -278,6 +278,23 @@ describe('exportGame (wechat)', () => {
expect(declaration).toContain('game:updates');
}, 60_000);
+ it('a development build that dials the editor turns off DevTools\' domain check, and only that build', async () => {
+ const cfg = async (debugChannel?: { url: string }) => {
+ const out = path.join(root, debugChannel ? 'dist-wechat-dbg' : 'dist-wechat-nodbg');
+ const res = await exportGame({
+ root, entryScene: 'scenes/main.esscene',
+ hostsDir: 'unused-for-wechat', packagesDir: OFFICIAL_PACKAGES, scriptsEntry: 'src/main.ts',
+ sdkDistDir: path.join(root, '_sdk'), wasmDir: path.join(root, '_wxwasm'), outDir: out,
+ platform: 'wechat', ...(debugChannel ? { debugChannel } : {}),
+ });
+ expect(res.ok).toBe(true);
+ return JSON.parse(readFileSync(path.join(out, 'project.config.json'), 'utf8')).setting;
+ };
+ // Measured in DevTools: without it the socket is refused, "url not in domain list".
+ expect((await cfg({ url: 'ws://192.168.1.5:37420/?token=t' })).urlCheck).toBe(false);
+ expect((await cfg()).urlCheck).toBeUndefined();
+ }, 60_000);
+
it('refuses to substitute a web build for a mini-game one', async () => {
// Serving the web glue would produce a package that builds clean and dies on
// a device — the failure this whole per-platform layout exists to prevent.
diff --git a/sdk/src/render/frameCapture.ts b/sdk/src/render/frameCapture.ts
index 6958b9e57..51f18215b 100644
--- a/sdk/src/render/frameCapture.ts
+++ b/sdk/src/render/frameCapture.ts
@@ -210,7 +210,10 @@ export async function getSnapshotImageData(module: ESEngineModule): Promise<Imag
flipped.set(pixels.subarray(srcOff, srcOff + rowBytes), dstOff);
}
- return new ImageData(flipped, w, h);
+ // A mini-game host has no ImageData; the fields every reader uses are the same.
+ return typeof ImageData === 'function'
+ ? new ImageData(flipped, w, h)
+ : { width: w, height: h, data: flipped, colorSpace: 'srgb' } as ImageData;
}
/** A frame renders before this resolves: a live loop's next animation frame, or a driver's step. */