2

I am trying to make chrome App which can access localfile system and keep watch on specific directory to check if any new file came or not? , so i need to use chrome.filesystem for that as per this code provided by google , its giving me error that chrome.filesystem is undefined.

Code :

  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);
          });
        });

Menifest File :

{
  "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;
  });
});

How can i use chrome.filesystem ? please help. Thank you.

10
  • Edit the question to include your manifest file
    – Xan
    Dec 11, 2014 at 9:59
  • Please take a look i added menifest file also. Dec 11, 2014 at 10:02
  • Manifest seems okay.. Where is this code, and how are you opening the page with this code?
    – Xan
    Dec 11, 2014 at 10:04
  • you can check that code here : github.com/GoogleChrome/chrome-app-samples/blob/master/samples/… Dec 11, 2014 at 10:06
  • 2
    I realize this code came from a Google example, but the way to debug things like this is to remove extraneous stuff until you get down to the bare minimum that shows the problem. Toss out all the stuff about notifications, window properties, and everything unrelated to chrome.fileSystem.chooseEntry. If that works, start adding the other stuff back in until it breaks. You are drowning in unnecessary complexity! (The principle I'm using is this: 1. chrome.fileSystem.chooseEntry is well know to be defined. 2. Your app does not work. 3. The answer must therefore lie between the two.) Dec 12, 2014 at 15:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.