beforeinstallprompt doesnt get fired in +layout.svelte
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Discussed in https://github.com/sveltejs/kit/discussions/11550
Originally posted by rheanV January 9, 2024
I have an installable PWA (for sveltekit app). I want to add a custom button for installing the app. I placed my window.addEventListener('beforeinstallprompt', (event) => {
event.preventDefault();
//logic
}); in the onMount of the +layout.svelte file. I have all other configurations correct, meets all installation criteria, and can be installed via the browser download option in the URL bar. However, my "beforeinstallprompt" does not get fired in the +layout.svelte. If I place it in app.html then it is fired but not in +layout.svelte. How should I fix this? What am I missing in my sveltekit app setup?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked discussion and comparing the beforeinstallprompt listener in +layout.svelte's onMount with the working listener in app.html. Trace when each listener is registered relative to the event, then verify the expected behavior in a minimal installable PWA. Done means the issue explains or fixes why the event does not fire from +layout.svelte.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100