Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A GUI to debug phantomjs script

Tags:

phantomjs

I am using phantomjs to build a web crawler. My current crawler is a Python script using selenium, which requires a running Firefox browser. While Selenium is good for debugging scripts (as I can use firebug to inspect the webpage), it cannot be deployed on linux servers without GUI. So I am trying to translate my Python script to phantomjs.

To debug phantomjs scripts, I save the page source html and render a png screenshot to disk, and open it in Firefox to inspect the source page. I am wondering if there is a better way to do this, e.g. a plugin for phantomjs, etc.

like image 310
Yin Zhu Avatar asked Jul 31 '13 08:07

Yin Zhu


People also ask

How do you debug a test in PhantomJS?

Open a new browser tab and return to the debugging portal at http://127.0.0.1:9000. There should now be a second entry in the bulleted list. Click on this entry to open a new debugger that operates in the context of your page inside PhantomJS.

How PhantomJS works?

PhantomJS is a discontinued headless browser used for automating web page interaction. PhantomJS provides a JavaScript API enabling automated navigation, screenshots, user behavior and assertions making it a common tool used to run browser-based unit tests in a headless system like a continuous integration environment.


1 Answers

This little hack is using a simple technique: It grabs the screen as PhantomJS or CasperJS sees it with captureBase64('png') and then it is POSTing the image into the receiving server which then sends it via socket.io to the browser which displays it is as inline image.

The source code is available on github:

https://github.com/maciejjankowski/flaming-octo-puss

I'm not sure if PhantomJS has it, but CasperJS does (and the latter adds some extra functions to PhantomJS)

and use remote debugging as others suggest

like image 192
Maciej Jankowski Avatar answered Oct 30 '22 07:10

Maciej Jankowski