Stuff for working with phantomjs from within Emacs.
This package requires phantomjs v1.5 to be installed. This Emacs package does only cursory checking for that dependancy.
The location of phantomjs can be controlled with the customizaton variable:
which is expanded before being used (so you can use ~ and .. and such like).
You can install this package from Marmalade in the usual way.
Here's some illustrative EmacsLisp:
(defun test-phantom-complete () (elnode-stop 8005) (message "test run done")) (let (phantom-server) (setq phantom-server (phantomjs-server 'servertest 6101 'test-phantom-complete)) (sleep-for 2) ;; Open a url (phantomjs-open phantom-server "http://localhost:8005/talk/stuff/html/index.html" (lambda (status arg) (sleep-for 3) ;; Then exit (phantomjs-exit arg (lambda (status arg) (message "plaintalk exited phantom"))))))
(phantomjs-open phantom-server "http://localhost:8005/talk/stuff/html/index.html" (lambda (status server-proc) (sleep-for 3) (phantomjs-call server-proc "window.location.hostname" (lambda (status server-proc) (phantomjs-exit server-proc (lambda (status server-proc) (message "plaintalk exited phantom")))))))
I have also implemented a synchronous style, basically it just uses an automatic semaphore with the async style, it makes the code easier to write though:
(phantomjs-open server (concat "file://" (expand-file-name "test.html" phantomjs--base))) (phantomjs-call server "document.getElementById('title').id") (phantomjs-call server "document.getElementById('subtitle').id") (phantomjs-exit server) ;; Manually wait... you shouldn't need this call (phantomjs--wait-for server t)
To build the package yourself, use make:
make clean all
will produce the appropriately versioned phantomjs tar file which can then be installed (locally) with:
will compile and install the package.