DEV: Use isSecureContext for service worker registrations (#19407)

Currently, we check if the site is loaded over `https` before
registering the service worker. This prevents the service worker from
being registered in a standard dev/test setup.

This change replaces the protocol check with `isSecureContext`
property check.

In addition to resources delivered over `https`, `isSecureContext`
returns `true` for resources loaded over `http://127.0.0.1`, `http://localhost`,
`http://*.localhost` and `file://`.
This commit is contained in:
Selase Krakani 2022-12-11 16:37:41 +00:00 committed by GitHub
parent 1a0473e890
commit 656d0fa762
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 3 deletions

View File

@ -5,9 +5,7 @@ export function registerServiceWorker(
serviceWorkerURL,
registerOptions = {}
) {
const isSecured = document.location.protocol === "https:";
if (isSecured && "serviceWorker" in navigator) {
if (window.isSecureContext && "serviceWorker" in navigator) {
const caps = container.lookup("capabilities:main");
const isAppleBrowser =
caps.isSafari ||