0

The problem here is that the things that I'm writing in popup.js with window.webkitRequestFileSystem can be read from there, but I can not be read from content.js.

PS: the code is the same in both files

manifest.json

 {
  "manifest_version": 2,

  "browser_action": {
    "default_popup": "action.html"
  },
  "content_scripts": [
    {
      "js": ["content.js"]
    }
  ],
  "background": {
    "scripts": ["background.js"]
  },
  "permissions": [
    "unlimitedStorage",
  ]
}

action.html

// Here is the popup.js file included

popup.js

window.webkitRequestFileSystem(window.PERSISTENT, 0, readFromFileStorage, errorHandler);

function readFromFileStorage(fs) {
  fs.root.getFile('file.txt', {}, function(fileEntry) {
    fileEntry.file(function(file) {
       var reader = new FileReader();

        reader.onloadend = function(e) {
          console.log(this.result);
        };

       reader.readAsText(file);
    }, errorHandler);
  }, errorHandler);
}

content.js

window.webkitRequestFileSystem(window.PERSISTENT, 0, readFromFileStorage, errorHandler);
// the function 'readFromFileStorage' is the same as in "popup.js"
waaadim
  • 409
  • 5
  • 17

1 Answers1

1

According to the docs:

The security boundary imposed on file system prevents applications from accessing data with a different origin.

popup.js and a content script injected into a webpage are considered two different origins, so you cannot access the data stored in one's filesystem from the other.
Based on your requirements and particula setup, Message Passing you could use message passing to communicate and pass data between a content script and the popup or background page.

gkalpak
  • 47,844
  • 8
  • 105
  • 118
  • thanks, didn't knew that PS. This answer here about `message passing` was easier for me to understand than the official google documentation. http://stackoverflow.com/questions/3937000/chrome-extension-accessing-localstorage-in-content-script – waaadim Nov 01 '13 at 14:35