Skip to the code

A web app manifest to install the shop

Leaf and Kettle wants customers to add the shop to their phone's home screen and open it like an app. Browsers need a web app manifest for that. Write app/manifest.ts: its default export returns a MetadataRoute.Manifest object, which Next.js serves as JSON at /manifest.webmanifest.

Take the app's name, short_name, description, theme_color, and background_color from brand in @/lib/brand.

The installed app opens on the home page, in a window of its own: display: "standalone", scope: "/", and start_url: "/?source=pwa", so the shop's analytics can tell visits from the app. Set id to "/" as well.

List every icon in appIcons, in order, each as { src, sizes, type, purpose }: src is its file, sizes is its size twice, like "192x192", type is "image/png", and purpose is "maskable" for a maskable icon and "any" for the others.

GET /manifest.webmanifest
{
  "id": "/",
  "name": "Leaf and Kettle",
  "short_name": "Leaf&Kettle",
  "start_url": "/?source=pwa",
  "display": "standalone",
  ...
  "icons": [
    { "src": "/icons/kettle-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
    ...
  ]
}

The app's other files

lib/brand.ts, read-only. Import it as @/lib/brand.

/** Leaf and Kettle's name and colors, as the designers chose them. */
export const brand = {
  name: "Leaf and Kettle",
  /** For the home screen, which has room for about 12 characters under an icon. */
  shortName: "Leaf&Kettle",
  description: "Loose-leaf teas, brewing guides, and a kettle that's always on.",
  /** For the title bar and the phone's status bar. */
  themeColor: "#2f5d3a",
  /** For the splash screen, while the app starts. */
  backgroundColor: "#fbf8f1",
};
 
/**
 * The app icons in public/icons, all PNG files. A maskable icon keeps its kettle inside the middle 80%,
 * so a phone can crop it to a circle or a rounded square without cutting any of it off.
 */
export const appIcons = [
  { file: "/icons/kettle-192.png", size: 192, maskable: false },
  { file: "/icons/kettle-512.png", size: 512, maskable: false },
  { file: "/icons/kettle-maskable-512.png", size: 512, maskable: true },
];

What the tests check

  1. names the app with the brand's name, short name, and description
    const manifest = await Manifest();
    expect(manifest.name).toBe("Leaf and Kettle");
    expect(manifest.short_name).toBe("Leaf&Kettle");
    expect(manifest.description).toBe("Loose-leaf teas, brewing guides, and a kettle that's always on.");
    
  2. opens in a window of its own, on the home page, tagged for analytics
    const manifest = await Manifest();
    expect(manifest.display).toBe("standalone");
    expect(manifest.scope).toBe("/");
    expect(manifest.start_url).toBe("/?source=pwa");
    
  3. keeps / as the app's id, whatever start_url says
    expect((await Manifest()).id).toBe("/");
    
  4. colors the title bar and the splash screen with the brand's colors
    const manifest = await Manifest();
    expect(manifest.theme_color).toBe("#2f5d3a");
    expect(manifest.background_color).toBe("#fbf8f1");
    
  5. lists every icon with its size, type, and purpose
    expect((await Manifest()).icons).toEqual([
      { src: "/icons/kettle-192.png", sizes: "192x192", type: "image/png", purpose: "any" },
      { src: "/icons/kettle-512.png", sizes: "512x512", type: "image/png", purpose: "any" },
      { src: "/icons/kettle-maskable-512.png", sizes: "512x512", type: "image/png", purpose: "maskable" },
    ]);
    

Learn more

app/manifest.tsSaved in this browser

Run tests runs every test on your code, here in your browser. The problem is solved when they all pass.

Ctrl + Enter runs the tests (⌘ + Enter on a Mac).