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)
The estimate() method of the StorageManager interface asks the Storage Manager for how much storage the current origin takes up ( usage ), and how much space is available ( quota ). This method operates asynchronously, so it returns a Promise which resolves once the information is available.
storage. Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers. The Navigator. storage read-only property returns the singleton StorageManager object used to access the overall storage capabilities of the browser for the current site or app.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With