# related_applications and prefer_related_applications

> related_applications lists a PWA's native or web counterparts by platform, url, and id; prefer_related_applications hints that a related app is preferred over the web app.

The `related_applications` manifest member lists a web app's native and web counterparts as an array of objects. Each object names a `platform` and a store `url` or `id`. `prefer_related_applications`
is a boolean hint that the browser may suggest one of those counterparts instead of offering to
install the web app itself. The same array is what `navigator.getInstalledRelatedApps()`
reads at runtime.

Chrome 44 on Android, Samsung Internet 4.0, Android WebView 44, and Edge 17 process both
members (BCD `manifests.webapp.related_applications`). Chrome on desktop reads the array for
`getInstalledRelatedApps()` on Windows and reports an installability error when `prefer_related_applications` is `true`. BCD records no support in Firefox or
Safari, and notes that on Firefox for Android the property parses but has no effect.

## Member

| Property | Value |
|---|---|
| Type | `related_applications` is an array of objects with `platform` (string, required), `url` (string), `id` (string), `min_version` (string), and `fingerprints` (array of `{ type, value }`). At least one of `url` or `id` is required. `prefer_related_applications` is a boolean. |
| Allowed `platform` values | `play` (Google Play), `itunes` (App Store), `windows` (Microsoft Store), `chrome_web_store`, `f-droid`, `amazon`, and `webapp` (a PWA identified by its manifest `id`). |
| Default | an empty array, and `false`. Omitting `prefer_related_applications` is the same as writing `false`. |
| Example value | `[{ "platform": "play", "id": "com.example.app" }]` with `"prefer_related_applications": true`. |

Chromium validates each entry on its own: a missing platform logs `'platform' is a required
field, related application ignored.` and an entry with neither `url` nor `id` logs `one of 'url'
or 'id' is required, related application ignored.`. An entry that is not an object is skipped without a message, and entries that pass these checks are kept. The relation
is one-way: the native app is not required to point back at the web app, except for
`getInstalledRelatedApps()`, which on Android verifies the Play app's Digital Asset Links
statement before reporting it installed.

In Chromium, `prefer_related_applications: true` makes the installability check report `Manifest specifies
prefer_related_applications: true`. Chromium's logging file also defines a separate error,
`prefer_related_applications is only supported on Chrome Beta and Stable channels on
Android`, for a non-qualifying channel

:::caution
Chromium's [`installable_logging.cc`](https://chromium.googlesource.com/chromium/src/+/main/components/webapps/browser/installable/installable_logging.cc) defines the installability error `Manifest specifies prefer_related_applications: true`, which DevTools lists in the **Installability** section ([`AppManifestView.ts`](https://github.com/ChromeDevTools/devtools-frontend/blob/main/front_end/panels/application/AppManifestView.ts)). In [`manifest_parser.cc`](https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/modules/manifest/manifest_parser.cc), an entry in `related_applications` that has no `platform` is skipped and records `'platform' is a required field, related application ignored.`, which DevTools lists under **Errors and warnings**.
:::

## Examples

Declare native and web counterparts in the manifest, then query the array at runtime.

### Pointing at a Play Store app and the Microsoft Store listing

A web app with native siblings lists both. The Play entry carries the package name as `id`
and the store page as `url`; the Microsoft Store entry has only a `url`. Without
`prefer_related_applications` the list does not block installability, and `getInstalledRelatedApps()` reads it.

```json
{
  "name": "Trail Maps",
  "start_url": "/",
  "display": "standalone",
  "related_applications": [
    {
      "platform": "play",
      "url": "https://play.google.com/store/apps/details?id=com.example.trailmaps",
      "id": "com.example.trailmaps"
    },
    {
      "platform": "windows",
      "url": "https://apps.microsoft.com/store/detail/trail-maps/9WZDNCRFHVJL"
    }
  ]
}
```

Add `"prefer_related_applications": true` only when the browser should prefer the native app over the web app; Chromium's installability check reports an error while it is `true`.

### Hiding the install button when the native app is present

`navigator.getInstalledRelatedApps()` resolves with the entries from the array that are
installed on the device (Chrome 80 on Android; Chrome 85 on Windows for `windows` entries). It
works only from the top-level frame of the app's own origin, and the Play app must publish a
Digital Asset Links statement for the origin. The fallback keeps the button for browsers without
the method.

```js
async function nativeAppInstalled() {
  if (typeof navigator.getInstalledRelatedApps !== 'function') {
    return false; // Safari, Firefox, Chrome iOS: show the web install path
  }
  try {
    const apps = await navigator.getInstalledRelatedApps();
    return apps.some((app) => app.platform === 'play' || app.platform === 'windows');
  } catch {
    return false; // not top-level, or the asset links did not verify
  }
}

nativeAppInstalled().then((installed) => {
  document.querySelector('#install-web-app').hidden = installed;
});
```

The resolved objects carry `platform`, `url`, `id`, and `version`, so the same call can also
detect an outdated native app when `min_version` is set.

### Detecting whether the PWA itself is already installed

A `webapp` entry whose `id` equals the manifest's own `id` lets the site, opened in a browser
tab, ask whether its PWA is installed on this device. Chrome 85 and later resolve it; other
browsers fall through to the display-mode check, which only knows about the current window.

```json
{
  "id": "/",
  "related_applications": [
    { "platform": "webapp", "url": "https://trailmaps.example/manifest.webmanifest" }
  ]
}
```

```js
async function pwaInstalled() {
  if (matchMedia('(display-mode: standalone)').matches) return true; // running as the app
  if (typeof navigator.getInstalledRelatedApps !== 'function') return false;
  const apps = await navigator.getInstalledRelatedApps();
  return apps.some((app) => app.platform === 'webapp');
}
```

Use the answer to replace an "Install" call to action with "Open app"; the `webapp` entry has
no effect on installability or on the install prompt.

## See also

- [getInstalledRelatedApps(): detecting an installed native or PWA counterpart](/reference/installation/get-installed-related-apps/)
- [id manifest member](/reference/manifest/id/)
- [Installability criteria: what makes a PWA installable](/reference/installation/installability-criteria/)
- [Trusted Web Activity (TWA): PWAs in the Play Store](/reference/installation/twa/)
- [Manifest Incubations: related_applications member](https://wicg.github.io/manifest-incubations/#related_applications-member) (wicg.github.io)
- [Navigator: getInstalledRelatedApps() method](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getInstalledRelatedApps) (developer.mozilla.org)