notifications
使用底层操作系统提供的通知机制向用户显示通知。由于此 API 使用操作系统的通知机制,因此通知的显示和行为细节可能因操作系统和用户的设置而异。
在 macOS 上,通知的外观大致如下

在 Windows 上,通知会一直保留在操作中心,直到浏览器关闭。通知的外观大致如下

要使用此 API,您需要拥有“notifications” 权限。
类型
notifications.NotificationOptions-
定义通知的内容。
notifications.TemplateType-
通知的类型。例如,这决定了通知是否可以包含图像。
函数
notifications.clear()-
清除给定 ID 的特定通知。
notifications.create()-
创建并显示一个新通知。
notifications.getAll()-
获取所有通知。
notifications.update()-
更新通知。
事件
-
当用户点击通知中的按钮时触发。
notifications.onClicked-
当用户点击通知(但不是按钮)时触发。
notifications.onClosed-
当通知关闭时触发,无论是系统关闭还是用户主动关闭。
notifications.onShown-
通知显示后立即触发。
扩展程序示例
浏览器兼容性
加载中…
注意: 此 API 基于 Chromium 的 chrome.notifications API。