Reputation: 11543
The following minimal HTML file results in an error in the browser's console. File
is undefined when accessed from a web worker in Chrome.
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).
Am I missing something, or is there a workaround to get it to work with Chrome (or may be even other browsers) ?
<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>
Upvotes: 3
Views: 1283
Reputation: 9586
WebkitSlice
is deprecated in chrome latest version so use slice
instead of it. and use it
as ebidel stated
var blob = new Blob(["var slice = Blob.prototype.slice;"]);
Upvotes: 0
Reputation: 24109
If you change File
to Blob
, your script works. File
inherits from Blob
.
var blob = new Blob(["var slice = Blob.prototype.webkitSlice;"]);
For anyone following: crbug.com/147503
Upvotes: 3