This repository has been archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Examples
mazemult edited this page Oct 5, 2012
·
20 revisions
PhantomJS comes with a lot of included examples. Often an example comes in two flavors: JavaScript and CoffeeScript.
Basic examples
-
arguments.js
shows the arguments passed to the script -
countdown.js
prints a 10 second countdown -
echoToFile.js
writes the command line arguments to a file -
fibo.js
lists the first few numbers in the Fibonacci sequence -
hello.js
displays the famous message -
module.js
anduniverse.js
demonstrate the use of module system -
outputEncoding.js
displays a string in various encodings -
printenv.js
displays the system's environment variables -
scandir.js
lists all files in a directory and its subdirectories -
sleepsort.js
sorts integers and delays display depending on their values -
version.js
prints out PhantomJS version number
Rendering/rasterization
-
colorwheel.js
creates a color wheel using HTML5 canvas -
rasterize.js
rasterizes a web page to image or PDF -
render_multi_url.js
renders multiple web pages to images -
technews.js
captures Google News as a PNG image
Page automation
-
direction.js
uses Google Maps to print driving direction -
follow.js
shows the number of followers of some Twitter accounts -
imagebin.js
uploads an image to imagebin.org -
injectme.js
injects itself into a web page context -
ipgeocode.js
deduces the location via IP geocoding -
movies.js
lists movies from kids-in-mind.com -
phantomwebintro.js
uses jQuery to read #intro element text from phantomjs.org -
pizza.js
uses yelp.com to find pizza places in Mountain View -
seasonfood.js
displays the BBC seasonal food list -
tweets.js
displays the most recent tweets -
unrandomize.js
modifies a global object at page initialization -
waitfor.js
waits until a test condition is true or a timeout occurs
Network
-
detectsniff.js
detects if a web page sniffs the user agent -
loadspeed.js
computes the loading speed of a web site -
netlog.js
dumps all network requests and responses -
netsniff.js
captures network traffic in HAR format -
post.js
sends an HTTP POST request to a test server -
postserver.js
starts a web server and sends an HTTP POST request to it -
server.js
starts a web server and sends an HTTP GET request to it -
serverkeepalive.js
starts a web server which answers in plain text -
simpleserver.js
starts a web server which answers in HTML
Testing
-
run-jasmine.js
runs Jasmine based tests -
run-qunit.js
runs QUnit based tests
Browser
-
features.js
detects browser features usingmodernizr.js
-
useragent.js
changes the browser's user agent property
(More to be written)