Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

phantomjs handling for emacs

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .gitignore
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.creole
Octocat-spinner-32 build.el
Octocat-spinner-32 config.js
Octocat-spinner-32 ghostweb.js
Octocat-spinner-32 packagedir.el
Octocat-spinner-32 phantomjs.el
Octocat-spinner-32 test.html
README.creole

Stuff for working with phantomjs from within Emacs.

Dependancies

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:

phantomjs-home

which is expanded before being used (so you can use ~ and .. and such like).

Installing

You can install this package from Marmalade in the usual way.

Using

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"))))))

It's also possible to call Javascript functions inside the opened web page:

(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")))))))

Synchronous style

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)

Building the package

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:

M-x package-install-file

Alternately:

make install

will compile and install the package.

Something went wrong with that request. Please try again.