# pwa nextjs

> Ship an installable Next.js App Router PWA with a reliable install button, safe service worker caching, and a test harness that asks Chrome itself.

pwa nextjs is a free AI agent skill on Agensi by Maurício Pena, in Frontend & Web Apps. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Maurício Pena](https://www.agensi.io/creators/mauricio-pena)
- Category: [Frontend & Web Apps](https://www.agensi.io/skills/frontend-web-apps)
- Uses: 2
- Version: 1.0
- Last updated: 2026-10-15
- Security: scan passed (2026-10-15); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/pwa-nextjs
- Tags: web-design, nextjs, pwa, typescript, service-worker

## About this skill

Ship an installable PWA on the Next.js App Router in one pass, and find out why the install button does not show up. Chrome has two install paths with different requirements, and most guides describe only one. This skill covers the whole set and checks it against Chrome itself.

### What it does
- **Manifest** through `app/manifest.ts`, including the self-referencing `related_applications` entry that `getInstalledRelatedApps()` needs, and no duplicate link tags.
- **Icons**: 192, 512 and a separate maskable, plus an iOS `apple-icon`. ImageMagick commands included, with a preview step that crops the maskable to the real safe zone.
- **Service worker** with the `fetch` handler that Chrome's automatic prompt requires. Runtime caching is limited to `/_next/static/`, so no API response, avatar or upload from a logged-in user is ever stored.
- **Install prompt capture** with an inline `<script>` in `<head>`. A `useEffect` listener, and `next/script` with `beforeInteractive`, both miss the event when Chrome fires it during hydration.
- **Install button** that does not wait for `beforeinstallprompt` to render and hides itself for people who already installed. Includes a banner that collapses into a small "Get app" chip, for public apps.
- **Middleware and proxy exemptions** (`middleware.ts`, or `proxy.ts` on Next 16) so auth redirects do not swallow `/manifest.webmanifest` and `/sw.js`.
- **iOS metadata** without duplicated meta tags.

### How it works
1. Build all seven pieces together. A PWA that is four-fifths done installs nowhere.
2. Add the capture script to the root layout and mount the registration component.
3. Exempt the manifest, the worker and the offline page from auth, then confirm protected routes still redirect.
4. Run `verify-pwa.mjs` against the production build.

### The verification harness
`verify-pwa.mjs` boots your production build on a spare port, drives headless Chromium and asks Chrome directly through `Page.getInstallabilityErrors`. It runs up to 20 checks: manifest parsing, anonymous access to public files, worker state, duplicate meta tags, the install button shown and hidden, and the offline fallback with the server really down. It exits non-zero on failure, so it works in CI. An optional `PROTECTED_PATH` confirms that auth still redirects.

### Why not just prompt for it
A generic PWA answer explains the manifest and the worker. It rarely mentions that the browser menu and the automatic prompt have different requirements, that an auth middleware silently redirects the manifest, or that the prompt event can fire before your code is listening. This skill also tells the agent how to measure, so it does not draw conclusions from a bot-protection page or from a server that never actually went down.

### Use cases
- Making an existing Next.js App Router app installable.
- Debugging a missing install button or install prompt.
- Adding a safe offline fallback to an app behind login.
- Checking PWA installability in CI.

### Requirements and limits
- Written for the Next.js App Router (15 and 16), verified on Next.js 16.4.0. Not for the Pages Router, Workbox or Vite.
- The harness needs Node, `@playwright/test` and Chromium installed in the project (`npx playwright install chromium`). Linux and macOS only.
- ImageMagick is needed only to generate icons. The commands use `magick` (v7); on v6, replace it with `convert`.
- `getInstalledRelatedApps()` works in Chrome only. Elsewhere the button stays visible, by design.
- Headless Chromium never fires `beforeinstallprompt`, so the harness proves the button renders without it, not the native prompt itself.

### Source
MIT licensed. Canonical source and issues: https://github.com/mpena2099/pwa-nextjs-skill

## Requires

- Node.js
- Playwright

## Known limitations

- Next.js App Router only (15 and 16), verified on Next.js 16.4.0. Not for the Pages Router, Workbox or Vite.
- The verification harness runs on Linux and macOS only, and needs Node, `@playwright/test` and Chromium installed in the project.
- Headless Chromium never fires `beforeinstallprompt`, so the harness proves the install button renders without it, not that the native prompt appears on a real device.
- `getInstalledRelatedApps()` works in Chrome only. In other browsers the install button stays visible even after installing, by design.
- iOS has no install prompt. The button shows "Add to Home Screen" instructions there.
- Icon commands need ImageMagick (`magick` on v7, `convert` on v6).

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the pwa nextjs skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does this skill solve the 'missing install button' problem common in Next.js PWAs?

This skill eliminates common race conditions in the Next.js App Router that prevent install prompts from firing, while providing a safe service worker strategy that avoids caching sensitive user data in authenticated apps.

### Which frameworks and AI agents are compatible with this skill?

The skill is specifically optimized for Next.js App Router projects using TypeScript and is compatible with AI agents capable of file system operations and command execution.

### What specific components are included in the implementation path?

You receive a complete implementation package including the manifest generator, a race-condition-proof capture script, specialized middleware configurations, and an automated verification harness using Playwright.

### Does this tool help with the creation of PWA-compliant icons?

Yes, it includes specialized ImageMagick commands to automatically generate compliant 192x192, 512x512, and maskable icons with the correct safe-zone padding required for iOS and Android.

### Are there any external dependencies required to use all the features?

While the core PWA logic is handled within Next.js, you will need ImageMagick 7 installed for icon generation and Playwright if you wish to run the automated installability tests.

### Why should I use this skill instead of manually prompting an AI for PWA code?

Unlike generic prompts, this skill enforces a 'seven-piece' architecture that addresses specific Next.js hydration issues, ensuring the install prompt works reliably even when browser heuristics are throttled.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
