Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File API, web workers, and Chrome/Chromium

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>
like image 908
lgautier Avatar asked Dec 14 '25 10:12

lgautier


1 Answers

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

like image 84
ebidel Avatar answered Dec 16 '25 00:12

ebidel