如何从Chrome扩展访问沙箱外的文件和目录结构? [英] How to access file and directory structure outside the sandbox from chrome extension?

查看:703
本文介绍了如何从Chrome扩展访问沙箱外的文件和目录结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道暴露给本地客户端的文件系统api,但似乎无法在沙箱外访问。有一个API允许通过提示窗口访问沙箱外。



如果我的理解正确,就不能访问目录。我最近遇到了chrome dev,它允许您在任何目录中创建工作区,并允许在目录级别进行剪切,复制和粘贴操作。我想知道他们是如何获得沙箱外的文件和目录的。



我引用的扩展名是:
https://github.com/dart-lang/chromedeveditor

解决方案

Chrome开发者编辑器不是Chrome扩展程序,而是Chrome应用程序。 Chrome应用可以使用 chrome.fileSystem API来读取和写入用户选择的目录和文件。



扩展只能使用非扩展特定的 FileSystem API 。唯一允许扩展在虚拟文件系统之外写入的API是 chrome .downloads.download ,它允许扩展将文件保存到用户选择的目录中。在此操作之后,扩展名可以删除,但不能修改(下载的)文件。



(如果您的扩展程序请求 file:// * / * < all_urls> 权限勾选允许访问文件网址复选框扩展页面,那么你的扩展将具有对用户文件系统的只读访问权;如果你想追求这种方法,请阅读 https:// stackoverflow .com / a / 19493206

I know about file system api exposed to native client but it seems it can not allow access outside sandbox. There is an api which can allow access outside sandbox by a prompt window.

If my understanding is correct it can not allow access to a directory. I recently came across chrome dev which allow you to create workspace in any directory and allows cut, copy and paste operations even at directory level. I am wondering how are they getting the access to files and directory outside sandbox.

The extension which I am referring is: https://github.com/dart-lang/chromedeveditor

解决方案

Chrome Dev Editor is not a Chrome extension, but a Chrome App. Chrome Apps can use the chrome.fileSystem API to read and write to directories and files that are selected by a user.

Extensions can only access a sandboxed filesystem using the non-extension-specific FileSystem API. The only API that allows extensions to write outside the virtual filesystem is chrome.downloads.download, which allows extensions to save a file to a directory as chosen by the user. After this operation, an extension can delete, but not modify the (downloaded) file.

(and if your extension requests the file://*/* or <all_urls> permission and the user ticks the "Allow access to file URLs" checkbox at the Extensions page, then your extension will have read-only access to the user's filesystem; if you want to pursue this method, read https://stackoverflow.com/a/19493206)

这篇关于如何从Chrome扩展访问沙箱外的文件和目录结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆