"physi.js" causes the error: "Script cannot be accessed from origin 'null'"

时间:2015-05-12 22:28:50

标签: javascript three.js physics-engine physijs

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:

public class RollDice {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        int dice1;   // First Dice.
        int dice2;   // Second Dice.
        int total;   // Sum of the two rolls. 

        dice1 = (int)(Math.random()*6) + 1;
        dice2 = (int)(Math.random()*6) + 1;
        total = dice1 + dice2;

        System.out.println("Your first roll is " + dice1);
        System.out.println("Your second roll is  " + dice2);
        System.out.println("Your complete roll is " + total);

    }  

}  

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

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

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

3 个答案:

答案 0 :(得分:2)

在网络服务器上部署您的网站。没有Web服务器,我会得到同样的错误。

答案 1 :(得分:2)

浏览器不允许从本地文件创建工作程序,因为这将是一个安全问题。

另见这个问题:

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

答案 2 :(得分:1)

只需添加Chrome扩展程序即可 https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb?hl=en

并使用扩展程序启动index.html。现在它将在localhost中运行,不会有错误