【问题标题】:How do I read from a file located inside a Chrome extension bundle? [duplicate]如何读取位于 Chrome 扩展包内的文件? [复制]
【发布时间】:2016-09-06 05:43:54
【问题描述】:

互联网上的每个页面似乎都为此提出了不同的选择,谁知道哪些是弃用的,哪些不是。从扩展包中读取文件的“正确”方法是什么?我不想将数据内联到脚本文件本身,因为这是一种糟糕的做法,而且会消耗不必要的内存。

【问题讨论】:

    标签: google-chrome-extension


    【解决方案1】:

    Fetch 是最新且最简单的。它适用于所有情况,除了在运行时获取打包文件的列表,这需要chrome.runtime.getPackageDirectoryEntry

    fetch("manifest.json").then(function(response) {
     return(response.json())
    }).then(function(manifest) {
     console.log(manifest)
    })
    

    https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

    【讨论】:

      猜你喜欢
      • 2015-05-05
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-08
      • 2014-01-26
      相关资源
      最近更新 更多