beforeinstallprompt Event Capture Debugger
Test capture of the PWA beforeinstallprompt event, debug custom install
buttons, and generate a safe install prompt snippet.
Live debugger
A real beforeinstallprompt event only fires when the current page
satisfies the browser’s installability criteria. This page may not fire the event
until all production PWA requirements are active.
Introduction
The beforeinstallprompt event allows a website to delay the browser’s
default install prompt and present a custom install button instead. This is useful
when you want control over when and how users are invited to install your progressive
web app.
The event can be confusing because it only fires under specific conditions, and it may not fire at all if the page is already installed, does not meet installability requirements, or runs in a browser that does not support the event.
How it works
This tool listens for real browser events on the current page. It also provides a synthetic event mode so you can test the button and prompt flow without relying on installability.
- Real events are captured with
window.addEventListener("beforeinstallprompt", ...). - The event is stored so it can be triggered later from a user click.
- Synthetic events are clearly labeled and only simulate UI behavior.
- The generated snippet uses standard DOM APIs and does not rely on frameworks.
How to use
- Open this page in a browser that supports
beforeinstallprompt. - Watch the event log for a real event.
- If no real event appears, use Create synthetic event to test the UI flow.
- Click Trigger captured prompt when an event is available.
- Use the snippet generator to create a custom install button for your own site.
- Test the snippet on your own HTTPS-enabled PWA.
Practical example
The generated snippet follows this pattern:
window.addEventListener("beforeinstallprompt", (event) => {
event.preventDefault();
deferredPrompt = event;
button.hidden = false;
});
button.addEventListener("click", async () => {
if (!deferredPrompt) {
return;
}
deferredPrompt.prompt();
await deferredPrompt.userChoice;
deferredPrompt = null;
});
This keeps the prompt deferred until the user chooses to install.
Use cases
- Debugging why a custom install button never appears.
- Testing whether your app captures the install event.
- Prototyping install UX before final PWA requirements are complete.
- Generating clean install button code without a framework.
- Explaining the event flow to teammates or clients.
Best practices
- Always call
event.preventDefault()when storing the event. - Only call
prompt()after a user gesture. - Hide the install button until the event is captured.
- Listen for
appinstalledto update your UI after installation. - Do not repeatedly prompt users after dismissal.
Common mistakes
- Calling
prompt()outside a click handler. - Assuming the event fires on every browser.
- Forgetting HTTPS or service worker requirements.
- Showing the install button before the event exists.
- Treating synthetic tests as proof of real installability.
Limitations
- This tool cannot force a real browser event to fire.
- Synthetic events do not install anything.
- Browser support varies, especially on iOS.
- The tool cannot inspect another website’s page directly.
- Real installability depends on your live site, manifest, service worker, and HTTPS.
Browser compatibility
- Chrome and Edge: Primary support for
beforeinstallprompt. - Firefox: Does not use the same install prompt model.
- Safari: iOS and macOS use Add to Home Screen behavior rather than this event.
FAQ
Does this tool upload anything?
No. All event handling and snippet generation happen locally in your browser.
Why does no real event appear?
The browser may not consider the page installable. Common reasons include missing manifest fields, missing service worker behavior, HTTP instead of HTTPS, the app already being installed, or browser platform limitations.
What is the synthetic event for?
It lets you test the UI state and prompt flow without requiring the browser to fire a real install event. It does not install an app.
Can I use the generated snippet in production?
Yes, after reviewing it and testing it on your own site. It uses standard browser APIs and does not require external libraries.