clone

a deno framework for local-first web apps that open instantly, work offline and sync when users choose

feat/fix-sync-enrollment-startup
lofi / docs / recipes / related-app-discovery.md
related-app-discovery.md 2.1K rendered
1# Related-application discovery23Use this recipe only when the product already owns a native or installed-web companion and has4completed that platform's bidirectional verification. The5[`getInstalledRelatedApps()` API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getInstalledRelatedApps)6is experimental, limited to top-level secure contexts in supporting browsers, and intended here only7to avoid redundant presentation such as a companion-app onboarding banner.89## Manifest and verification1011The starter omits both members. Add the verified listing while leaving native preference false:1213```json14{15 "prefer_related_applications": false,16 "related_applications": [17 {18 "platform": "play",19 "id": "com.example.companion",20 "url": "https://play.google.com/store/apps/details?id=com.example.companion"21 }22 ]23}24```2526Do not invent identifiers. Android requires Digital Asset Links; Windows, cross-scope PWAs, and27other platforms have their own verification mechanisms. Manifest declaration alone is not proof of28ownership. Keep `prefer_related_applications` false or omitted so Chromium retains PWA29installability.3031## Presentation-only discovery3233```ts34import { discoverRelatedApplications } from "@nzip/lofi/recipes/related-app-discovery";3536const discovery = await discoverRelatedApplications({37 allow: [{38 platform: "play",39 id: "com.example.companion",40 url: "https://play.google.com/store/apps/details?id=com.example.companion",41 }],42});4344const showCompanionOnboarding = discovery.status !== "installed";45```4647Only exact allow-list matches are returned. Browser-supplied versions, unknown apps, and extra48fields are discarded. Unsupported, empty, malformed, embedded-context, and rejected calls all retain49the normal PWA experience. Never use discovery for authentication, authorization, account linking,50feature entitlements, or proof that the current user controls the companion app.5152Test unsupported and empty results, exact and mismatched platform IDs/URLs, API rejection, top-level53versus embedded contexts, privacy-safe UI, PWA installability, platform verification updates, and54removing the manifest listing.