Ind*_*ing 24 intellij-idea javascript-debugger webstorm phantomjs casperjs
我可以在PhantomJS和/或CasperJS上使用交互式JS调试器吗?
Ind*_*ing 15
我没有完全解决这个问题,但我确实减轻了痛苦.
PhantomJS提供了一个命令行参数来启用webkit的远程调试器.AFAIK,PhantomJS启动服务器并<head>
使用熟悉的浏览器内调试器将脚本转储到网页中.它实际上非常好,有断点等.但是,切换到在终端中手动挖掘随机命令行参数和脚本的路径是非常恼人的.
因此,我使用IntelliJ的"外部工具"功能来启动Bash脚本,该脚本可以杀死任何以前的调试会话,启动PhantomJS,然后在Chrome中打开该页面.
#!/bin/bash
lsof -i tcp@0.0.0.0:9000 #list anything bound to port 9000
if [ $? -eq 0 ] #if something was listed
then
killall 'phantomjs'
fi
/usr/local/Cellar/phantomjs/2.0.0/bin/phantomjs --remote-debugger-port=9000 $1 &
# --remote-debugger-autorun=yes <- use if you have added 'debugger;' break points
# replace $1 with full path if you don't pass it as a variable.
sleep 2; #give phantomJS time to get started
open -a /Applications/Google\ Chrome.app http://localhost:9000 & #linux has a different 'open' command
# alt URL if you want to skip the page listing
# http://localhost:9000/webkit/inspector/inspector.html?page=1
#see also
#github.com/ariya/phantomjs/wiki/Troubleshooting
Run Code Online (Sandbox Code Playgroud)
接下来的几行是IntelliJ的设置,尽管上面的代码在任何平台/ IDE上都能正常工作.
程序:$ProjectFileDir$/path/to/bash/script.sh
参数:$FilePath$
工作目录:$ProjectFileDir$
PhantomJS有一个remote-debugger-port
选项,您可以使用它来调试Chrome开发工具中的casper脚本.要使用它,只需使用以下参数执行casper脚本:
casperjs test script.js --remote-debugger-port=9000
然后,在Chrome中打开http:// localhost:9000,然后单击about:blank
显示自己的链接.然后,您应该发现自己处于熟悉的Chrome开发工具领域.
由于这是一个脚本而不是一个网页,为了开始调试,你必须在脚本执行之前做两件事之一:
__run()
以实际启动您的脚本.debugger;
在代码中插入一行,并使用其他--remote-debugger-autorun=yes
参数运行casper脚本.在远程调试页面打开的情况下执行此操作将运行脚本,直到它到达您的debugger;
行.有一个很好的教程可以很好地解释这一切.
归档时间: |
|
查看次数: |
7300 次 |
最近记录: |