PushSubscription: endpoint property

Baseline 已廣泛支援

此功能已成熟,並可在許多裝置和瀏覽器版本上執行。自 2023 年 3 月以來,它已在各種瀏覽器中可用。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

注意:此功能在 Web Workers 中可用。

PushSubscription 介面的 **endpoint** 只讀屬性返回一個字串,其中包含與推送訂閱關聯的端點。

此端點是一個指向推送伺服器的自定義 URL,可用於向訂閱了推送服務的特定 service worker 例項傳送推送訊息。因此,最好對端點保密,以防止他人劫持和濫用推送功能。

字串。

示例

js
navigator.serviceWorker.ready.then((reg) => {
  reg.pushManager.subscribe({ userVisibleOnly: true }).then((subscription) => {
    console.log(subscription.endpoint);

    // At this point you would most likely send the subscription
    // endpoint to your server, save it, then use it to send a
    // push message at a later date
  });
});

規範

規範
推送 API
# dom-pushsubscription-endpoint

瀏覽器相容性