From a2e3dd288485bce130f8beb943a4833a57103225 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Fri, 9 Oct 2026 07:54:07 +1000 Subject: [PATCH] fix(app): make the web app installable as a PWA (#53905) --- packages/app/e2e/service-worker/cache.spec.ts | 43 ++++++++++++++++++- packages/app/index.html | 2 +- packages/app/manifest.json | 12 ++++++ packages/app/vite.icons.test.ts | 10 ++--- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/packages/app/e2e/service-worker/cache.spec.ts b/packages/app/e2e/service-worker/cache.spec.ts index e423c1ecccc..2877b6730d4 100644 --- a/packages/app/e2e/service-worker/cache.spec.ts +++ b/packages/app/e2e/service-worker/cache.spec.ts @@ -1,4 +1,4 @@ -import { expect, test, type Page } from "@playwright/test" +import { chromium, expect, test, type Page } from "@playwright/test" import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises" import { createServer, type ServerResponse } from "node:http" import type { AddressInfo } from "node:net" @@ -453,3 +453,44 @@ test("the production build precaches every deployable file except on-demand Offi await new Promise((resolve, reject) => server.close((error) => (error ? reject(error) : resolve()))) } }) + +test("the production build installs as an app behind an authenticating proxy", async () => { + const directory = new URL("../../dist/", import.meta.url) + + const server = createServer(async (request, response) => { + // Model a reverse proxy that rejects every request without the signed-in user's cookie. + if (!request.headers.cookie?.includes("session=signed-in")) return void response.writeHead(401).end() + const path = new URL(request.url ?? "/", "http://localhost").pathname + const file = extname(path) ? path : "/index.html" + const bytes = await readFile(new URL(`.${file}`, directory)).catch(() => undefined) + + if (!bytes) return void response.writeHead(404).end("Not found") + + // Check the real HTML without starting the app or its service worker. + if (file === "/index.html") + response.writeHead(200, { "content-type": "text/html", "content-security-policy": "script-src 'none'" }) + + response.end(bytes) + }) + + server.listen(0, "127.0.0.1") + await once(server, "listening") + // SAFETY: a server listening on a host and port reports an AddressInfo; only pipe servers report a string. + const address = server.address() as AddressInfo + const url = `http://127.0.0.1:${address.port}` + // Chrome Headless Shell has no install checks and reports no errors for any page, and an incognito context always + // reports one, so check in a persistent Chrome profile. + const context = await chromium.launchPersistentContext("", { channel: "chromium" }) + + try { + await context.addCookies([{ name: "session", value: "signed-in", url }]) + const page = await context.newPage() + await page.goto(url) + const session = await context.newCDPSession(page) + expect((await session.send("Page.getInstallabilityErrors")).installabilityErrors).toEqual([]) + } finally { + await context.close() + server.closeAllConnections() + await new Promise((resolve, reject) => server.close((error) => (error ? reject(error) : resolve()))) + } +}) diff --git a/packages/app/index.html b/packages/app/index.html index e07a15b4121..336cf814efa 100644 --- a/packages/app/index.html +++ b/packages/app/index.html @@ -9,7 +9,7 @@ OpenCode - + diff --git a/packages/app/manifest.json b/packages/app/manifest.json index 427c3adf423..d3dff469c29 100644 --- a/packages/app/manifest.json +++ b/packages/app/manifest.json @@ -5,6 +5,18 @@ "start_url": "/", "scope": "/", "icons": [ + { + "src": "/web-app-manifest-192x192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "any" + }, + { + "src": "/web-app-manifest-512x512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "any" + }, { "src": "/web-app-manifest-192x192.png", "sizes": "192x192", diff --git a/packages/app/vite.icons.test.ts b/packages/app/vite.icons.test.ts index a9a12655e1b..73179adedd2 100644 --- a/packages/app/vite.icons.test.ts +++ b/packages/app/vite.icons.test.ts @@ -29,7 +29,7 @@ test.each(["dev", "beta", "prod", "local"])("bundles %s app icons", async (chann if (file?.type !== "asset") throw new Error(`Missing asset: ${path}`) - return typeof file.source === "string" ? new TextEncoder().encode(file.source) : file.source + return new Uint8Array(Buffer.from(file.source)) }) }) @@ -45,12 +45,12 @@ test.each(["dev", "beta", "prod"])("serves %s app icons", async (channel) => { try { await server.listen() - const address = server.httpServer?.address() + const url = server.resolvedUrls?.local[0] - if (!address || typeof address === "string") throw new Error("Expected an HTTP port") + if (!url) throw new Error("Expected a local URL") await check(channel, async (path) => { - const response = await fetch(`http://127.0.0.1:${address.port}${path}`) + const response = await fetch(new URL(path, url)) expect(response.status).toBe(200) if (path.endsWith(".webmanifest")) expect(response.headers.get("content-type")).toBe("application/manifest+json") @@ -67,7 +67,7 @@ test.each(["dev", "beta", "prod"])("serves %s app icons", async (channel) => { async function check(channel: string, read: (path: string) => Promise) { const html = new TextDecoder().decode(await read("/index.html")) const actual: typeof manifest = JSON.parse(new TextDecoder().decode(await read("/site.webmanifest"))) - expect(actual.icons.every((icon) => icon.purpose === "maskable")).toBe(true) + expect(actual.icons.some((icon) => icon.purpose === "maskable")).toBe(true) expect(actual).toEqual({ ...manifest, icons: manifest.icons.map((icon) => ({ ...icon, src: `/icons/${channel}${icon.src}` })),