PushMessageData: phương thức bytes()

Baseline 2025
Newly available

Since January 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is only available in Service Workers.

Phương thức bytes() của giao diện PushMessageData trích xuất dữ liệu push message dưới dạng đối tượng Uint8Array.

Cú pháp

js
bytes()

Tham số

Không có.

Giá trị trả về

Một Uint8Array.

Ngoại lệ

Giá trị trả về Uint8Array được hỗ trợ bởi một ArrayBuffer chứa các byte. Mọi ngoại lệ được ném ra trong quá trình tạo bộ đệm hỗ trợ này sẽ được ném lại.

Xem TypedArray.

Ví dụ

js
self.addEventListener("push", (event) => {
  const buffer = event.data.bytes();

  // làm gì đó với mảng typed của bạn
});

Thông số kỹ thuật

Specification
Push API
# dom-pushmessagedata-bytes

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