PhantomJS能够与WebWorkers合作吗?

时间:2022-05-23 01:23:20

Everytime when I try to test Web Worker via PhantomJS it gives me an error:

每次当我尝试通过PhantomJS测试Web Worker时,它都会给我一个错误:

SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.

SECURITY_ERR:DOM异常18:尝试突破用户代理的安全策略。

Does it mean that PhantomJS isn't able to work with WebWorkers or I need to set some configuration to make it work?

这是否意味着PhantomJS无法与WebWorkers合作,或者我需要设置一些配置才能使其工作?

E.g. I need to test a script which interacts with WebWorker (in my case worker.js file):

例如。我需要测试一个与WebWorker交互的脚本(在我的例子中是worker.js文件):

var worker = new Worker('doWork.js');
worker.addEventListener('message', function(e) {
  console.log('Worker said: ', e.data);
}, false);
worker.postMessage('Hello World');
phantom.exit();

And this is a code of Worker (dowork.js):

这是Worker(dowork.js)的代码:

self.addEventListener('message', function(e) {
  self.postMessage(e.data);
}, false);
phantom.exit();

And when I try to run it I got:

当我尝试运行它时,我得到了:

pavel@lenovo:~/phantom_test$ phantomjs worker.js 
SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.

  worker.js:1

1 个解决方案

#1


Your script will not work with the current release of PhantomJS 2. I assume you're using PhantomJS 2 (but this applies to PhantomJS 1 too).

你的脚本不适用于当前版本的PhantomJS 2.我假设你使用的是PhantomJS 2(但这也适用于PhantomJS 1)。

We had an issue when the main execution context didn't respect web-security option. And the fix for it was recently pushed (see https://github.com/ariya/phantomjs/commit/d938eddaf2039cc4d8a90704f736129edb8e1260)

当主执行上下文不尊重web-security选项时,我们遇到了问题。最近推出了它的修复程序(参见https://github.com/ariya/phantomjs/commit/d938eddaf2039cc4d8a90704f736129edb8e1260)

So, you have to wait for 2.0.1 release or build PhantomJS 2 from sources.

因此,您必须等待2.0.1版本或从源代码构建PhantomJS 2。

#1


Your script will not work with the current release of PhantomJS 2. I assume you're using PhantomJS 2 (but this applies to PhantomJS 1 too).

你的脚本不适用于当前版本的PhantomJS 2.我假设你使用的是PhantomJS 2(但这也适用于PhantomJS 1)。

We had an issue when the main execution context didn't respect web-security option. And the fix for it was recently pushed (see https://github.com/ariya/phantomjs/commit/d938eddaf2039cc4d8a90704f736129edb8e1260)

当主执行上下文不尊重web-security选项时,我们遇到了问题。最近推出了它的修复程序(参见https://github.com/ariya/phantomjs/commit/d938eddaf2039cc4d8a90704f736129edb8e1260)

So, you have to wait for 2.0.1 release or build PhantomJS 2 from sources.

因此,您必须等待2.0.1版本或从源代码构建PhantomJS 2。