patrick
patrick

Reputation: 16959

beforeinstallprompt only firing if serviceworker not yet installed

I have the following code that only fires if serviceworker is not yet installed, if I reload the page, it no longer fires, I did not add the code yet to install the PWA (deferredprompt does nothing). I'm using Chrome. I am not declining the prompt, I am not even displaying the prompt at the moment.

let deferredPrompt = null;
    window.addEventListener('beforeinstallprompt', (e) => {
        // Prevent Chrome 67 and earlier from automatically showing the prompt
        e.preventDefault();

        consolelog('=== before install prompt fired ===', 3)
        // Stash the event so it can be triggered later.
        deferredPrompt = e as any;



    });

Upvotes: 1

Views: 1142

Answers (1)

patrick
patrick

Reputation: 16959

The event fires immediately on load (if you have a serviceworker installed), and I was wiring up the event too late, so I missed it.

Upvotes: 1

Related Questions