【问题标题】:Why is navigator.storage undefined in latest Chrome?为什么 navigator.storage 在最新的 Chrome 中未定义?
【发布时间】:2021-04-07 21:28:29
【问题描述】:

我在本地开发时尝试在http://0.0.0.0:5000 上使用navigator.storage,但navigator.storageundefined

navigator.storage 何时/为什么可以未定义?

我在 Chrome 77 中。

【问题讨论】:

  • 它是在 77.0.3865.120 上为我定义的,Win 10,你的版本是什么?
  • 来自文档:此功能仅在安全上下文 (HTTPS) 中可用,在部分或所有支持的浏览器中可用。 您是否在本地主机上使用 HTTPS?
  • @KostasX 啊,我没有在 localhost 上使用 HTTPS。也许就是这样。
  • Chrome 中似乎没有为我返回 HTTPS,但 http://0.0.0.0:5000 无论如何都不是真实地址。你的意思是用 http://127.0.0.1:5000 代替 localhost。
  • Localhost 即使没有 HTTPS 也是一个安全的上下文,但你必须使用(并且应该使用)http://127.0.0.1:5000/ = http://localhost:5000/

标签: javascript html local-storage navigator


【解决方案1】:

根据@Ry- 的评论,使用http://localhost:5000http://127.0.0.1:5000 代替http://0.0.0.0:5000 可以解决问题。

由于某种原因,浏览器决定在访问 http://0.0.0.0 上的 URL 时使 navigator.storage 不可用。

【讨论】:

    【解决方案2】:

    我只是没有在 Chrome 控制台中正确解决承诺:

    await navigator.storage.estimate()
    

    【讨论】:

    • 你可以做await navigator.storage.estimate()。不需要额外的承诺,因为estimate() 已经返回了一个承诺。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 2014-05-30
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多