You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS Safari中PushAPI无法使用,返回空endpoint问题排查

问题:Chrome中PushAPI订阅返回空Endpoint及密钥

我的代码在本地及生产环境的Chrome中运行正常,但某台企业管理设备上出现异常。使用标准PushAPI实现的Subscribe()函数(未使用Apple APN服务),浏览器能正常请求用户通知权限,但执行订阅后返回的PushSubscription对象中,endpoint、p256dh密钥、auth密钥均为空,且全程无报错信息。

订阅函数代码

export function Subscribe(vapid: string): Promise<PushSubscription> {
    return new Promise((resolve, reject) => {
        if (!vapid) {
            reject("VAPID not declared")
        }

        navigator.serviceWorker.getRegistration()
        .then((registration) => {  
            if (!registration) {
                return
            }
            registration.pushManager.subscribe({
                userVisibleOnly: true,
                applicationServerKey: urlBase64ToUint8Array(vapid),
            }).then((subscription) => {
                console.log(subscription)
                if (!subscription) {
                    reject(new Error("Unable to subscribe (empty subscription)"))
                }
                if (subscription.endpoint === "") {
                    reject(new Error("Unable to subscribe (empty endpoint)"))
                }
                resolve(subscription)
            })
        })
        .catch((err) => {
            reject(err)
        });
    })
}

异常现象

订阅后得到的PushSubscription对象:

PushSubscription {endpoint: "", expirationTime: null, options: PushSubscriptionOptions, getKey: function, unsubscribe: function, …}

序列化后的JSON结构:

{
  "keys":{
    "p256dh":"",
    "auth":""
  }
}

已完成的排查操作

  • 其他设备测试该代码,订阅流程完全正常;
  • 删除~/Library/Safari/RemoteNotifications/Permissions.plist后,某依赖非服务端推送API的通知测试页面可正常工作,但服务端推送类型的测试页面仍无法使用,发送通知时弹出"undefined"提示,调试发现提交给服务器的Payload同样为空:
{
  "endpoint":"",
  "publicKey":"",
  "authSecret":""
}
  • 确认该设备处于企业管理范围内,管理员明确表示未设置任何推送通知限制政策。

内容的提问来源于stack exchange,提问作者Yann Bizeul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 06:44:59