วิธีเพิ่ม UI การติดตั้งที่สมบูรณ์ขึ้น

App Store มอบพื้นที่ให้นักพัฒนาแอปได้แสดงแอปของตนก่อนการติดตั้ง โดยมีภาพหน้าจอและข้อมูลข้อความที่ช่วยให้ผู้ใช้เลือกติดตั้งแอปได้ UI การติดตั้งที่สมบูรณ์ยิ่งขึ้นมีพื้นที่คล้ายๆ ให้นักพัฒนาแอปเว็บได้เชิญผู้ใช้ให้ติดตั้งแอปจากเบราว์เซอร์โดยตรง UI ที่เพิ่มประสิทธิภาพนี้พร้อมใช้งานในสภาพแวดล้อม Chrome สำหรับ Android และเดสก์ท็อป

ข้อความแจ้งเริ่มต้น

ดูตัวอย่างประสบการณ์การใช้งานเริ่มต้นด้านล่าง ซึ่งไม่มีบริบทเพียงพอ

กล่องโต้ตอบการติดตั้งเริ่มต้นของเบราว์เซอร์สำหรับเดสก์ท็อป
กล่องโต้ตอบการติดตั้งเริ่มต้นบนเดสก์ท็อป


กล่องโต้ตอบการติดตั้งเริ่มต้นของเบราว์เซอร์สำหรับอุปกรณ์เคลื่อนที่
กล่องโต้ตอบการติดตั้งเริ่มต้นในอุปกรณ์เคลื่อนที่

UI การติดตั้งที่สมบูรณ์ยิ่งขึ้น

หากต้องการรับกล่องโต้ตอบ UI การติดตั้งที่สมบูรณ์ยิ่งขึ้นแทนข้อความแจ้งเริ่มต้นขนาดเล็กแบบปกติ ให้เพิ่มช่อง screenshots และ description ลงในไฟล์ Manifest ของเว็บ ดูตัวอย่าง Squoosh.app ด้านล่าง

UI การติดตั้งที่สมบูรณ์ยิ่งขึ้นบนเดสก์ท็อปและอุปกรณ์เคลื่อนที่
UI การติดตั้งที่สมบูรณ์ยิ่งขึ้นบนเดสก์ท็อปและอุปกรณ์เคลื่อนที่

กล่องโต้ตอบ UI การติดตั้งที่สมบูรณ์ขึ้นประกอบด้วยเนื้อหาของช่อง description และ screenshots ในไฟล์ Manifest ของเว็บ

หากต้องการเรียกกล่องโต้ตอบ คุณจะต้องเพิ่มภาพหน้าจออย่างน้อย 1 ภาพสำหรับรูปแบบของอุปกรณ์ที่เกี่ยวข้อง แต่เราขอแนะนำให้เพิ่มคำอธิบายด้วย ดูรายละเอียดของฟิลด์เหล่านั้นด้านล่าง

ภาพหน้าจอ

ภาพหน้าจอจะเพิ่มส่วนที่ "สมบูรณ์ยิ่งขึ้น" ให้กับ UI การติดตั้งแบบใหม่ และเราขอแนะนำอย่างยิ่งให้ใช้ภาพหน้าจอเหล่านั้น ในไฟล์ Manifest คุณเพิ่มสมาชิก 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 ภาพเท่านั้น ถ้ามีการเพิ่ม User Agent จะไม่สนใจเลย

นอกจากนี้ คุณจะต้องใส่ขนาดและประเภทของรูปภาพเพื่อให้แสดงผลอย่างถูกต้อง ดูการสาธิตนี้

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();
  });
}