How can I use beforeinstallprompt event for Google Chrome for PWA apps? Could you please provide any sample file to call this event. Regards, Ravi

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

How can I use beforeinstallprompt event for Google Chrome for PWA apps?

Could you please provide any sample file to call this event.

Regards

Hi,

beforeinstallprompt will only be fired when some conditions are true :

  • The PWA must not already be installed
  • Meets a user engagement heuristic (the user must have at least 30s interaction with your web app.
  • Your web app must include a web app manifest.
  • Your web app must be served over a secure HTTPS connection.
  • Has registered a service worker with a fetch event handler

a web app manifest includes:

  • short_name or name
  • icons including a 192px and a 512px version
  • start_url

below is the sample which might be helpful for you.

{

"background_color": "purple",

"description": "lojaportaldotricot TESTE",

"display": "standalone",

"icons": [

{

"src": "/componentes/serviceWorker/fox-icon.png",

"sizes": "192x192",

"type": "image/png"

}

],

"name": "lojaportaldotricot",

"short_name": "lojaportaldotricot",

"start_url": "/dashboard"

}

you can also refer to the below link for more information.

https://love2dev.com/blog/beforeinstallprompt/

Thank you

Hi Srujan,

Thanks for update.

I have few queries.

Is "beforeinstallprompt" event automatically trigger if the given all condition is true ?

Or do we need to call this beforeinstallprompt function manually.

If we need to call it manually could you please provide us sample for that.

Kindly let me know.

Regards,

Ravi Khandelwal