javascript 在内容脚本中访问 url 时不允许加载本地资源:<blob_url>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21403347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Not allowed to load local resource: <blob_url> while accessing url in content script
提问by gvijay
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.
我正在尝试在我的内容脚本中读取本地文件。我正在使用扩展弹出窗口中的文件对话框上传本地文件,然后将 url 作为消息发送到内容脚本。
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.
我从 chrome 扩展的弹出 js 中的本地读取文件创建了一个 blob URL,然后将其作为消息传递给内容脚本,在那里我尝试通过 xhr 获取它。我验证了在内容脚本中正确接收了 url,并且在 chrome 中加载时该 url 具有正确的内容。我在附加代码的最后一行收到此错误。
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
我在清单权限中添加了“file:///*”,但我不确定是否有遗漏的地方
采纳答案by brucek
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...
这看起来像一个 Chrome 错误,请参阅:https: //code.google.com/p/chromium/issues/detail?id=295829- 我也在想办法解决它,但还没有任何运气...