Processing
 

Chrome can't load web worker

28/01/2014 14:36#1

Progo

Member

Joined at: 10 months ago

Post: 4

Thank: 0

Thanked: 0

I am working on a project that uses a web worker.

In my head section I have this code:

var worker = new Worker("worker.js"); // More code 

This works fine in Safari, but Chrome reports the following error:

Uncaught SecurityError: Failed to create a worker: script at '(path)/worker.js' cannot be accessed from origin 'null'.

Why does this work perfectly in Safari but not Chrome? How do I fix this?

Thank you.

21/04/2014 22:09Top#2

Joined at: 7 months ago

Post: 1

Thank: 0

Thanked: 0

For good reasons, Chrome doesn't let you load web workers when running scripts from a local file. Note: Firefox won't work either. Try Safari. :)

17/06/2014 15:08Top#3

Joined at: 11 months ago

Post: 2

Thank: 0

Thanked: 0

The problem has been properly explained by Noble Chicken but I have a more general solution for it. Instead of installing wamp or xamp, with python you can navigate to the folder your project is hosted in and type: python -m http.server

Just that and you will have a running server on that folder, reachable from localhost.

30/10/2015 09:05Top#4

Joined at: 10 months ago

Post: 6

Thank: 0

Thanked: 0

I use a workaround. Chrome is just a bit retarded, so it blocks Worker but not <script>. Hence the best way to make a universal solution is this:

function worker_function() {     // all code here } // This is in case of normal worker start if(window!=self)   worker_function(); 

You then link it as normal <script src="...". And once the function is defined, you use this abomination of a code:

new Worker(URL.createObjectURL(new Blob(["("+worker_function.toString()+")()"], {type: 'text/javascript'}))); 
22/04/2014 02:47Top#5

Thara

Member

Joined at: 7 months ago

Post: 1

Thank: 0

Thanked: 0

I have problem as you post too but now i can find solution of it. You have to run it with localhost (wamp or xamp). It will done.

17/02/2016 18:10Top#6

Mickael

Member

Joined at: 7 months ago

Post: 2

Thank: 0

Thanked: 0

You can also use the --allow-file-access-from-files flag when you launch Chrome.

Example for MacOsX :

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files 

More info : Web worker settings for chrome

04/04/2015 09:24Top#7

Joined at: 7 months ago

Post: 1

Thank: 0

Thanked: 0

you need a web server for request from HTTP protocol Instead of local file and work correctly :)

16/10/2015 18:28Top#8

Joined at: 7 months ago

Post: 2

Thank: 0

Thanked: 0

Chrome load the file but cannot run it. Use Firefox. It's working for me.

10/04/2016 11:33Top#9

Joined at: 7 months ago

Post: 1

Thank: 0

Thanked: 0

A probably reason is chrome doesn't let you load web workers when running scripts from a local file. And I try run the code on my firefox, can not either.

15/10/2015 17:32Top#10

salfter

Member

Joined at: 7 months ago

Post: 1

Thank: 0

Thanked: 0

With Python 2.x being more widely deployed than Python 3.x, something like python -m SimpleHTTPServer 8000 is more generally applicable, and not just for Mac OS X. I found it necessary for use under Cygwin, for instance.

With that in place, this example worked like a champ.

19/06/2016 17:21Top#11

Joined at: 7 months ago

Post: 1

Thank: 0

Thanked: 0

If you have Node installed, you can try this.

Install local-web-server globally. (once and for all)

$ npm install -g local-web-server 

Now you can use it in any folder that you want to access the contents through http .

$ ws 

Navigate to http://localhost:8000 (default port: 8000)

Similar articles

Chrome, THREE.js: Cross-origin image load denied

5 years ago - Reply: 5 - Views: 269

Prevent Google Chrome Log XMLHttpRequest

3 years ago - Reply: 5 - Views: 276

How can I include ChromeDriver in a JAR?

3 years ago - Reply: 3 - Views: 81

Chrome geolocation not working on any site

3 years ago - Reply: 1 - Views: 46

wrong borders' width in android browser

3 years ago - Reply: 4 - Views: 206

Uncaught SyntaxError: Unexpected token < On Chrome

3 years ago - Reply: 10 - Views: 468

Flashdata not getting cleared in Codeigniter

3 years ago - Reply: 5 - Views: 57

Illegal access Javascript error in Chrome

3 years ago - Reply: 1 - Views: 51

ng-repeat not updating in Chrome

3 years ago - Reply: 1 - Views: 81

Applying border to a checkbox in Chrome

4 years ago - Reply: 2 - Views: 118

open browser plugin using access vba

3 years ago - Reply: 1 - Views: 25

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re