Installing to Home Screen¶
Add to Home screen is a browser feature that allows installing a shortcut to the user's Home screen.
PWA checklist¶
First we need to follow a few steps to configure PWA support:
-
Create a new
public/app.webmanifest
file: -
Create a 192x192 pixel icon in
public/logo-192x192.png
. -
Link to the manifest in your
index.html
: -
Create a new
src/service-worker.ts
that will be the entry point for your service worker: -
Configure your build script to also build
dist/service-worker.js
whenever younpm run build
. For example: -
In your game where you call
playpass.init()
, pass along the service worker URL:
Checking if the player can install¶
Not all browsers support PWA installation. Other browsers require the user to spend some time
interacting with the page before it can become installable. Use
getInstallState()
to check current availability.
if (playpass.device.getInstallState() == "installable") {
// Show an offer to install for an in-game reward
}
Requesting to install¶
Call requestInstall()
to show the built-in browser UI for installing the PWA.
const installed = await playpass.device.requestInstall();
if (installed) {
// Player installed, give them a reward for installing
}