Getting remote debugging set up with PhantomJS

前端 未结 4 772
后悔当初
后悔当初 2021-01-30 16:56

I\'m trying to set up remote debugging with PhantomJS, without much luck. I am following the instructions at https://github.com/ariya/phantomjs/wiki/Troubleshooting. I have a li

4条回答
  •  迷失自我
    2021-01-30 17:36

    To debug a script, start phantomjs like so:

    phantomjs --remote-debugger-port=9000 hello.js
    

    Here's a super simple test script that works (hello.js). Note that you should put debugger; at the top of your script, or wherever in your script you want to break into the debugger.

    hello.js

    debugger;
    
    for (var i=0; i < 5; i++)
    {
      console.log('debugging in phantom js:' + i);
    }
    
    phantom.exit();
    

    Now just load the following url in your browser:

    http://127.0.0.1:9000/

    Then you'll see a link listed in the browser page

    about:blank
    

    Click on it, and then you'll see a whole page that looks like the Chrome Inspector. Click on the "Console" button in the toolbar that's in this page (not the console of Chrome or Safari that you're used to using).

    Now, in that console type __run() and hit enter. Your script will display and start debugging!

提交回复
热议问题