您可以使用带有自签名证书的 Service Worker 吗? [英] Can you use a service worker with a self-signed certificate?

查看:32
本文介绍了您可以使用带有自签名证书的 Service Worker 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用于测试的开发者服务器.他们有 SSL 自签名证书,这使我们可以通过 HTTPS 测试 Web 应用程序,但带有显着警告,表明证书无法验证.

I have developer server that are used for testing. They have SSL self-signed certificates, which allow us to test the web application over HTTPS, but with prominent warnings that the certificates are not verifiable.

那很好,但我有一个 Service Worker,它在 navigator.serviceWorker.register

That's fine, but I have a Service Worker that throws an error with the navigator.serviceWorker.register

SecurityError: Failed to register a ServiceWorker: 获取脚本时发生 SSL 证书错误.

SecurityError: Failed to register a ServiceWorker: An SSL certificate error occurred when fetching the script.

如何将 Service Worker 与具有自签名证书的 Intranet 测试服务器一起使用?

How do I use a Service Worker with an intranet testing server which has a self-signed certificate?

推荐答案

作为使用自签名证书的替代方法,您可以启动 Chrome 或 Firefox,使其假装某些域是安全的.例如,在 Mac 上使用 Chrome,您可以使用以下命令启动它:

As an alternative to using self-signed certificates, you can launch Chrome or Firefox such that it pretends certain domains are secure. For example, using Chrome on a Mac, you can launch it using:

/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome --user-data-dir=/tmp/foo --unsafely-treat-insecure-origin-as-secure=http://www.your.site

Service Worker 应该从 http://www.your.site 工作.

Service workers should then work from http://www.your.site.

更多信息可以在这里找到:通过 HTTP 测试 Service Worker 的选项

More info can be found here: Options for testing service workers via HTTP

--unsafety-... 更改为 --unsafely-...

这篇关于您可以使用带有自签名证书的 Service Worker 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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