waaadim
waaadim

Reputation: 419

clientside filestorage can not read file from content_scripts

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"

Upvotes: 0

Views: 66

Answers (1)

gkalpak
gkalpak

Reputation: 48211

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.

Upvotes: 1

Related Questions