无法安装站点:未检测到匹配的 Service Worker [英] Site cannot be installed: no matching service worker detected

查看:47
本文介绍了无法安装站点:未检测到匹配的 Service Worker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试编写我的第一个 pwa 并遇到以下问题:

当我启动我的网络应用程序时,我收到以下错误:

<块引用>

无法安装站点:未检测到匹配的 Service Worker.您可能需要重新加载页面,或者检查当前页面的 Service Worker 是否还控制清单中的起始 URL

我认为我的清单 url 是正确的,因为这个 link

manifest.json

"start_url": ".","display": "独立",方向":肖像","theme_color": "#29BDBB","background_color": "#29BDBB"

我像这样注册我的软件:

if ('serviceWorker' in navigator) {navigator.serviceWorker.register('./sw.js').then(function(reg) {console.log('成功注册服务工作者', reg);}).catch(函数(错误){console.warn('注册服务工作者时出错', err);});}

我从这里

所以我正在尝试制作一个简单的网络应用程序,我可以使用 firebase 托管该应用程序.>

有什么问题吗?感谢您的帮助

解决方案

将 Service Worker 脚本文件放在您网站的根目录并将 start_url 设置为 /,或把它放在你想要的任何地方,并使用 scope 属性和 Service-Worker-Allowed HTTP 标头,如 我的另一个答案.

Hey I am trying to program my first pwa and got the following problem:

when I start my web app I get the following error:

Site cannot be installed: no matching service worker detected. You may need to reload the page, or check that the service worker for the current page also controls the start URL from the manifest

I think my manifest url is right because of this link

manifest.json

"start_url": ".",
"display": "standalone",
"orientation": "portrait",
"theme_color": "#29BDBB",
"background_color": "#29BDBB"

and I register my sw like this:

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./sw.js').then(function(reg) {
    console.log('Successfully registered service worker', reg);
}).catch(function(err) {
    console.warn('Error whilst registering service worker', err);
});
}

I got my sw from here

So I am trying to make a simple web app which I can host with firebase.

Whats the problem? Thanks for your help

解决方案

Place the service worker script file at the root of your website and set start_url to /, or place it wherever you want and use the scope property and the Service-Worker-Allowed HTTP header as in my other answer.

这篇关于无法安装站点:未检测到匹配的 Service Worker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆