Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pwa-install-handler

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pwa-install-handler

Handle beforeinstallprompt event in your PWA.

  • 2.6.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28K
increased by3.73%
Maintainers
0
Weekly downloads
 
Created
Source

PWA install handler

Handling PWA installation prompt made easier. MDN docs

Installation

npm install pwa-install-handler

Usage

HTML

<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()
})

React

For more information see react-use-pwa-install.

Screencast

UI example

Demo

Check website or code.

Methods

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

Notes

You PWA must meet some requirements to be installable. Without that the canInstall will always be false. The requirements are browser specific. You can read more about it here (MDN) and here (web.dev).

Some browsers don't support custom install button. These will have canInstall always set to false too. For more information check BeforeInstallPromptEvent support.

Keywords

FAQs

Package last updated on 02 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc