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

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

问题描述

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

当我启动Web应用程序时,出现以下错误:

无法安装站点:未检测到匹配的服务程序.您可能需要重新加载页面,或检查当前页面的服务工作者是否也从清单中控制了起始URL

由于此链接

,我认为我的清单网址是正确的

manifest.json

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

我这样注册我的sw:

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);
});
}

我从这里

因此,我正在尝试制作一个简单的Web应用程序,可以使用 firebase 进行托管.

>

出什么问题了?感谢您的帮助

解决方案

将服务工作者脚本文件放置在网站的根目录下,并将start_url设置为/,或者将其放置在任意位置并使用属性和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.

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

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