forked from ariya/phantomjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
detro edited this page Oct 31, 2012
·
5 revisions
PhantomJS comes with a lot of included examples. Often an example comes in two flavors: JavaScript and CoffeeScript.
Basic examples
-
arguments.jsshows the arguments passed to the script -
countdown.jsprints a 10 second countdown -
echoToFile.jswrites the command line arguments to a file -
fibo.jslists the first few numbers in the Fibonacci sequence -
hello.jsdisplays the famous message -
module.jsanduniverse.jsdemonstrate the use of module system -
outputEncoding.jsdisplays a string in various encodings -
printenv.jsdisplays the system's environment variables -
scandir.jslists all files in a directory and its subdirectories -
sleepsort.jssorts integers and delays display depending on their values -
version.jsprints out PhantomJS version number -
page_events.jsprints out page events firing: useful to better grasppage.on*callbacks
Rendering/rasterization
-
colorwheel.jscreates a color wheel using HTML5 canvas -
rasterize.jsrasterizes a web page to image or PDF -
render_multi_url.jsrenders multiple web pages to images -
technews.jscaptures Google News as a PNG image
Page automation
-
direction.jsuses Google Maps to print driving direction -
follow.jsshows the number of followers of some Twitter accounts -
imagebin.jsuploads an image to imagebin.org -
injectme.jsinjects itself into a web page context -
ipgeocode.jsdeduces the location via IP geocoding -
movies.jslists movies from kids-in-mind.com -
phantomwebintro.jsuses jQuery to read #intro element text from phantomjs.org -
pizza.jsuses yelp.com to find pizza places in Mountain View -
seasonfood.jsdisplays the BBC seasonal food list -
tweets.jsdisplays the most recent tweets -
unrandomize.jsmodifies a global object at page initialization -
waitfor.jswaits until a test condition is true or a timeout occurs
Network
-
detectsniff.jsdetects if a web page sniffs the user agent -
loadspeed.jscomputes the loading speed of a web site -
netlog.jsdumps all network requests and responses -
netsniff.jscaptures network traffic in HAR format -
post.jssends an HTTP POST request to a test server -
postserver.jsstarts a web server and sends an HTTP POST request to it -
server.jsstarts a web server and sends an HTTP GET request to it -
serverkeepalive.jsstarts a web server which answers in plain text -
simpleserver.jsstarts a web server which answers in HTML
Testing
-
run-jasmine.jsruns Jasmine based tests -
run-qunit.jsruns QUnit based tests
Browser
-
features.jsdetects browser features usingmodernizr.js -
useragent.jschanges the browser's user agent property
(More to be written)