大网数据广告活动
Web 标准与前端开发

BackgroundFetchUpdateUIEvent

· 52CE 我爱测

The **`BackgroundFetchUpdateUIEvent`** interface of the Background Fetch API is an event type for the ServiceWorkerGlobalScope.backgroundfetchsuccess_event and ServiceWorkerGlobalScope.backgroundfetchfail_event events, and provides a method for updating the title and icon of the

Background Fetch APIservice

The BackgroundFetchUpdateUIEvent interface of the Background Fetch API is an event type for the ServiceWorkerGlobalScope.backgroundfetchsuccess_event and ServiceWorkerGlobalScope.backgroundfetchfail_event events, and provides a method for updating the title and icon of the app to inform a user of the success or failure of a background fetch.

Constructor

  • BackgroundFetchUpdateUIEvent.BackgroundFetchUpdateUIEvent()
    • : Creates a new BackgroundFetchUIEvent object. This constructor is not typically used, as the browser creates these objects itself for the ServiceWorkerGlobalScope.backgroundfetchsuccess_event and ServiceWorkerGlobalScope.backgroundfetchfail_event events.

Instance properties

Also inherits properties from its parent, BackgroundFetchEvent.

Instance methods

Also inherits methods from its parent, BackgroundFetchEvent.

  • BackgroundFetchUpdateUIEvent.updateUI()
    • : Updates the title and icon in the user interface to show the status of a background fetch. Resolves with a Promise.

Examples

In this example, the backgroundfetchsuccess event is listened for, indicating that a fetch has completed successfully. The BackgroundFetchUpdateUIEvent.updateUI() method is then called, with a message to let the user know the episode they downloaded is ready.

addEventListener("backgroundfetchsuccess", (event) => {
  const bgFetch = event.registration;

  event.waitUntil(
    (async () => {
      // Create/open a cache.
      const cache = await caches.open("downloads");
      // Get all the records.
      const records = await bgFetch.matchAll();
      // Copy each request/response across.
      const promises = records.map(async (record) => {
        const response = await record.responseReady;
        await cache.put(record.request, response);
      });

      // Wait for the copying to complete.
      await Promise.all(promises);

      // Update the progress notification.
      event.updateUI({ title: "Episode 5 ready to listen!" });
    })(),
  );
});

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。