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


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

กล่องโต้ตอบ UI การติดตั้งที่สมบูรณ์ยิ่งขึ้นประกอบด้วยเนื้อหาของฟิลด์ description
และ screenshots
ในไฟล์ Web Manifest
หากต้องการเรียกใช้กล่องโต้ตอบ คุณเพียงแค่ต้องเพิ่มภาพหน้าจออย่างน้อย 1 ภาพสำหรับรูปแบบอุปกรณ์ที่เกี่ยวข้อง แต่เราขอแนะนำให้เพิ่มคำอธิบายด้วย ดูรายละเอียดของช่องเหล่านั้นได้ที่ด้านล่าง
ภาพหน้าจอ
ภาพหน้าจอช่วยเพิ่มความ "สมบูรณ์" ให้กับ UI การติดตั้งใหม่ และเราขอแนะนำให้ใช้ภาพหน้าจอ ในไฟล์ Manifest คุณจะเพิ่มscreenshots
member ซึ่งรับอาร์เรย์ที่ต้องมีรูปภาพอย่างน้อย 1 รูป และ Chrome จะแสดงรูปภาพได้สูงสุด 8 รูป ตัวอย่างแสดงอยู่ด้านล่าง
"screenshots": [
{
"src": "source/image1.png",
"sizes": "640x320",
"type": "image/png",
"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();
});
}