使用Chrome.filesystem时出错:Chrome.fileSystem未定义

时间:2014-12-11 09:57:44

标签: javascript google-chrome google-chrome-devtools google-chrome-app

我正在尝试制作可以访问本地文件系统的chrome App并监视特定目录以检查是否有新文件出现? ,所以我需要使用chrome.filesystem根据谷歌提供的这个代码,它给我的错误,chrome.filesystem未定义。

代码:

  chooseDirButton.addEventListener('click', function(e) {
          chrome.fileSystem.chooseEntry({type: 'openDirectory'}, function(theEntry) {
            if (!theEntry) {
              output.textContent = 'No Directory selected.';
              return;
            }
            // use local storage to retain access to this file
            chrome.storage.local.set({'chosenFile': chrome.fileSystem.retainEntry(theEntry)});
            loadDirEntry(theEntry);
          });
        });

清单文件:

{
  "manifest_version": 2,
  "name": "Test",
  "short_name": "Test",
   "minimum_chrome_version": "31",
  "description": "Description for Test",

  "version": "0.0.1.0",

  "icons": {
    "16": "assets/icon_16.png",
    "128": "assets/icon_128.png"
  },

  "app": {
    "background": {
      "scripts": ["background.js"],
      "persistent": false
    }
  },
"permissions": [
    {"fileSystem": ["write", "retainEntries", "directory"]},
    "storage","notifications","webview","http://*/*","fileSystem"
  ],
  "file_handlers": {
    "text": {
      "types": [
          "text/*"
      ]
    }
  }
}

background.js:

chrome.app.runtime.onLaunched.addListener(function(launchData) {
  chrome.app.window.create('index.html', {id:"fileWin", innerBounds: {width: 800, height: 500}}, function(win) {
    win.contentWindow.launchData = launchData;
  });
});
  

我如何使用chrome.filesystem?请帮忙。谢谢。

0 个答案:

没有答案