最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Not allowed to load local resource: <blob_url> while accessing url in content script - Stack Overflow

programmeradmin13浏览0评论

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

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

Share Improve this question edited Jan 28, 2014 at 11:59 gvijay asked Jan 28, 2014 at 10:41 gvijaygvijay 1,4992 gold badges12 silver badges17 bronze badges 4
  • You just can't use local files to do this. You must run your script on a webserver. – Florent Commented Jan 28, 2014 at 10:47
  • Did you mean content_scripts from chrome extensions can only access non local url ? – gvijay Commented Jan 28, 2014 at 11:55
  • Go to chrome://extensions, and check "allow access to file url" on your extension. – Alejandro Silvestri Commented Jan 28, 2014 at 15:43
  • @YoArgentino : already checked. – gvijay Commented Jan 28, 2014 at 16:20
Add a ment  | 

1 Answer 1

Reset to default 3

This looks like a Chrome bug, see: https://code.google./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...

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论