gpt4 book ai didi

google-chrome - Chrome 扩展程序 : How to List The Contents of Local Directory

转载 作者:行者123 更新时间:2023-12-04 12:42:25 25 4
gpt4 key购买 nike

我想做的事:

我想创建一个用于测试目的的 Chrome 扩展程序。该扩展名应该可以 访问本地 上的目录和文件硬盘 .

我是如何做到的:

我请求了 file:///* 的权限在我的 manifest.json文件。然后我确保复选框 Allow access to file URLs被检查。然后我为一个文件制作了一个 XHR:

  var xhr = new XMLHttpRequest();  
xhr.open("GET", 'file://c:/dir/file.name', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();

...以及整个目录的 XHR:
  var xhr = new XMLHttpRequest();  
xhr.open("GET", 'file://c:/dir/', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();

...对于整个文件系统:
  var xhr = new XMLHttpRequest();  
xhr.open("GET", 'file:///', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();

发生了什么:
  • 我能够为我的文件请求获得​​正确的响应。
  • 当我请求一个目录时,我收到了 Chrome 的源代码
    默认的人类可读目录概述:

  • .
      <html>
    <head>
    <script>

    [...]
      </script>
    <style>

    [...]
      </style>
    <title id="title"></title>
    </head>
    <body>
    <div id="listingParsingErrorBox" i18n-values=".innerHTML:listingParsingErrorBoxText"></div>
    <span id="parentDirText" style="display:none" i18n-content="parentDirText"></span>
    <h1 id="header" i18n-content="header"></h1>
    <table id="table">
    <tr class="header">
    <td i18n-content="headerName"></td>
    <td class="detailsColumn" i18n-content="headerSize"></td>
    <td class="detailsColumn" i18n-content="headerDateModified"></td>
    </tr>
    </table>
    </body>
    </html>

    [...]
      <script>start("C:\\dir\\");</script>
    <script>addRow("..","..",1,"0 B","11/11/11 11:11:11 AM");</script>
    <script>addRow("file.name","file.name",0,"4.9 kB","11/11/11 11:11:11 PM");</script>
  • 当我请求整个文件系统时,出现错误。

  • 我的问题:

    我能够阅读简单的文件。但是我的分机怎么能得到一个不错的 目录的机器可读概述 还是整个文件系统?谢谢。

    编辑:我知道 FileSystem API 旨在访问沙盒 filesystem:// ,但也许 Chrome 允许扩展程序也访问 file:// .我找不到任何关于 file:// 的文档从 Chrome 扩展程序访问,所以我只能猜测。

    最佳答案

    独立 Chrome 中没有内置功能。

    解析目录列表页面的替代方法:

  • NPAPI 扩展(C++,推荐)
  • 具有文件系统访问权限的本地服务器。 NodeJS is a good pick .
  • 关于google-chrome - Chrome 扩展程序 : How to List The Contents of Local Directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11452758/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com