Answer the question
In order to leave comments, you need to log in
Chrome blocks worker execution, how to fix it?
There is an index.html file which is open in Chrome browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
if(!!window.Worker){
var worker = new Worker('task.js');
worker.postMessage();
}else{
console.log('Workers in not support!');
}
</script>
</body>
</html>
Uncaught SecurityError: Failed to construct 'Worker': Script at 'file:///I:/%7BH%7D/Andrey/LanAndDev/JavaScript/WebWorkers/task.js' cannot be accessed from origin 'null'.
Answer the question
In order to leave comments, you need to log in
Deploy a local web server and the error will go away. The problem is in the file:/// protocol - workers are prohibited when executing scripts from a local file.
Just put yourself a local server of some kind. For example:
https://github.com/gruntjs/grunt-contrib-connect
https://www.apachefriends.org/en/index.html
or something like that
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question