在Android移动设备上使用Chrome调试服务工作者 [英] Debug service worker with Chrome on Android mobile

查看:41
本文介绍了在Android移动设备上使用Chrome调试服务工作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个渐进式Web应用程序,并且为了确保它在移动设备上(尤其是在占90%用户的Android版Chrome上)正常工作,我正在尝试在Android设备上测试Service Worker.

I'm developing a progressive webapp and, in order to make sure it's working on mobile device (and particularly on Chrome for Android as it's 90% of users), I'm trying to test service worker on an Android device.

不幸的是,在 Chrome for Android 上,我无法注册服务人员:

获取脚本时发生SSL证书错误.

An SSL certificate error occurred when fetching the script.

无法加载资源:net :: ERR_CERT_AUTHORITY_INVALID

Failed to load resource: net::ERR_CERT_AUTHORITY_INVALID


我知道服务工作者需要通过HTTPS进行服务,因此我的Web应用程序具有自签名证书.它不受浏览器的信任,但是仍然可以继续进行.当使用Android上的Firefox时,我可以签名以推送通知并注册服务人员,但是使用Chrome不能正常运行.


I know service worker needs to be served over HTTPS so I have a self-signed certificate for my webapp. It is not trusted by browsers but it is still possible to proceed anyway. When using Firefox for Android, no problem I can sign to push notifications and register the service worker but with Chrome it's not working.

在桌面版Chrome上,可以使用开发工具在非安全来源上启用Service Worker.我希望找到可以在移动设备上使用但不存在的等效标志.

On Chrome for desktop, it's possible to enable service worker over non-secure origin with dev tools. I hoped to find the equivalent flag that I could use on mobile but none exists.

是否可以在Chrome Android上授权服务工作者进行调试?

我发现了一个旧问题,没有任何有用的答案

I found an old question with no helpful answer there about the same issue and decided to open this one up for visibilty.

推荐答案

从您引用的其他StackOverflow帖子中,我可以看到问题所在.

From the other StackOverflow post you're referring to, I can see the solution is in the question.

您需要向您的Android信任列表中添加证书颁发机构 crt .

You need to add a Certificate Authority crt to your Android trust list.

为什么要专门指定证书颁发机构.crt?

仅仅是因为Android仅接受CA证书.

Simply because Android only accepts CA certificates.

如何获得CA证书?

通常,证书颁发机构(CA)充当受信任的第三方.为了进行调试,您可以充当CA自己颁发自签名证书.

Normally, a Certificate Authority (CA) acts as a trusted third party. For debug purpose, you can act as a CA to issue self-signed certificate yourself.

  1. 创建一个根密钥: openssl genrsa -des3 -out rootCA.key 4096 (警告:任何持有此密钥的人都可以代表您签名证书!)

  1. Create a root key: openssl genrsa -des3 -out rootCA.key 4096 (warning : anyone holding this can sign certificates on your behalf !)

创建并自签名根证书: openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt

Create and self sign the Root Certificate: openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt

请记住,您的Web应用程序的 SSL证书需要使用相同的自行创建的CA生成.

Remember that your webapp's SSL certificate needs to be generated with that same self-created CA.

在Android设备上安装证书

获得.crt文件后,将其复制到设备中.然后转到设置>安全>从存储安装.它应该检测到证书并让您添加它.

Once you got your .crt file, copy it inside your device. Then go to Settings > Security > Install from storage. It should detect the certificate and let you add it.

要确保已正确安装,请转至受信任的凭证> 用户.

To make sure it's installed correctly, go to Trusted Credentials > User.

这篇关于在Android移动设备上使用Chrome调试服务工作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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