Function
Chromium fires beforeinstallprompt as soon as it judges the site
installable, and it never fires it again. That is routinely before React
has hydrated, so a listener added from a component effect misses it: measured
on Android Chrome 149, with the manifest valid, every icon served and the
service worker registered, the install prompt never appeared at all.
Called from instrumentation-client, which Next runs before the application
starts — the earliest hook the framework offers. Several earlier attempts are
worth not repeating: an inline <script> and a <script src> rendered from
the root layout both reached only Next's streamed payload and never executed,
and next/script with beforeInteractive is documented for external src
scripts and emitted nothing for inline content.
Preventing the default is not optional: left alone the browser shows its own promotion alongside ours, and the learner is asked twice by two surfaces.
Start listening for the browser's install offer.