LaunchParams

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Giao diện LaunchParams của Launch Handler API được sử dụng khi triển khai xử lý điều hướng khởi chạy tùy chỉnh trong PWA. Khi window.launchQueue.setConsumer() được gọi để thiết lập chức năng xử lý điều hướng khởi chạy, hàm callback bên trong setConsumer() nhận một đối tượng LaunchParams.

Điều hướng tùy chỉnh như vậy được khởi tạo qua Window.launchQueue khi PWA được khởi chạy với giá trị client_mode của launch_handlerfocus-existing, navigate-new, hoặc navigate-existing.

Thuộc tính phiên bản

LaunchParams.files Read only Experimental

Trả về một mảng chỉ đọc các đối tượng FileSystemHandle đại diện cho các tệp được truyền cùng với điều hướng khởi chạy qua phương thức POST.

LaunchParams.targetURL Read only Experimental

Trả về URL đích của lần khởi chạy.

Ví dụ

js
if ("launchQueue" in window) {
  window.launchQueue.setConsumer((launchParams) => {
    if (launchParams.targetURL) {
      const params = new URL(launchParams.targetURL).searchParams;

      // Assuming a music player app that gets a track passed to it to be played
      const track = params.get("track");
      if (track) {
        audio.src = track;
        title.textContent = new URL(track).pathname.slice(1);
        audio.play();
      }
    }
  });
}

Thông số kỹ thuật

Specification
Web App Launch Handler API
# launchparams-interface

Tương thích trình duyệt

Xem thêm