JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 29124
  • Score
    100M100P100Q155382F
  • License ISC

Handle beforeinstallprompt event in your PWA.

Package Exports

  • pwa-install-handler

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pwa-install-handler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PWA install handler

Handling PWA installation prompt made easier. MDN docs

Instalation

npm install --save-dev pwa-install-handler

Usage

HTML

<button role="button" id="installButton" style="display: none;">
    Install
</button>

JavaScript

import pwaInstallHandler from 'pwa-install-handler'

const $button = document.querySelector('#installButton')

pwaInstallHandler.addListener((canInstall) => {
    $button.style.display = canInstall ? 'inline-block' : 'none'
})

$button.addEventListener('click', () => {
    pwaInstallHandler.install().then((isInstalled) => {
        console.log(
            isInstalled
                ? 'User accepted installation prompt'
                : 'User rejected installation prompt'
        )
    })
})

Screencast

UI example

Methods

pwaInstallHandler.install: () => Promise<boolean>
pwaInstallHandler.addListener: (
    callback: (canInstall: boolean) => void,
    install?: () => Promise<boolean>
) => void
pwaInstallHandler.removeListener: (
    callback: (canInstall: boolean) => void,
    install?: () => Promise<boolean>
) => void
pwaInstallHandler.canInstall: () => boolean
pwaInstallHandler.getEvent: () => BeforeInstallPromptEvent | null