我正在开发一个使用Web worker的项目.
在我的脑子部分,我有这个代码:
var worker = new Worker("worker.js");
// More code
Run Code Online (Sandbox Code Playgroud)
这在Safari中运行良好,但Chrome报告以下错误:
Uncaught SecurityError: Failed to create a worker: script at '(path)/worker.js' cannot be accessed from origin 'null'.
为什么这在Safari中完美运行而不是Chrome?我该如何解决?
谢谢.
我正在尝试使用 physi.js 库 ()。我遵循了给出的所有步骤:
https://github.com/chandlerprall/Physijs/wiki/Basic-Setup
但是,我得到了错误:
Uncaught SecurityError: Failed to construct 'Worker': Script at 'file://172.16.159.200/js/physijs_worker.js' cannot be accessed from origin 'null'.
Run Code Online (Sandbox Code Playgroud)
我试图更深入,并看到该行的问题:
this._worker = new Worker( Physijs.scripts.worker || 'physijs_worker.js' );
Run Code Online (Sandbox Code Playgroud)
是什么导致了这个问题?浏览器是谷歌浏览器。我检查过,文件“physijs_worker.js”出现在正确的位置。