5

I was trying to play with physi.js library (). I followed all the steps given:

https://github.com/chandlerprall/Physijs/wiki/Basic-Setup

However, I got the error:

Uncaught SecurityError: Failed to construct 'Worker': Script at 'file://172.16.159.200/js/physijs_worker.js' cannot be accessed from origin 'null'.

I tried to go deeper, and saw that the problem with the line:

this._worker = new Worker( Physijs.scripts.worker || 'physijs_worker.js' );

What did cause that issue? The browser is Google Chrome. I checked, the file "physijs_worker.js" appears in the right location.

Darius Miliauskas
  • 3,283
  • 4
  • 30
  • 50
  • Related post [here](https://stackoverflow.com/q/21408510/465053), [here](https://stackoverflow.com/q/37718656/465053) and [here](https://stackoverflow.com/q/6811398/465053). – RBT Nov 09 '17 at 05:09
  • https://benohead.com/cross-domain-cross-browser-web-workers/ – Ahmad Samilo Sep 11 '18 at 11:05

3 Answers3

3

Browsers don't allow creating workers from local files because that would be a security issue.

See also this question:

Why does not Chrome allow Web Workers to be run in JavaScript?

Community
  • 1
  • 1
marsze
  • 13,389
  • 5
  • 38
  • 53
2

Deploy your website on a web server. Without the web server I get the same error.

RBT
  • 21,293
  • 19
  • 144
  • 210
Rendolf
  • 86
  • 1
2

Just add the chrome extension https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb?hl=en

and use the extension to launch your index.html. As now it will be running in localhost, there will be no error

Fast Mani
  • 151
  • 7