Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 544
pinoyyid Avatar asked Dec 23 '18 20:12

pinoyyid


People also ask

What is the use of storage estimate?

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.

What is navigator storage?

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.


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.

like image 93
Keith Avatar answered Oct 01 '22 13:10

Keith