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

浏览器兼容性