Why is window.navigator.storage.estimate() sometimes undefined on Chrome

Viewed 1284

If I serve my app from http://localhost, in the dev console I can do window.navigator.storage.estimate().

If I serve the same app from http://example.com where example.com resolves to 127.0.0.1 from my /etc/hosts, window.navigator is undefined.

How come?

(Chrome is 71)

1 Answers

From MDN -> https://developer.mozilla.org/en-US/docs/Web/API/StorageEstimate/quota

It appears this feature is only available in a secure context, aka https://

But it appears Chrome considers localhost to also be a secure context, so https:// is not required. I assume this is because localhost is commonly used for development purposes, and acquiring an SSL cert for local domains can be tricky.

More info at https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts which confirms file:// and localhost to be considered secure. if (window.isSecureContext) is available to test the status.

Related