通过HTTP测试服务人员的选项 [英] Options for testing service workers via HTTP

查看:106
本文介绍了通过HTTP测试服务人员的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试服务人员,但我有一个虚拟主机设置,我似乎无法在本地主机上启用https。



如何将白名单我的本地虚拟主机URL测试服务工作者
,只要我尝试注册本地主机上的服务工作者? Chrome说https需要启用服务工作者。我怎么能通过这个限制至少为本地测试。

解决方案

一般来说,您需要同时提供您的页面和您的服务工作者脚本通过HTTPS为了使用服务工作者。基本原理在首选安全起源强大的新功能



为便于本地开发,HTTPS要求存在例外情况:如果您通过<$ c访问页面和服务工作者脚本$ c> http:// localhost [:port] ,或通过 http://127.xyz [:port] ,然后服务人员如果由于某种原因,您需要通过除 localhost以外的其他主机名访问本地Web服务器 / code>或 127.xyz ,或者如果您需要在不支持HTTPS的远程Web服务器上测试内容,您可以使用手动解决方法。它涉及通过命令行启动Chrome,并使用 - user-data-dir - unsafely-treat-insecure-origin -as-secure 标志。



此错误包含更多详细信息,包括

Firefox 完整示例。 / ServiceWorker / issues / 658#issuecomment-87283965rel =noreferrer>提供类似的功能,通过 devtools.serviceWorkers.testing.enabled 设置。 / p>

请注意,此功能仅适用于,其目的是为了便于进行无法进行的测试,并且您应始终计划使用HTTPS服务于您的网站的生产版本。不要要求真正的用户通过启用这些标志的步骤!


I want to test service workers but I have a virtual host setup and I can't seem to be able to enable https on localhost.

How can I whitelist my local virtual host url to test service workers whenever I try and register for the service worker on the localhost? Chrome says https is required to enable service worker. How can I get past this restriction at least for local testing.

解决方案

In general, you need to serve both your page and your service worker script via HTTPS in order to use service workers. The rationale is described at Prefer Secure Origins For Powerful New Features.

There's an exception to the HTTPS requirement in place to facilitate local development: if you access your page and service worker script via http://localhost[:port], or via http://127.x.y.z[:port], then service workers should be enabled without any further actions.

If, for some reason, you need to access your local web server via a hostname other than localhost or 127.x.y.z, or if you need to test things on a remote web server that doesn't support HTTPS, there is a manual workaround you can use. It involves starting up Chrome via the command line, and using both the --user-data-dir and --unsafely-treat-insecure-origin-as-secure flags.

This bug has more details, including a full example of how to launch Chrome.

Firefox offers similar functionality, via the devtools.serviceWorkers.testing.enabled setting.

Please note that this functionality is only meant to facilitate testing that wouldn't otherwise be able to take place, and you should always plan on using HTTPS when serving the production version of your site. Don't ask real users to go through the steps of enabling those flags!

这篇关于通过HTTP测试服务人员的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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