demo · v140

Cross-Platform Router

A click-handler that asks navigator.getInstalledRelatedApps() which of your native apps the user has, then routes accordingly. Toggle the simulated install state of an Android app, a Windows MSIX, and a PWA, and watch the "open in" behaviour change.

simulate which apps the user has installed:

Android app
Windows MSIX
PWA
open User clicks "open document"
share User taps share-to-app
install User on the marketing site
const installed = await navigator.getInstalledRelatedApps();

const native = installed.find(a => a.platform === "play"
                              || a.platform === "windows");
if (native) {
  // Deep-link into the platform app
  location.href = native.url + "?doc=" + id;
} else if (installed.find(a => a.platform === "webapp")) {
  // Trust PWA install
  location.href = "/app/document/" + id;
} else {
  // Promote install
  showInstallSheet();
}

see also