Base solution for your next web application
Open Closed

PWA - beforeinstallprompt event not calling #10429


User avatar
0
shedspotter created

Hi, PWA - beforeinstallprompt event not calling. I created tested with separted angular demo app with same angular version (11). In demo, I am getting beforeinstallprompt event successfully but not in asp.net zero project. Please help. what's wrong with asp.net zero.

  • What is your product version? => 10.3.0
  • What is your product type? => Angular
  • What is product framework type? => .net core?

I am using this code in default-layout.component.ts file.

@HostListener('window:beforeinstallprompt', ['$event'])
onbeforeinstallprompt(event: any) {
   console.log('👍', 'beforeinstallprompt', event);
}

12 Answer(s)
  • User Avatar
    0
    musa.demir created

    Hi @shedspotter

    Which browser do you use to test it? It is not supported by all the browsers. You can check if your browser support it in here https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent#browser_compatibility

  • User Avatar
    0
    shedspotter created

    I tested in Google Chrome & Microsoft Edge browsers.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think the problem is not related to app. I'm not experienced with PWAs but adding this code to index.html also doesn't trigger the event. So, I assume, there are some other criteries for this event to trigger as shared in https://stackoverflow.com/a/51248010/6681451

  • User Avatar
    0
    shedspotter created

    We have followed all criteries trigger event.

    • Served over a secure HTTPS connection.
    • Prod build
    • Apple toch icon
    • Your web app must include a web app manifest.
    • The PWA must not already be installed
    • Has registered a service worker with a fetch event handler.

    But, still not getting triggring window:beforeinstallprompt event.

    FYI: I have experienced with Angular PWA. I am able to implement this feature in sample angular 11 app.
    That's why i am not sure about ASP.NET zero theme.
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @shedspotter

    Could you share your ample angular 11 app which includes working window:beforeinstallprompt ?

  • User Avatar
    0
    shedspotter created

    You can fork my this sample app using this link. https://github.com/sujeetjaiswara/ng-pwa-demo

  • User Avatar
    0
    shedspotter created

    Hi, Is there any activity ? It's long time. I am not getting any response.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @shedspotter

    Sorry for the delay. I have tried several times but this event is not triggered for me. Do I have to make any special operation to make it work ?

    I started the app and checked the browser console and there are no logs.

  • User Avatar
    0
    shedspotter created

    Please try this live url: Preview : https://ng-pwa-demo.vercel.app Source Code: https://github.com/sujeetjaiswara/ng-pwa-demo

    PWA Require:

    • https protocol
    • prod publish (ng build --prod)
    • The PWA must not already be installed
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I couldn't see the relavent logs in the browser console. I have tried several screen sizes;

    Are you able to see those logs on your browser console ?

  • User Avatar
    0
    shedspotter created

    Please uninstall if you already installed it. because "beforeinstallprompt" event doesn't fire after the app is installed.

    Uninstall steps:

    1. Open app using desktop shortcut.
    2. then uninstall using brower option:
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @shedspotter

    Thanks, I got it working now. Sorry, I don't have any experience with PWA apps. But, AspNet Zero is not a PWA app by default. Did you convert it to a PWA ? It is expected that this shouldn't work in AspNet Zero by default.

    Sorry for not understanding your question correctly at first place.