用chrome扩展名列出一个本地目录 [英] List a local directory with chrome extension

查看:154
本文介绍了用chrome扩展名列出一个本地目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个chrome扩展,扫描一个本地目录中的新文件...
但是,如果我将文件:// *权限添加到清单,我可以访问内部文件浏览器chrome with

xmlhttp.open(GET,file:// C:/ Users / username / Desktop /,false);
xmlhttp.send();
console.log(xmlhttp.response);



从响应中我可以提取文件的URL并在扩展中使用。

现在我的问题是:还有其他方法吗?上面的方法似乎更像是一个解决方法,如果更改了chrome的文件浏览器,它很容易中断...

解决方案

不得不在Chrome扩展中在本地机器上做些什么,我总是创建一个接受通过HTTP连接的小程序,并且像普通程序那样工作,通过POST使用JSON来执行命令。这给了你很大的灵活性,因为它基本上允许你编写一个Chrome扩展,可以做任何桌面程序可以做的事情。



然而,这有很大的缺点,而且只有在绝对必要时才应该这样做。例如:


  • 除非要为每个操作系统编写代理程序,否则无法在所有操作系统上执行此操作。 / li>
  • 无法通过Google的分机托管服务来安装该扩展程序。

  • 您必须编写你自己的安装程序来注册扩展名
  • 有这样一个非常真实的安全考虑。您将打开执行命令的Web服务。非常确定你没有暴露用户。在所有的现实中,如果你正在制作一个文件浏览器,你可能正在暴露用户。这将是由你来解决这个安全漏洞,就像你正在创建任何其他的Web服务。


I'm trying to create a chrome extension which scans a local directory for new files ... However, if I add the file://* permission to the manifest I can access the internal file browser of chrome with

xmlhttp.open("GET","file://C:/Users/username/Desktop/",false); xmlhttp.send(); console.log(xmlhttp.response);

From the response I could extract the file URLs and use them in my extension.

My question is now: Are there other approaches? The above way seems more like a workaround and easily breaks if chrome's file browser is changed ...

解决方案

Any time I've had to do something on the local machine from a Chrome extension, I've always created a small program that accepts connections via HTTP, and does the work as a normal program, taking commands with JSON over POST. This gives you great flexibility, as it essentially allows you to write a Chrome extension that can do anything a desktop program can do.

However, there are great downsides to this, and you should only do it if absolutely necessary. For instance:

  • You can't do this for all operating systems, unless you're going to write an agent for every OS.
  • The extension cannot be installed from Google's extension hosting.
  • You must write your own installation program that registers the extension.
  • There are very real security considerations to worry about with this. You will be opening up a web service that executes commands. Be very sure that you are not exposing the user. In all reality, if you are making a file browser, you probably are exposing the user. It will be up to you to fix this security hole, as if you were creating any other web service.

这篇关于用chrome扩展名列出一个本地目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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