Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the install function supposed to do anything? #748

Closed
Dobermensch opened this issue Aug 31, 2024 · 6 comments
Closed

Is the install function supposed to do anything? #748

Dobermensch opened this issue Aug 31, 2024 · 6 comments

Comments

@Dobermensch
Copy link

I'm using this plugin with nuxt. Everything works as expected.

However, I wanted to to create a button for the user to add the PWA to the homescreen so I stumbled upon the $pwa.install method.

I'm calling it on button click but it does nothing.

What is it supposed to do or why isn't it working?

I have client: { installPrompt: true } in pwa object in nuxt.config.

@userquin
Copy link
Member

You should check if showInstallPrompt is true, the install function does nothing if not enabled.

@Dobermensch
Copy link
Author

Dobermensch commented Aug 31, 2024

I checked the value of showInstallPrompt. It is false.

I tried to set it to true and then use the $pwa.install method. Nothing happened.

Here's a snippet of my code:

const addClicked = async () => {
  $pwa.showInstallPrompt = true
  await $pwa.install()
}

How do I use the $pwa.install method?

@userquin
Copy link
Member

That flag must be set by the browser on before install prompt event listener: the sw must installed and activated and the browser must support the feature. You cannot change browser behavior.

You can check the logic here: https://github.com/vite-pwa/nuxt/blob/main/src/runtime/plugins/pwa.client.ts#L86

@Dobermensch
Copy link
Author

So if I understand correctly, since I cannot change the browser behaviour, it means it either works or it doesn't. In my case, since it doesn't work, there's nothing I can do?

@Dobermensch
Copy link
Author

bump

@userquin
Copy link
Member

userquin commented Sep 9, 2024

If the browser doesn't have that feature we cannot do anything, check: https://caniuse.com/?search=beforeinstallprompt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants