简体   繁体   English

文件API,网络工作者和Chrome / Chromium

[英]File API, web workers, and Chrome/Chromium

The following minimal HTML file results in an error in the browser's console. 以下最小HTML文件导致浏览器控制台出错。 File is undefined when accessed from a web worker in Chrome. 从Chrome中的Web工作人员访问时, File未定义。

I am somewhat puzzled by this: it is working perfectly well with Firefox and I'd expect Chrome to have this already ironed out, at in a development version (the problem seems present in Chrome 22, 23, and 24). 我对此感到有些困惑:它与Firefox完美配合,我希望Chrome能够在开发版本中解决这个问题(Chrome 22,23和24中出现问题)。

Am I missing something, or is there a workaround to get it to work with Chrome (or may be even other browsers) ? 我是否遗漏了某些内容,或者是否有解决方法可以将其与Chrome(或者甚至是其他浏览器)配合使用?

<html>
<body>
<script type="text/javascript">
// File seems to be defined
var slice = File.prototype.webkitSlice;

window.URL = window.URL || window.webkitURL;
// File is not defined when creating the worker below
var blob = new Blob(["var slice = File.prototype.webkitSlice;"]);
var blobURL = window.URL.createObjectURL(blob);

// Getting:
// Uncaught TypeError: Cannot read property 'prototype' of undefined 
var worker = new Worker(blobURL);
</script>
</body>
</html>

If you change File to Blob , your script works. 如果将File更改为Blob ,则脚本可以正常工作。 File inherits from Blob . File继承自Blob

var blob = new Blob(["var slice = Blob.prototype.webkitSlice;"]);

For anyone following: crbug.com/147503 对于以下任何人: crbug.com/147503

WebkitSlice is deprecated in chrome latest version so use slice instead of it. WebkitSlice在chrome最新版本中已弃用,因此请使用slice而不是它。 and use it 并使用它

as ebidel stated 正如ebidel所说

var blob = new Blob(["var slice = Blob.prototype.slice;"]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM