Skip to content

Instantly share code, notes, and snippets.

@adactio
Last active November 29, 2025 20:15
Show Gist options
  • Select an option

  • Save adactio/a445544723363d37b9c31a74a03ef928 to your computer and use it in GitHub Desktop.

Select an option

Save adactio/a445544723363d37b9c31a74a03ef928 to your computer and use it in GitHub Desktop.
Web Install HTML web component
class ButtonInstall extends HTMLElement {
connectedCallback () {
this.button = this.querySelector('button');
if (window.matchMedia('(display-mode: standalone)').matches) {
this.button.remove();
return;
}
if (!navigator.install) {
this.button.remove();
return;
}
this.button.addEventListener('click', async (ev) => {
await navigator.install();
});
}
}
customElements.define('button-install', ButtonInstall);
@adactio
Copy link
Author

adactio commented Nov 29, 2025

Usage:

<install-button> <button>Add the app</button> </install-button>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment