Open chronicadventure opened 5 months ago
+1, did you ever find a solution to this problem @chronicadventure?
you can enable pwa.client.installPrompt
option in pwa nuxt module options, then use $pwa?.showInstallPrompt
to activate the custom install badge/dialog in the ui, when user click on install call $pwa?.install()
If I just want to add a way to manually trigger the install prompt, is that possible? I don't necessarily want to disable the default browser prompt.
Currently I'm trying to add a button that simply calls the prompt, however calling await $pwa?.install();
does absolutely nothing. It doesn't throw an error nor does the prompt appear.
My button:
<UButton @click="installPwa">Installeer</UButton>
installPwa:
async function installPwa() {
console.log("Installing PWA"); // To make sure this function gets called (it does)
await $pwa?.install();
}
My nuxt config:
pwa: {
registerType: "prompt",
manifest: {
// Removed for simplicity (it is valid, I can install the app manually just fine)
},
workbox: {
globPatterns: ["**/*.{js,css,html,wasm}"],
maximumFileSizeToCacheInBytes: 8000000, // 8MB, needed for the wasm files
},
},
I got it working now. It seems that $pwa?.install()
won't work unless you've setclient.installPrompt
to true in your nuxt config. It seems that what I was trying to achieve (have the default install prompt and manually open one) isn't possible. It's either one, not both.
Thanks for your help and time userquin!
You cannot install PWA, you need to intercept the beforeinstallprompt
replacing the callback using the deferredPrompt
from beforeinstallprompt
listener (preventing the browser behavior) , iirc the sw must be also installed and activated.
You can check the logic here: https://github.com/vite-pwa/nuxt/blob/main/src/runtime/plugins/pwa.client.ts#L90-L126
Check this for example: https://github.com/elk-zone/elk/blob/main/components/pwa/PwaInstallPrompt.client.vue
From https://elk.zone
if you're using Nuxt it is fine, otherwise you'll need to use $pwa
instead useNuxtApp().$pwa
(both should work in nuxt)
If you want to customize the browser PWA prompt I cannot help you, check https://whatpwacando.today/ (click on the install pwa button)
I have a component that shows up with an install button. Once the user clicks the install button I'm using
await $pwa.install()
but no install prompt shows up. There are no console errors and there are no manifest errors in the chrome application tab. Here is my manifest file:Here is the vue component: