fix(game): own export chooser modal; PNG option outside in-app webviews only
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 59s
CI / conformance (pull_request) Successful in 9s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m26s

Telegram's native showPopup delivers its callback with no user
activation, so navigator.share (TG iOS) and clipboard writes (TG
Android GCG copy) silently fail from it — the chooser is now always the
app's own modal, keeping the button click's gesture alive for the
delivery APIs.

The data:URL preview modal is dropped: the Android TG/VK long-press
menu mangles data: URLs (dead download, black-screen open, base64
clipboard garbage), so a binary PNG has no working client-side route in
those webviews at all. The image option is withheld there until the
server-rendered signed-URL delivery (Telegram downloadFile /
VKWebAppDownloadFile) lands; the plain web and mobile browsers keep it.

On-device findings by the owner on the test contour (TG iOS, TG
Android, VK Android).
This commit is contained in:
Ilia Denisov
2026-07-02 17:16:05 +02:00
parent a0eacf3011
commit 946420db93
9 changed files with 95 additions and 202 deletions
+23 -26
View File
@@ -1,10 +1,13 @@
import { expect, test, type Page } from './fixtures';
// The finished-game export: the history header's 📤 button opens a format chooser —
// the GCG file or the rendered PNG image (lib/gameimage) — as a native Telegram popup
// inside Telegram and as the app's own modal elsewhere. g3 ("vs Rick") is the seeded
// finished game. Web Share is force-disabled per test so every engine deterministically
// exercises the download (plain browser) or preview (in-app webview) branch.
// The finished-game export: the history header's 📤 button opens the app's own format
// chooser modal — never Telegram's native popup, whose callback runs without user
// activation and so kills navigator.share / clipboard writes (verified on-device).
// The PNG option is offered only outside the in-app WebViews (no working binary
// delivery there until the server-rendered signed-URL path lands); the GCG file is
// always offered. g3 ("vs Rick") is the seeded finished game. Web Share is
// force-disabled per test so both engines deterministically exercise the download
// branch.
async function disableWebShare(page: Page): Promise<void> {
await page.addInitScript(() => {
@@ -27,7 +30,7 @@ test('the export chooser downloads the PNG image on a plain browser', async ({ p
await openFinishedHistory(page);
await page.getByRole('button', { name: 'Export game' }).click();
// The app's own chooser modal (not inside Telegram) offers both formats.
// The app's own chooser modal offers both formats on the plain web.
await expect(page.getByRole('button', { name: 'GCG file' })).toBeVisible();
const download = page.waitForEvent('download');
await page.getByRole('button', { name: 'Image (PNG)' }).click();
@@ -44,13 +47,13 @@ test('the export chooser downloads the GCG file on a plain browser', async ({ pa
expect((await download).suggestedFilename()).toMatch(/^game-.+\.gcg$/);
});
test('inside Telegram the chooser is the native popup and the image lands in the preview modal', async ({
test('inside Telegram the chooser is the app modal and withholds the image option', async ({
page,
}) => {
await disableWebShare(page);
// A Telegram WebApp stub whose showPopup records its params and picks the image option —
// the native-chooser path. With no Web Share in the webview, the image must land in the
// long-press preview modal (the Android Telegram delivery), never a dead <a download>.
// A Telegram WebApp stub with showPopup present: were the chooser still native, it would
// be called — the spy locks the regression (its activation-less callback breaks share and
// clipboard delivery on real devices).
await page.addInitScript(() => {
Object.assign(window, {
Telegram: {
@@ -59,9 +62,9 @@ test('inside Telegram the chooser is the native popup and the image lands in the
initDataUnsafe: {},
ready() {},
expand() {},
showPopup(params: unknown, cb: (id: string) => void) {
(window as unknown as { __popup?: unknown }).__popup = params;
setTimeout(() => cb('image'), 0);
showPopup(_params: unknown, cb: (id: string) => void) {
(window as unknown as { __popupCalled?: boolean }).__popupCalled = true;
setTimeout(() => cb(''), 0);
},
},
},
@@ -74,17 +77,11 @@ test('inside Telegram the chooser is the native popup and the image lands in the
await page.locator('.scoreboard').click();
await page.getByRole('button', { name: 'Export game' }).click();
// The native popup carried both formats plus cancel (≤3 buttons, Bot API 6.2)
const popup = await page.evaluate(
() => (window as unknown as { __popup?: { buttons?: { id?: string; type?: string }[] } }).__popup,
);
expect(popup?.buttons?.map((b) => b.id ?? b.type)).toEqual(['image', 'gcg', 'cancel']);
// …and no in-app chooser modal was mounted.
await expect(page.getByRole('button', { name: 'GCG file' })).toHaveCount(0);
// The preview modal shows the rendered PNG as a data: URL (long-press-saveable) + the hint.
const img = page.locator('.export-preview');
await expect(img).toBeVisible();
expect(await img.getAttribute('src')).toMatch(/^data:image\/png/);
await expect(page.locator('.export-hint')).toBeVisible();
// The app's own modal opened with the GCG option only — no PNG in an in-app WebView
await expect(page.getByRole('button', { name: 'GCG file' })).toBeVisible();
await expect(page.getByRole('button', { name: 'Image (PNG)' })).toHaveCount(0);
// …and the native popup was never used for the chooser.
expect(
await page.evaluate(() => (window as unknown as { __popupCalled?: boolean }).__popupCalled),
).toBeFalsy();
});