本文是小编为大家收集整理的关于通过npm窗口安装casperjs时,试图访问框架的javascript不安全的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我通过NPM在Windows Machina上安装了Casperj和Phantomjs.但是我得到了这个问题.
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上的主分支,但尚未作为Casperjs的发行版(最新是1.1-Beta3).
解决此问题的最简单方法是降级到phantomjs 1.9.7.由于您使用的是NPM,因此很容易使用
完成npm -g install phantomjs@1.9.7-15
phantomjs版本与NPM Phantomjs软件包匹配到1.9.7,然后所有内容都破裂了.您可以使用npm show phantomjs.
检查版本如果您降级到1.9.7版,则必须使用请求HTTPS资源的网站使用--ssl-protocol=any命令行选项运行.原因显示在我的答案中在这里.
正确的方法解决此问题的方法是从git 安装新版本.这将使您不仅可以使用phantomjs 1.9.8没有其他错误行,而且可以使用phantomjs 2,而casperjs 1.1-beta3则无法使用.
参考:
github essue#1068
casperjs#1139
一个>
其他推荐答案
使用 " phantomjs": "^1.9.9" 对于caseperjs
casperjs --ssl-protocol=tlsv1 test run.js
问题描述
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.
推荐答案
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).
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 phantomjs@1.9.7-15
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.
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.
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.
References:
GitHub issue #1068
Workaround for CasperJS #1139
PhantomJS issue on SO
其他推荐答案
Use "phantomjs": "^1.9.9" And for caseperJs
casperjs --ssl-protocol=tlsv1 test run.js