Windows安装casperjs时

Windows安装casperjs时

本文介绍了通过npm Windows安装casperjs时,不安全的javascript尝试访问框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过npm在Windows machina上安装了casperjs和phantomjs.但是我遇到了这个问题.

I have installed casperjs and phantomjs on my windows machina via npm. However I get this issue.

C:\>casperjs sample.js

C:\>Unable to open file: sample.js
Unsafe JavaScript attempt to access frame with URL about:blank from frame
with URL file:///C:/Users/vini/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js.
Domains, protocols and ports must match.

推荐答案

这是CasperJS和1.9.8版本的PhantomJS的一个已知问题.它不执行任何操作,并且错误仅在退出时打印.它们不会干扰您的脚本.有一种解决方法,它已合并到GitHub上的master分支中,但尚未作为CasperJS的发行版提供(最新版本为1.1-beta3).

This is a known issue with CasperJS and the 1.9.8 version of PhantomJS. It doesn't do anything and the errors are only printed during exit. They don't interfere with your script. There is a workaround and it was merged into master branch on GitHub, but it is not available as a release of CasperJS yet (latest is 1.1-beta3).

解决此问题的最简单的方法是降级到PhantomJS 1.9.7.由于您使用的是NPM,因此只需

The easiest way to solve this is to downgrade to PhantomJS 1.9.7. Since you're using NPM it is easily done with

npm -g install [email protected]

PhantomJS版本与NPM phantomjs软件包版本匹配,直到1.9.7,然后一切都中断了.您可以使用npm show phantomjs检查版本.

The PhantomJS versions match with the NPM phantomjs package versions up until 1.9.7, then everything breaks. You can check the versions with npm show phantomjs.

如果降级到1.9.7版,则对于请求https资源的站点,必须使用--ssl-protocol=any命令行选项运行.原因显示在我的答案中此处.

If you downgrade to version 1.9.7, you will have to run with the --ssl-protocol=any commandline option for sites that request https resources. The reason is shown in my answer here.

解决此问题的正确方法从git 安装新版本.这样,您不仅可以使用没有附加错误行的PhantomJS 1.9.8,而且可以使用CasperJS 1.1-beta3无法实现的PhantomJS 2.

The proper way to solve this is to install a new version from git. This will enable you to not only use PhantomJS 1.9.8 without the additional error lines, but also PhantomJS 2 which would not be possible with CasperJS 1.1-beta3.

参考文献:
GitHub问题#1068
CasperJS#1139的解决方法
关于SO的PhantomJS问题

References:
GitHub issue #1068
Workaround for CasperJS #1139
PhantomJS issue on SO

这篇关于通过npm Windows安装casperjs时,不安全的javascript尝试访问框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 02:41