Skip to content

nicferrier/phantomjsel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

phantomjs handling for emacs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published