最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get filenames for all files in a chrome extension directory? - Stack Overflow

programmeradmin5浏览0评论

I'm writing a chrome extension which will add custom images to a webpage. I want the users to put all their images in the "backgrounds" folder, and I want my extension to be able to retrieve the file names of every file in the "backgrounds" directory in the extensions folder. It seems like there is no way to do this in chrome extensions. When I try to use the chrome fileSystem API, I get this error:

There were warnings when trying to install this extension:
'fileSystem' is only allowed for packaged apps, but this is a extension.

How can I do this?

I'm writing a chrome extension which will add custom images to a webpage. I want the users to put all their images in the "backgrounds" folder, and I want my extension to be able to retrieve the file names of every file in the "backgrounds" directory in the extensions folder. It seems like there is no way to do this in chrome extensions. When I try to use the chrome fileSystem API, I get this error:

There were warnings when trying to install this extension:
'fileSystem' is only allowed for packaged apps, but this is a extension.

How can I do this?

Share Improve this question edited Jan 26, 2016 at 5:11 Sungguk Lim 6,2287 gold badges46 silver badges64 bronze badges asked Jan 25, 2016 at 23:45 user2936448user2936448 3494 silver badges17 bronze badges 3
  • This ment thread may be useful: github./Wykks/Untamed-Now-Playing-Next/issues/40 – dsgriffin Commented Jan 25, 2016 at 23:51
  • @daniel I learned nothing from this and am actually more confused now. – user2936448 Commented Jan 26, 2016 at 0:13
  • 1 Basically you can only use fileSystem with Chrome apps, not extensions. It talks about separating aspects of the extension/app into different things but yeah.. – dsgriffin Commented Jan 26, 2016 at 0:14
Add a ment  | 

1 Answer 1

Reset to default 8

You can get read-only access to your extension's folder with chrome.runtime.getPackageDirectoryEntry, with which you can work using the HTML5 FileSystem API.

However, this will not allow you to do what you want to do.

While you're developing an extension, it will work fine, as Chrome does not mind changes to the extension's folder - they are expected.

However, when the extension is deployed to users, Chrome will maintain a cryptographic hash of the extension folder's contents. In case there are any external modification to the files, the extension is considered promised and is forcibly disabled.

So you should consider other approaches instead, such as:

  • using the above HTML5 FileSystem API to have a virtual persistent filesystem to which you can let the user "upload" files through your UI;
  • storing data as blob:/data: URIs in chrome.storage or IndexedDB;
  • asking the user to put the files in a cloud drive your extension can access using its usual API.
发布评论

评论列表(0)

  1. 暂无评论