Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
webpagetest
Advanced tools
WebPageTest API Wrapper is a NPM package that wraps WebPageTest API for NodeJS as a module and a command-line tool.
$ npm install webpagetest -g
$ webpagetest test http://twitter.com/marcelduran
var WebPageTest = require('webpagetest');
var wpt = new WebPageTest('www.webpagetest.org');
wpt.runTest('http://twitter.com/marcelduran', function (err, data) {
if (err) throw err;
console.log(data);
});
marcelduran.com/webpagetest-api
$ webpagetest --help
The default WPT server can also be specified via environment variable WEBPAGETEST_SERVER
$ webpagetest locations
{
"response": {
"statusCode": 200, "statusText": "Ok",
"data": {
"location": [
...
{
"id": "SanJose_IE9",
"Label": "San Jose, CA USA (IE 9,Chrome,Firefox)",
"location": "SanJose_IE9",
"Browser": "IE 9",
"PendingTests": {
"p1": 0, "p2": 0, "p3": 0, "p4": 0, "p5": 2, "p6": 2, "p7": 0,
"p8": 0, "p9": 0, "Total": 7, "HighPriority": 2, "LowPriority": 4,
"Testing": 1, "Idle": 0
}
},
...
]
}
}
}
$ webpagetest test http://twitter.com/marcelduran --key 1F2A3K4E5 --location SanJose_IE9
{
"statusCode": 200,
"statusText": "Ok",
"data": {
"testId": "121025_PT_N8K",
"ownerKey": "868cb2813a0f376a977dd1a24ab041b4f12361b3",
"jsonUrl": "http://localhost/results.php?test=121025_PT_N8K&f=json",
"xmlUrl": "http://localhost/xmlResult.php?test=121025_PT_N8K",
"userUrl": "http://localhost/results.php?test=121025_PT_N8K",
"summaryCSV": "http://localhost/csv.php?test=121025_PT_N8K",
"detailCSV": "http://localhost/csv.php?test=121025_PT_N8K&requests=1"
}
}
$ webpagetest status 121025_PT_N8K
{
"statusCode": 101,
"statusText": "Test Pending",
"data": {
"statusCode": 101,
"statusText": "Test Pending",
"testId": "121025_PT_N8K",
"runs": 1,
"fvonly": 0,
"location": "SanJose_IE9"
}
}
$ webpagetest results 121025_PT_N8K
{
"response": {
"statusCode": 200, "statusText": "Ok",
"data": {
"testId": "121025_PT_N8K",
"summary": "http://www.webpagetest.org/result/121025_PT_N8K/",
"testUrl": "http://twitter.com/marcelduran",
"location": "SanJose_IE9",
"connectivity": "DSL",
"bwDown": 1500, "bwUp": 384, "latency": 50, "plr": 0,
"completed": "Thu, 25 Oct 2012 23:42:11 +0000",
"runs": 1, "successfulFVRuns": 1,
"average": {
"firstView": {
"loadTime": 3942, "TTFB": 1518,
"bytesIn": 963405, "bytesInDoc": 431612,
"requests": 32, "requestsDoc": 19,
"render": 2509, "fullyLoaded": 7765,
"docTime": 3942, "domTime": 0,
"titleTime": 1641, "avgRun": 1
}
},
...
}
}
}
$ webpagetest waterfall 121025_PT_N8K --thumbnail --cached --uri
{
"type": "image/png",
"data": "iVBORw0KGgoAAAANSUhEUgA...RK5CYII="
}
getTestStatus(id, options, callback)
getTestResults(id, options, callback)
getLocations(options, callback)
getTesters(options, callback)
runTest(url_or_script, options, callback)
cancelTest(id, options, callback)
getHARData(id, options, callback)
getPageSpeedData(id, options, callback)
getUtilizationData(id, options, callback)
getRequestData(id, options, callback)
getTimelineData(id, options, callback)
getNetLogData(id, options, callback)
getConsoleLogData(id, options, callback)
getTestInfo(id, options, callback)
getWaterfallImage(id, options, callback)
getScreenshotImage(id, options, callback)
listen(port, callback)
scriptToString(script)
function(error, data)
optional[
{command1: 'value1'},
{command2: 123},
{command3: ['value1', 'value2', ... , 'valueN']},
...
'commandN'}
]
getWaterfallImage
and getScreenshotImage
callback function has a third parameter info
which is an object with {type: 'image/jpeg or png', encoding: 'utf8 or binary'}
scriptToString
script array values 1-N are optional. e.g:var script = wpt.scriptToString([
{logData: 0},
{navigate: 'http://foo.com/login'},
{logData: 1},
{setValue: ['name=username', 'johndoe']},
{setValue: ['name=password', '12345']},
{submitForm: 'action=http://foo.com/main'},
'waitForComplete'
]);
wpt.runTest(script, function (err, data) {console.log(err || data);});
options
parameter)true
, method does not make an actual request to the API Server but rather returns an object with url
which contains the actual URL to make the GET request to WebPageTest API ServerrunTest
method only)getPageSpeedData
, getUtilizationData
, getRequestData
, getTimelineData
, getNetLogData
, getConsoleLogData
, getWaterfallImage
and getScreenshotImage
methods)true
returns the repeat view (cached) datagetWaterfallImage
and getScreenshotImage
methods)getScreenshotImage
method only)window.onload
was fired)var WebPageTest = require('webpagetest');
var wpt = new WebPageTest('my-wpt.foo.com'); // default: www.webpagetest.org
var wptPublic = new WebPageTest('www.webpagetest.org', 'MY_API_KEY');
wpt.getLocations(function (err, data) {
if (err) throw err;
console.log(data);
});
wpt.runTest('http://twitter.com/marcelduran', {location: 'SanJose_IE9'}, function (err, data) {
if (err) throw err;
console.log(data);
});
wpt.getTestStatus('121025_PT_N8K', function (err, data) {
if (err) throw err;
console.log(data);
});
wpt.getTestResults('121025_PT_N8K', function (err, data) {
if (err) throw err;
console.log(data);
});
wpt.getWaterfallImage('121025_PT_N8K', {
thumbnail: true,
repeatView: true,
dataURI: true
}, function (err, data, info) {
if (err) throw err;
console.log(data, info);
}
);
WebPageTest API Wrapper comes with a handy RESTful API proxy
$ webpagetest listen 8080 --server wpt.foo.com
server listening on port 8080
http://localhost:8080
$ curl http://localhost:8080/help
$ curl http://localhost:8080/test/twitter.com/?location=SanJose_IE9
wpt.foo.com
is overriding the default www.webpagetest.org
server but can still be overridden with server
optionvar server = wpt.listen(8080, function(err, data) {
if (err) throw err;
console.log('listening on ' + data.url);
}); // listen on port 8080 (optional), default port is 7791
setTimeout(function() {
server.close(function() {
console.log('listening done');
});
}, 10000); // wait for 10s before stop listening
Have a bug/feature request? Please create an issue here on GitHub!
https://github.com/marcelduran/webpagetest-api/issues
Marcel Duran
Copyright 2013 Twitter, Inc. and other contributors
Licensed under the MIT License
FAQs
WebPageTest API wrapper for NodeJS
We found that webpagetest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.