Demonstrate how to debug a page being snapshotted in PhantomJS
All examples assume you already have NodeJS installed on your local machine
- Clone this repo
- Open a command prompt
- Change to the examples/debug-phantomjs directory
- Run
npm install
- Run
npm start
This example snapshots the entire website of the WPSPA example application using its sitemap to drive. However, it sets up PhantomJS to debug just the "hello-world" page of the application on port 9000 as seen through the default html-snapshots script. The html-snapshots process will see the page you are debugging timeout, but that is OK - we're holding it for debugging.
NOTE: Each PhantomJS instance launched with the --remote-debugger-port option will stay alive, even after the script calls exit. You have to end the process yourself.
- Add the
phantomjsOptions
option to your html-snapshots options. - Assign
"--remote-debugger-port=9000"
to the page you want to debug. - Open up Chrome and navigate to http://
<ipaddress>
:9000. If you executed html-snapshots on the same machine, the<ipaddress>
will be 127.0.0.1 - Click "about:blank"
- In the "Scripts" tab, find the "about:blank" script in the dropdown. This is the html-snapshots default PhantomJS script.
- Set some breakpoints.
- In the "Console" tab, type
__run()
and hit enter. - Step through the code.
For more detailed explanation, checkout the remote debugging section of the PhantomJS troubleshooting guide.
Even after the script exits, PhantomJS will stick around because it was launched in debug mode. Presumably, this is so you can continue debugging over and over if need be.
If you want to kill it:
pgrep phantomjs
to find the PID of the phantomjs debug process- kill -15