0.3.9 • Published 1 month ago

@khmyznikov/pwa-install v0.3.9

Weekly downloads
1
License
MIT
Repository
github
Last release
1 month ago

Published on NPM npm

\<pwa-install>

New to PWAs? Unsure how to create a Web App? Check out these resources for a quick start: PWA Intro, PWA Starter, PWA Builder

Installation dialog for Progressive Web Application (PWA) and Add to Home Screen/Dock dialog for Web Apps. This offers an enhanced user experience and addresses the absence of native dialogs in certain browsers. 20kB brotli compressed bundle. Translation/localization is supported.

Use it as Web Component with any modern framework. No polyfill is required. React polyfill. Angular sample.

Demo

Gallery

iOS default      Install instructionApp gallery       
iOS example defaultiOS example install instructioniOS example gallery
MacOS 14+ (Sonoma)Install instruction
sonoma_dialog-minsonoma-dialog-open-min
iPadOS
iPadOS example light
AndroidApp gallery  Light theme  
Android example defaultAndroid example galleryAndroid example white
Chrome App Gallery  
Chrome example defaultChrome example gallery

Install

npm i @khmyznikov/pwa-install

Alternatively, you can use unpkg or esm.sh.

Import

import '@khmyznikov/pwa-install';

Use

<pwa-install></pwa-install>

React polyfill

Demo

Supported params

<pwa-install
  manual-apple="true"
  manual-chrome="true"
  disable-chrome="true"
  disable-close="true"

  install-description="Custom call to install text"
  disable-install-description="true"
  disable-screenshots="true"

  manifest-url="/manifest.json"
  name="PWA"
  description="Progressive web application"         
  icon="/icon.png">
</pwa-install>
<!-- 
  manual-apple/chrome params means you want to show the Dialog manually by showDialog().
  disable-chrome param is for completely disabling custom logic and interception for Chominum browsers (will work built-in browser logic).
--->

Make a good manifest file and don't use name/descr/icon params. Boolean attributes needs to be removed to act like "false"

Supported events

  • pwa-install-success-event
  • pwa-install-fail-event
  • pwa-install-available-event
  • pwa-user-choice-result-event
  • pwa-install-how-to-event
  • pwa-install-gallery-event
<script type="text/javascript">
  var pwaInstall = document.getElementsByTagName('pwa-install')[0];

  pwaInstall.addEventListener('pwa-install-success-event', (event) => {console.log(event.detail.message)});
</script>

⚠️ success/fail/choice events is Chromium only, iOS don't have them.

Supported properties (readonly)

  • userChoiceResult: string;
  • isDialogHidden: boolean
  • isInstallAvailable: boolean
  • isAppleMobilePlatform: boolean
  • isAppleDesktopPlatform: boolean
  • isUnderStandaloneMode: boolean
  • isRelatedAppsInstalled: boolean
<script type="text/javascript">
  var pwaInstall = document.getElementsByTagName('pwa-install')[0];

  console.log(pwaInstall.isUnderStandaloneMode);
</script>

Supported methods

  • install
  • hideDialog
  • showDialog
  • getInstalledRelatedApps: async
<script type="text/javascript">
  var pwaInstall = document.getElementsByTagName('pwa-install')[0];

  pwaInstall.install();
</script>

getInstalledRelatedApps is Chromium only, always empty on iOS.

Async mode

If you need to target Chromium browsers but you want to postpone component mounting, you can do it! But, need to capture beforeinstallprompt manually and pass it to the component's externalPromptEvent property(not attribute).

// capture event asap, better right in index.html script tag
window.addEventListener('beforeinstallprompt', (e) => {
  e.preventDefault();
  e.stopPropagation();
  e.stopImmediatePropagation();

  // save it somewhere
  window.promptEvent = e;
});

// later render the component on demand and pass event
document.getElementById("pwa-install").externalPromptEvent = window.promptEvent;

Supported localization

Translations available:

  • EN
  • RU
  • TR
  • DE
  • ES
  • NL
  • EL
  • FR
  • SR
  • PL
  • ZH/ZH-CN
  • IT
  • UK
  • CS
  • NO
  • PT
  • JA
  • SV
  • KO

Language should change automatically based on browser settings. Please create the pull-request if you want to help with translation to your language. It's an easy process.

Contribution Guidelines

ROADMAP

  • samsung mobile support
  • mozilla mobile support
  • manual theme

0.3.9

1 month ago

0.3.8

2 months ago

0.3.7

2 months ago

0.3.6

3 months ago

0.3.5

3 months ago

0.3.4

4 months ago

0.3.2

5 months ago

0.3.3

5 months ago

0.3.1

5 months ago

0.3.0

6 months ago

0.2.8

6 months ago

0.2.7

8 months ago

0.2.6

11 months ago

0.2.3

12 months ago

0.2.5

12 months ago

0.2.4

12 months ago

0.2.1

1 year ago

0.2.2

1 year ago

0.2.0

1 year ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago