4

I am trying to read in a local file in my content script. I am uploading a local file using file dialog at the extension popup and then sending the url to content script as a message.

I created a blob URL from a locally read file in my chrome extension's popup js, and then passed it as a message to content script, where I tried fetching it through xhr. I verified that the url was received correctly in content script and that the url when loaded in chrome has the right content. I get this error in the last line of attached code.

Not allowed to load local resource: blob:chrome-extension%3A//kbapkffopcceekghjelpjphdebhdkohi/9e40f540-9eb8-4ea6-ae7d-6ad52e7d2f89

Code :-

JSONFromUrl = function (url) {
  var xhr = new XMLHttpRequest();
  xhr.open('GET', url, true);
  xhr.responseType = 'blob';
  xhr.onload = function(e) {
  if (this.status == 200) {
  console.log("success");
    };
  }
  };
  xhr.send();
};

I have added "file:///*" in my manifest permissions, but I am unsure if there is something I might have missed

4
  • You just can't use local files to do this. You must run your script on a webserver.
    – Florent
    Jan 28, 2014 at 10:47
  • Did you mean content_scripts from chrome extensions can only access non local url ?
    – gvijay
    Jan 28, 2014 at 11:55
  • Go to chrome://extensions, and check "allow access to file url" on your extension. Jan 28, 2014 at 15:43
  • @YoArgentino : already checked.
    – gvijay
    Jan 28, 2014 at 16:20

1 Answer 1

3

This looks like a Chrome bug, see: https://code.google.com/p/chromium/issues/detail?id=295829 - I'm trying to figure out a way to work around it too but haven't had any luck yet...

1
  • Likely. I managed to send file around as an arraybuffer, but I still feel passing a URL would have been much preferable.
    – gvijay
    Jan 30, 2014 at 12:14

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.