より機能が充実したインストール UI を追加する方法

アプリストアは、デベロッパーがインストール前にアプリを紹介するためのスペースとして、ユーザーがアプリのインストールを選択するのに役立つスクリーンショットやテキスト情報を提供します。また、ウェブアプリ デベロッパーは、ブラウザから直接アプリをインストールするようユーザーを招待できる同様のスペースを提供します。この拡張された UI は、Android 環境とデスクトップ環境の Chrome でご利用いただけます。

デフォルトのプロンプト

以下のデフォルトのエクスペリエンスでは、十分なコンテキストが提供されていません。

デスクトップ用のブラウザのデフォルトのインストール ダイアログ
デスクトップのデフォルトのインストール ダイアログ


モバイル デバイスのブラウザのデフォルトのインストール ダイアログ
モバイルでのデフォルトのインストール ダイアログ

充実したインストール UI

通常の小さいデフォルト プロンプトの代わりにリッチなインストール UI ダイアログを表示するには、ウェブ マニフェストに screenshots フィールドと description フィールドを追加します。以下の Squoosh.app の例をご覧ください。

パソコンとモバイルでのインストール UI を拡充
パソコンとモバイルでのインストール UI が充実しました。

リッチなインストール UI ダイアログは、ウェブ マニフェストの description フィールドと screenshots フィールドの内容で構成されています。

ダイアログを表示するには、対応するフォーム ファクタのスクリーンショットを 1 つ以上追加する必要がありますが、説明も追加することをおすすめします。各フィールドの詳細については、以下をご覧ください。

スクリーンショット

スクリーンショットは新しいインストール UI の「リッチ」な部分を補強するため、使用することを強くおすすめします。マニフェストで screenshots メンバーを追加します。これは 1 つ以上の画像を必要とする配列で、Chrome では最大 8 つまで表示されます。たとえば、次のようになります。

 "screenshots": [
    {
     "src": "source/image1.gif",
      "sizes": "640x320",
      "type": "image/gif",
      "form_factor": "wide",
      "label": "Wonder Widgets"
    }
]

スクリーンショットは次の条件を満たしている必要があります。

  • 幅と高さは 320 ピクセル以上、3,840 ピクセル以下にする必要があります。
  • 最大サイズを最小サイズの 2.3 倍以下にする必要があります。
  • 同じフォーム ファクタの値を持つスクリーンショットはすべて、同じアスペクト比にする必要があります。
  • JPEG と PNG の画像形式のみがサポートされています。
  • 表示されるスクリーンショットは 8 つのみです。さらに追加された場合、ユーザー エージェントは単に無視します。

また、画像が正しくレンダリングされるように、画像のサイズとタイプを指定する必要があります。こちらのデモをご覧ください

form_factor は、スクリーンショットをパソコン環境(wide)とモバイル環境(narrow)のどちらで表示するかをブラウザに指示します。

説明

description メンバーは、インストール プロンプトでアプリについて説明し、アプリのインストールを続けるようユーザーに促します。

ダイアログは description がなくても表示されますが、おすすめします。最大文字数は、テキストが 7 行(約 324 文字)に達すると表示され、それより長い説明文は切り捨てられ、省略記号が追加されます(こちらの例をご覧ください)。

{
…
"description": "Compress and compare images with different codecs
right in your browser."
}
説明を追加しました
説明を追加しました。
一部が省略された長い説明です。
それより長い説明は切り捨てられます。

この説明は、インストール プロンプトの上部に表示されます。

スクリーンショットからお気づきかもしれませんが、インストール ダイアログにはアプリのオリジンも一覧表示されています。長すぎて UI に収まらないオリジンは切り捨てられます。これは省略とも呼ばれ、ユーザーを保護するためのセキュリティ対策として使用されます。

関連情報

デモ

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="color-scheme" content="dark light" />
    <link rel="manifest" href="manifest.json" />
    <title>How to add Richer Install UI to your web app</title>
    <!-- TODO: Devsite - Removed inline handlers -->
    <!-- <script>
      if ('serviceWorker' in navigator) {
        window.addEventListener('load', () => {
          navigator.serviceWorker.register('sw.js');
        });
      }
    </script>
    <script type="module" src="script.js"></script> -->
  </head>
  <body>
    <h1>How to add Richer Install UI to your web app</h1>
    <ol>
      <li>
        Install the app by clicking the button below. After the installation,
        the button is disabled.
        <p>
          <button disabled type="button">Install</button>
        </p>
      </li>
      <li>
        When you click on install a dialog similar to the ones from app stores
        will be displayed.
      </li>
      <li>
        The dialog includes the `description` and `screenshots` set in the app
        manifest.
      </li>
      <li>
        Screenshots should be different depending if the app is being installed
        on a mobile or desktop device, according to the `form_factor` value set
        for the screenshots on the manifest
      </li>
    </ol>
  </body>
</html>

JS


        // The install button.
const installButton = document.querySelector('button');

// Only relevant for browsers that support installation.
if ('BeforeInstallPromptEvent' in window) {
  // Variable to stash the `BeforeInstallPromptEvent`.
  let installEvent = null;

  // Function that will be run when the app is installed.
  const onInstall = () => {
    // Disable the install button.
    installButton.disabled = true;
    // No longer needed.
    installEvent = null;
  };

  window.addEventListener('beforeinstallprompt', (event) => {
    // Do not show the install prompt quite yet.
    event.preventDefault();
    // Stash the `BeforeInstallPromptEvent` for later.
    installEvent = event;
    // Enable the install button.
    installButton.disabled = false;
  });

  installButton.addEventListener('click', async () => {
    // If there is no stashed `BeforeInstallPromptEvent`, return.
    if (!installEvent) {
      return;
    }
    // Use the stashed `BeforeInstallPromptEvent` to prompt the user.
    installEvent.prompt();
    const result = await installEvent.userChoice;
    // If the user installs the app, run `onInstall()`.
    if (result.outcome === 'accepted') {
      onInstall();
    }
  });

  // The user can decide to ignore the install button
  // and just use the browser prompt directly. In this case
  // likewise run `onInstall()`.
  window.addEventListener('appinstalled', () => {
    onInstall();
  });
}