-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e129567
commit 5a4a468
Showing
53 changed files
with
3,752 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the <organization> nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# [PhantomJS](http://phantomjs.org) - Scriptable Headless WebKit | ||
|
||
PhantomJS ([phantomjs.org](http://phantomjs.org)) is a headless WebKit scriptable with JavaScript. The latest [stable release](http://phantomjs.org/release-2.0.html) is version 2.0. | ||
|
||
**Note**: Please **do not** create a GitHub pull request **without** reading the [Contribution Guide](https://github.com/ariya/phantomjs/blob/master/CONTRIBUTING.md) first. Failure to do so may result in the rejection of the pull request. | ||
|
||
## Use Cases | ||
|
||
- **Headless web testing**. Lightning-fast testing without the browser is now possible! | ||
- **Page automation**. [Access and manipulate](http://phantomjs.org/page-automation.html) web pages with the standard DOM API, or with usual libraries like jQuery. | ||
- **Screen capture**. Programmatically [capture web contents](http://phantomjs.org/screen-capture.html), including CSS, SVG and Canvas. Build server-side web graphics apps, from a screenshot service to a vector chart rasterizer. | ||
- **Network monitoring**. Automate performance analysis, track [page loading](http://phantomjs.org/network-monitoring.html) and export as standard HAR format. | ||
|
||
## Features | ||
|
||
- **Multiplatform**, available on major operating systems: Windows, Mac OS X, Linux, and other Unices. | ||
- **Fast and native implementation** of web standards: DOM, CSS, JavaScript, Canvas, and SVG. No emulation! | ||
- **Pure headless (no X11) on Linux**, ideal for continuous integration systems. Also runs on Amazon EC2, Heroku, and Iron.io. | ||
- **Easy to install**: [Download](http://phantomjs.org/download.html), unpack, and start having fun in just 5 minutes. | ||
|
||
## Questions? | ||
|
||
- Explore the complete [documentation](http://phantomjs.org/documentation/). | ||
- Read tons of [user articles](http://phantomjs.org/buzz.html) on using PhantomJS. | ||
- Join the [mailing-list](http://groups.google.com/group/phantomjs) and discuss with other PhantomJS fans. | ||
|
||
PhantomJS is free software/open source, and is distributed under the [BSD license](http://opensource.org/licenses/BSD-3-Clause). It contains third-party code, see the included `third-party.txt` file for the license information on third-party code. | ||
|
||
PhantomJS is created and maintained by [Ariya Hidayat](http://ariya.ofilabs.com/about) (Twitter: [@ariyahidayat](http://twitter.com/ariyahidayat)), with the help of [many contributors](https://github.com/ariya/phantomjs/contributors). Follow the official Twitter stream [@PhantomJS](http://twitter.com/PhantomJS) to get the frequent development updates. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use strict"; | ||
var system = require('system'); | ||
if (system.args.length === 1) { | ||
console.log('Try to pass some args when invoking this script!'); | ||
} else { | ||
system.args.forEach(function (arg, i) { | ||
console.log(i + ': ' + arg); | ||
}); | ||
} | ||
phantom.exit(); |
28 changes: 28 additions & 0 deletions
28
lib/phantomjs-2.1.1-linux-x86_64/examples/child_process-examples.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict"; | ||
var spawn = require("child_process").spawn | ||
var execFile = require("child_process").execFile | ||
|
||
var child = spawn("ls", ["-lF", "/rooot"]) | ||
|
||
child.stdout.on("data", function (data) { | ||
console.log("spawnSTDOUT:", JSON.stringify(data)) | ||
}) | ||
|
||
child.stderr.on("data", function (data) { | ||
console.log("spawnSTDERR:", JSON.stringify(data)) | ||
}) | ||
|
||
child.on("exit", function (code) { | ||
console.log("spawnEXIT:", code) | ||
}) | ||
|
||
//child.kill("SIGKILL") | ||
|
||
execFile("ls", ["-lF", "/usr"], null, function (err, stdout, stderr) { | ||
console.log("execFileSTDOUT:", JSON.stringify(stdout)) | ||
console.log("execFileSTDERR:", JSON.stringify(stderr)) | ||
}) | ||
|
||
setTimeout(function () { | ||
phantom.exit(0) | ||
}, 2000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use strict"; | ||
var page = require('webpage').create(); | ||
page.viewportSize = { width: 400, height : 400 }; | ||
page.content = '<html><body><canvas id="surface"></canvas></body></html>'; | ||
page.evaluate(function() { | ||
var el = document.getElementById('surface'), | ||
context = el.getContext('2d'), | ||
width = window.innerWidth, | ||
height = window.innerHeight, | ||
cx = width / 2, | ||
cy = height / 2, | ||
radius = width / 2.3, | ||
imageData, | ||
pixels, | ||
hue, sat, value, | ||
i = 0, x, y, rx, ry, d, | ||
f, g, p, u, v, w, rgb; | ||
|
||
el.width = width; | ||
el.height = height; | ||
imageData = context.createImageData(width, height); | ||
pixels = imageData.data; | ||
|
||
for (y = 0; y < height; y = y + 1) { | ||
for (x = 0; x < width; x = x + 1, i = i + 4) { | ||
rx = x - cx; | ||
ry = y - cy; | ||
d = rx * rx + ry * ry; | ||
if (d < radius * radius) { | ||
hue = 6 * (Math.atan2(ry, rx) + Math.PI) / (2 * Math.PI); | ||
sat = Math.sqrt(d) / radius; | ||
g = Math.floor(hue); | ||
f = hue - g; | ||
u = 255 * (1 - sat); | ||
v = 255 * (1 - sat * f); | ||
w = 255 * (1 - sat * (1 - f)); | ||
pixels[i] = [255, v, u, u, w, 255, 255][g]; | ||
pixels[i + 1] = [w, 255, 255, v, u, u, w][g]; | ||
pixels[i + 2] = [u, u, w, 255, 255, v, u][g]; | ||
pixels[i + 3] = 255; | ||
} | ||
} | ||
} | ||
|
||
context.putImageData(imageData, 0, 0); | ||
document.body.style.backgroundColor = 'white'; | ||
document.body.style.margin = '0px'; | ||
}); | ||
|
||
page.render('colorwheel.png'); | ||
|
||
phantom.exit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use strict"; | ||
var t = 10, | ||
interval = setInterval(function(){ | ||
if ( t > 0 ) { | ||
console.log(t--); | ||
} else { | ||
console.log("BLAST OFF!"); | ||
phantom.exit(); | ||
} | ||
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Detect if a web page sniffs the user agent or not. | ||
|
||
"use strict"; | ||
var page = require('webpage').create(), | ||
system = require('system'), | ||
sniffed, | ||
address; | ||
|
||
page.onInitialized = function () { | ||
page.evaluate(function () { | ||
|
||
(function () { | ||
var userAgent = window.navigator.userAgent, | ||
platform = window.navigator.platform; | ||
|
||
window.navigator = { | ||
appCodeName: 'Mozilla', | ||
appName: 'Netscape', | ||
cookieEnabled: false, | ||
sniffed: false | ||
}; | ||
|
||
window.navigator.__defineGetter__('userAgent', function () { | ||
window.navigator.sniffed = true; | ||
return userAgent; | ||
}); | ||
|
||
window.navigator.__defineGetter__('platform', function () { | ||
window.navigator.sniffed = true; | ||
return platform; | ||
}); | ||
})(); | ||
}); | ||
}; | ||
|
||
if (system.args.length === 1) { | ||
console.log('Usage: detectsniff.js <some URL>'); | ||
phantom.exit(1); | ||
} else { | ||
address = system.args[1]; | ||
console.log('Checking ' + address + '...'); | ||
page.open(address, function (status) { | ||
if (status !== 'success') { | ||
console.log('FAIL to load the address'); | ||
phantom.exit(); | ||
} else { | ||
window.setTimeout(function () { | ||
sniffed = page.evaluate(function () { | ||
return navigator.sniffed; | ||
}); | ||
if (sniffed) { | ||
console.log('The page tried to sniff the user agent.'); | ||
} else { | ||
console.log('The page did not try to sniff the user agent.'); | ||
} | ||
phantom.exit(); | ||
}, 1500); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// echoToFile.js - Write in a given file all the parameters passed on the CLI | ||
"use strict"; | ||
var fs = require('fs'), | ||
system = require('system'); | ||
|
||
if (system.args.length < 3) { | ||
console.log("Usage: echoToFile.js DESTINATION_FILE <arguments to echo...>"); | ||
phantom.exit(1); | ||
} else { | ||
var content = '', | ||
f = null, | ||
i; | ||
for ( i= 2; i < system.args.length; ++i ) { | ||
content += system.args[i] + (i === system.args.length-1 ? '' : ' '); | ||
} | ||
|
||
try { | ||
fs.write(system.args[1], content, 'w'); | ||
} catch(e) { | ||
console.log(e); | ||
} | ||
|
||
phantom.exit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use strict"; | ||
var feature, supported = [], unsupported = []; | ||
|
||
phantom.injectJs('modernizr.js'); | ||
console.log('Detected features (using Modernizr ' + Modernizr._version + '):'); | ||
for (feature in Modernizr) { | ||
if (Modernizr.hasOwnProperty(feature)) { | ||
if (feature[0] !== '_' && typeof Modernizr[feature] !== 'function' && | ||
feature !== 'input' && feature !== 'inputtypes') { | ||
if (Modernizr[feature]) { | ||
supported.push(feature); | ||
} else { | ||
unsupported.push(feature); | ||
} | ||
} | ||
} | ||
} | ||
|
||
console.log(''); | ||
console.log('Supported:'); | ||
supported.forEach(function (e) { | ||
console.log(' ' + e); | ||
}); | ||
|
||
console.log(''); | ||
console.log('Not supported:'); | ||
unsupported.forEach(function (e) { | ||
console.log(' ' + e); | ||
}); | ||
phantom.exit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use strict"; | ||
var fibs = [0, 1]; | ||
var ticker = window.setInterval(function () { | ||
console.log(fibs[fibs.length - 1]); | ||
fibs.push(fibs[fibs.length - 1] + fibs[fibs.length - 2]); | ||
if (fibs.length > 10) { | ||
window.clearInterval(ticker); | ||
phantom.exit(); | ||
} | ||
}, 300); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
console.log('Hello, world!'); | ||
phantom.exit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Use 'page.injectJs()' to load the script itself in the Page context | ||
|
||
"use strict"; | ||
if ( typeof(phantom) !== "undefined" ) { | ||
var page = require('webpage').create(); | ||
|
||
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this") | ||
page.onConsoleMessage = function(msg) { | ||
console.log(msg); | ||
}; | ||
|
||
page.onAlert = function(msg) { | ||
console.log(msg); | ||
}; | ||
|
||
console.log("* Script running in the Phantom context."); | ||
console.log("* Script will 'inject' itself in a page..."); | ||
page.open("about:blank", function(status) { | ||
if ( status === "success" ) { | ||
console.log(page.injectJs("injectme.js") ? "... done injecting itself!" : "... fail! Check the $PWD?!"); | ||
} | ||
phantom.exit(); | ||
}); | ||
} else { | ||
alert("* Script running in the Page context."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict"; | ||
var page = require('webpage').create(), | ||
system = require('system'), | ||
t, address; | ||
|
||
if (system.args.length === 1) { | ||
console.log('Usage: loadspeed.js <some URL>'); | ||
phantom.exit(1); | ||
} else { | ||
t = Date.now(); | ||
address = system.args[1]; | ||
page.open(address, function (status) { | ||
if (status !== 'success') { | ||
console.log('FAIL to load the address'); | ||
} else { | ||
t = Date.now() - t; | ||
console.log('Page title is ' + page.evaluate(function () { | ||
return document.title; | ||
})); | ||
console.log('Loading time ' + t + ' msec'); | ||
} | ||
phantom.exit(); | ||
}); | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/phantomjs-2.1.1-linux-x86_64/examples/loadurlwithoutcss.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use strict"; | ||
var page = require('webpage').create(), | ||
system = require('system'); | ||
|
||
if (system.args.length < 2) { | ||
console.log('Usage: loadurlwithoutcss.js URL'); | ||
phantom.exit(); | ||
} | ||
|
||
var address = system.args[1]; | ||
|
||
page.onResourceRequested = function(requestData, request) { | ||
if ((/http:\/\/.+?\.css/gi).test(requestData['url']) || requestData.headers['Content-Type'] == 'text/css') { | ||
console.log('The url of the request is matching. Aborting: ' + requestData['url']); | ||
request.abort(); | ||
} | ||
}; | ||
|
||
page.open(address, function(status) { | ||
if (status === 'success') { | ||
phantom.exit(); | ||
} else { | ||
console.log('Unable to load the address!'); | ||
phantom.exit(); | ||
} | ||
}); |
Oops, something went wrong.