我尝试这个非常简单的脚本:
debugger;
var casper = require('casper').create();
casper.on('remote.message', function(msg) {
this.echo('remote: ' + msg);
})
casper.start('http://stackoverflow.com');
casper.thenEvaluate(function(){
var ps = document.querySelectorAll('*');
console.log("DEBUG ps.length="+ps.length);
})
casper.run(function() {
this.exit();
});
然后我跑
casperjs --remote-debugger-port=9035 script.js
然后我打开http://127.0.0.1:9035在 Chrome 中,单击 bootstrap.js
链接,然后打开 console
选项卡,输入 __run()
,但全部挂起。
此功能应该正常工作吗?
最佳答案
我也被困在这个问题上几个小时,并没有完全解决这个问题。
不过我可以给你一些提示。
- 使用其他浏览器,就我而言,使用 Safari 而不是 Chrome。 https://github.com/ariya/phantomjs/issues/12864
使用phantomjs检查代码是否正常工作。
//casperscript.js phantom.casperPath = '/path/to/casperjs'; phantom.injectJs(phantom.casperPath + '/bin/bootstrap.js');
var casper = require('casper').create(); //...
在第1步/第2步之后,也许您仍然会遇到其他问题(例如崩溃)。因此您最好添加资源监听器或捕获屏幕截图以查看到底发生了什么。
关于javascript - '--remote-debugger-port' 应该与 casper 1.1.2 和 phantomjs 2.1.1 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42194379/