gpt4 book ai didi

android - ServiceWorker 注册失败 : DOMException: Only secure origins are allowed (see: https://goo. gl/Y0ZkNV)

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:57 26 4
gpt4 key购买 nike

我编写了代码来获取 GCM id 以发送 chrome 推送通知。我写了下面的代码来获取 GCM id。

var ChromePushManager = function (serviceWorkerPath, callback) {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(serviceWorkerPath).then(function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);

registration.pushManager.subscribe({userVisibleOnly: true}).then(function (subscription) {
console.log("subscription.subscriptionId: ", subscription.subscriptionId);
console.log("subscription.endpoint: ", subscription.endpoint);

// TODO: Send the subscription subscription.endpoint
// to your server and save it to send a push message
// at a later date
var register = ChromePushManager.getRegistrationId(subscription);
callback(null, register);
});
}).catch(function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
} else {
callback('Service workers aren\'t supported in this browser.', null);
}
};

ChromePushManager.getRegistrationId = function (pushSubscription) {
if (pushSubscription.subscriptionId) {
return pushSubscription.subscriptionId;
}

var endpoint = 'https://android.googleapis.com/gcm/send/';
parts = pushSubscription.endpoint.split(endpoint);

if (parts.length > 1)
{
console.log("RegistrationId : " + parts[1]);
return parts[1];
}
}

var chromePushManager = new ChromePushManager('../js/service-worker.js', function (error, registrationId) {
if (error !== null) {
console.log(error);
}
});

它在 http://localhost:8080 中运行良好.我在服务器上传了这段代码。我试图在服务器中执行代码。我遇到了错误。

ServiceWorker 注册失败:DOMException:只允许安全来源(参见:https://goo.gl/Y0ZkNV)。

我不知道这个错误是什么意思。你能不能解释一下这个错误是什么意思,并给我一个在我的服务器端解决这个错误的解决方案。

谢谢。

最佳答案

您需要在服务器上使用https

错误:只允许安全来源(参见:link)。

来自 link in error : secure origins from link in error

关于android - ServiceWorker 注册失败 : DOMException: Only secure origins are allowed (see: https://goo. gl/Y0ZkNV),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34290337/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com