Blazor.PWA.MSBuild icon indicating copy to clipboard operation
Blazor.PWA.MSBuild copied to clipboard

Install UI through Blazor rather than default banner?

Open ThatRickGuy opened this issue 5 years ago • 2 comments

Looking through your documentation, it sounds like I should be able to put the install button inside my app, but attempting to call await JSRuntime.InvokeAsync<object>("BlazorPWA.installPWA"); results in a WASM error: Microsoft.JSInterop.JSException: Could not find 'BlazorPWA' in 'window'.

I'm assuming I missed a step in there somewhere. I see the ServiceWorker.js and ServiceWorkerRegister.js, but nothing that contains installPWA.

Any pointers for getting the install to kick off from in Blazor, or is the banner the only option?

ThatRickGuy avatar Jan 06 '20 04:01 ThatRickGuy

you will need some settings in your csproj

<PropertyGroup Label="PWA">
<ServiceWorkerRegisterInstallableType>installable-blazor</ServiceWorkerRegisterInstallableType>
<ServiceWorkerForce>true</ServiceWorkerForce>
</PropertyGroup>

ServiceWorkerRegisterInstallableType tells it you are using Blazor for the install prompt

ServiceWorkerForce just lets it update the generated files - remove it when you have it working

SQL-MisterMagoo avatar Jan 06 '20 06:01 SQL-MisterMagoo

I found this to be a great explanation on how to creat a custom install prompt in Blazor: https://wellsb.com/csharp/aspnet/create-pwa-from-blazor-app/

dknittl avatar Feb 24 '20 13:02 dknittl