2017-02-12 57 views
1

我试试这个非常简单的脚本:是'--remote-debugger-port'应该与casper 1.1.2和phantomjs 2.1.1一起使用?

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 

然后我在Chrome中打开http://127.0.0.1:9035,点击bootstrap.js链接,然后打开console选项卡,键入__run(),但都得到挂起。

是这个功能应该正常工作?

回答

1

我还停留在这个几个小时,并没有完全解决这个问题。

不过我可以给你一些提示。

  1. 使用其他浏览器,在我的情况下,使用Safari而不是Chrome。 https://github.com/ariya/phantomjs/issues/12864
  2. 使用phantomjs检查工作的代码好。

    // casperscript.js phantom.casperPath ='/ path/to/casperjs'; phantom.injectJs(phantom.casperPath +'/bin/bootstrap.js');

    var casper = require('casper')。create(); // ...

  3. 第一步/第二步后,也许你仍然可以得到其他问题(比如像崩溃)。所以你最好添加资源监听器或捕捉屏幕截图,看看到底发生了什么。

相关问题