webpagetest
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -132,3 +132,3 @@ /** | ||
function dataURI(data) { | ||
return new Buffer(data || '', 'binary').toString('base64'); | ||
return new Buffer.from(data || '', 'binary').toString('base64'); | ||
} | ||
@@ -241,2 +241,21 @@ | ||
function deepClone(obj) { | ||
var newObj, value, key; | ||
if (typeof obj !== "object" || obj === null) { | ||
return obj; | ||
} | ||
newObj = Array.isArray(obj) ? [] : {}; | ||
for (key in obj) { | ||
value = obj[key]; | ||
// Recursively (deep) copy for nested objects, including arrays | ||
newObj[key] = deepClone(value); | ||
} | ||
return newObj; | ||
} | ||
module.exports = { | ||
@@ -254,3 +273,4 @@ xmlToObj: xmlToObj, | ||
setQuery: setQuery, | ||
WPTAPIError: WPTAPIError | ||
WPTAPIError: WPTAPIError, | ||
deepClone: deepClone | ||
}; |
@@ -331,2 +331,87 @@ /** | ||
}, | ||
'browserwidth': { | ||
name: 'browserwidth', | ||
key: 'bw', | ||
api: 'browser_width', | ||
param: 'pixels', | ||
info: 'Browser window width (in display pixels)' | ||
}, | ||
'browserheight': { | ||
name: 'browserheight', | ||
key: 'bh', | ||
api: 'browser_height', | ||
param: 'pixels', | ||
info: 'Browser window height (in display pixels)' | ||
}, | ||
'viewportheight': { | ||
name: 'viewportheight', | ||
key: 'vh', | ||
api: 'height', | ||
param: 'pixels', | ||
info: 'Viewport Height in css pixels' | ||
}, | ||
'viewportwidth': { | ||
name: 'viewportwidth', | ||
key: 'vw', | ||
api: 'width', | ||
param: 'pixels', | ||
info: 'Viewport Width in css pixels' | ||
}, | ||
'devicetopixelratio' : { | ||
name : 'devicetopixelratio', | ||
key : 'dpr', | ||
api : 'dpr', | ||
param : 'ratio', | ||
info : 'Device To Pixel Ratio' | ||
}, | ||
'appendua' : { | ||
name : 'appendua', | ||
key : 'au', | ||
api : 'appendua', | ||
param : 'string', | ||
info : 'String to append to the user agent string. This is in addition to the default PTST/ver string' | ||
}, | ||
'testtype' : { | ||
name : 'testtype', | ||
key : 'tt', | ||
api : 'type', | ||
param : 'string', | ||
info : 'For running alternative test types, can specify traceroute or lighthouse' | ||
}, | ||
'profiler' : { | ||
name : 'profiler', | ||
key : 'pr', | ||
api : 'profiler', | ||
param : 'number', | ||
info : 'Set to 1 to enable the V8 sampling profiler (Chromium only)' | ||
}, | ||
'disableAVIF' : { | ||
name : 'disableAVIF', | ||
key : 'avif', | ||
api : 'disableAVIF', | ||
param : 'number', | ||
info : 'Set to 1 to disable AVIF support (Chromium 88+)' | ||
}, | ||
'disableWEBP' : { | ||
name : 'disableWEBP', | ||
key : 'webp', | ||
api : 'disableWEBP', | ||
param : 'number', | ||
info : 'Set to 1 to disable WEBP support (Chromium 88+)' | ||
}, | ||
'disableJXL' : { | ||
name : 'disableJXL', | ||
key : 'jxl', | ||
api : 'disableJXL', | ||
param : 'number', | ||
info : 'Set to 1 to disable JpegXL support (Chromium 88+)' | ||
}, | ||
'dtShaper' : { | ||
name : 'dtShaper', | ||
key : 'dts', | ||
api : 'dtShaper', | ||
param : 'number', | ||
info : "Set to 1 to use Chrome's built-in traffic-shaping instead of the packet-level netem shaping usually used by the test agents" | ||
}, | ||
'latency': { | ||
@@ -698,3 +783,3 @@ name: 'latency', | ||
name: 'getLocations', | ||
options: [options.request], | ||
options: [options.request,options.apikey], | ||
info: 'list locations and the number of pending tests' | ||
@@ -701,0 +786,0 @@ }, |
@@ -42,3 +42,3 @@ /** | ||
if (info.encoding === 'binary') { | ||
data = new Buffer(data, 'binary'); | ||
data = new Buffer.from(data, 'binary'); | ||
type = info.type; | ||
@@ -45,0 +45,0 @@ } else { |
@@ -122,3 +122,3 @@ /** | ||
var i, len, pos, | ||
buffer = new Buffer(length), | ||
buffer = new Buffer.alloc(length), | ||
type = (res.headers['content-type'] || '').split(';')[0]; | ||
@@ -285,3 +285,3 @@ | ||
callback = callback || typeof options === 'function' && options; | ||
options = options === callback ? {} : options || {}; | ||
options = options === callback ? {} : helper.deepClone(options) || {}; | ||
helper.setQuery(mapping.commands.results, options, query); | ||
@@ -305,3 +305,5 @@ | ||
var query = helper.setQuery(mapping.commands.locations, options); | ||
if (!query.k && this.config.key && !options.allLocations) { | ||
query.k = this.config.key; | ||
} | ||
return api.call(this, paths.locations, callback, query, options); | ||
@@ -323,4 +325,4 @@ } | ||
callback = callback || options; | ||
options = options === callback ? {} : options; | ||
options = options === callback ? {} : helper.deepClone(options); | ||
// testing url or script? | ||
@@ -486,3 +488,3 @@ query[reSpace.test(what) ? 'script' : 'url'] = what; | ||
callback = callback || options; | ||
options = options === callback ? undefined : options; | ||
options = options === callback ? undefined : helper.deepClone(options); | ||
@@ -498,3 +500,3 @@ helper.setQuery(mapping.commands.restart, options, query); | ||
callback = callback || options; | ||
options = options === callback ? undefined : options; | ||
options = options === callback ? undefined : helper.deepClone(options); | ||
@@ -501,0 +503,0 @@ helper.setQuery(mapping.commands.cancel, options, query); |
{ | ||
"name": "webpagetest", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "WebPageTest API wrapper for NodeJS", | ||
"author": "Marcel Duran <github@marcelduran.com> (http://github.com/marcelduran)", | ||
"homepage": "http://github.com/marcelduran/webpagetest-api", | ||
"author": "WebPageTest <github@WebPageTest.com> (http://github.com/WebPageTest)", | ||
"homepage": "http://github.com/WebPageTest/webpagetest-api", | ||
"keywords": [ | ||
@@ -17,6 +17,6 @@ "webpagetest", | ||
"type": "git", | ||
"url": "git://github.com/marcelduran/webpagetest-api.git" | ||
"url": "git://github.com/WebPageTest/webpagetest-api.git" | ||
}, | ||
"bugs": { | ||
"url": "http://github.com/marcelduran/webpagetest-api/issues" | ||
"url": "http://github.com/WebPageTest/webpagetest-api/issues" | ||
}, | ||
@@ -23,0 +23,0 @@ "main": "lib/webpagetest.js", |
137
README.md
@@ -1,10 +0,13 @@ | ||
## WebPageTest API Wrapper for NodeJS | ||
<p align="center"><img src="https://docs.webpagetest.org/img/wpt-navy-logo.png" alt="WebPageTest Logo" /></p> | ||
<p align="center"><a href="https://docs.webpagetest.org/api/integrations/#officially-supported-integrations">Learn about more WebPageTest API Integrations in our docs</a></p> | ||
[![Build Status](https://secure.travis-ci.org/marcelduran/webpagetest-api.svg?branch=master)](https://travis-ci.org/marcelduran/webpagetest-api) | ||
# WebPageTest API Wrapper for NodeJS | ||
[![Build Status](https://travis-ci.com/WebPageTest/webpagetest-api.svg?branch=master)](https://travis-ci.com/WebPageTest/webpagetest-api) | ||
[![NPM Version](https://img.shields.io/npm/v/webpagetest.svg?style=flat)](https://www.npmjs.org/package/webpagetest) | ||
[![NPM Downloads](https://img.shields.io/npm/dm/webpagetest.svg?style=flat)](https://www.npmjs.org/package/webpagetest) | ||
[![Dependencies Status](https://david-dm.org/marcelduran/webpagetest-api.svg)](https://david-dm.org/marcelduran/webpagetest-api) | ||
[WebPageTest API Wrapper](https://marcelduran.com/webpagetest-api) is a [NPM](https://npmjs.org) package that wraps [WebPageTest](https://github.com/WPO-Foundation/webpagetest) API for [NodeJS](https://nodejs.org) as a module and a command-line tool. | ||
WebPageTest API Wrapper is a [NPM](https://npmjs.org) package that wraps [WebPageTest](https://github.com/WPO-Foundation/webpagetest) API for [NodeJS](https://nodejs.org) as a module and a command-line tool. | ||
## Getting started | ||
@@ -20,3 +23,3 @@ | ||
```bash | ||
$ webpagetest test http://marcelduran.com/webpagetest-api | ||
$ webpagetest test https://docs.webpagetest.org/api/integrations/ | ||
``` | ||
@@ -31,3 +34,3 @@ | ||
```bash | ||
$ docker run -it --rm webpagetest-api -k YOURAPIKEY test http://marcelduran.com/webpagetest-api | ||
$ docker run -it --rm webpagetest-api -k YOURAPIKEY test https://docs.webpagetest.org/api/integrations/ | ||
``` | ||
@@ -40,3 +43,3 @@ | ||
wpt.runTest('http://marcelduran.com/webpagetest-api', (err, data) => { | ||
wpt.runTest('https://docs.webpagetest.org/api/integrations/', (err, data) => { | ||
console.log(err || data); | ||
@@ -46,6 +49,2 @@ }); | ||
## API Console Demo | ||
[marcelduran.com/webpagetest-api](http://marcelduran.com/webpagetest-api/console/) | ||
## Command Line | ||
@@ -135,2 +134,14 @@ | ||
* **-U, --bwup** _\<bandwidth\>_: upload bandwidth in Kbps (used when specifying a custom connectivity profile) | ||
* **-bw, --browserwidth** _\<pixels\>_: Browser window width (in display pixels) | ||
* **-bh, --browserheight** _\<pixels\>_: Browser window height (in display pixels) | ||
* **-vh, --viewportheight** _\<pixels\>_: Viewport Height in css pixels | ||
* **-vw, --viewportwidth** _\<pixels\>_: Viewport Width in css pixels | ||
* **-dpr, --devicetopixelratio** _\<ratio\>_: Device To Pixel Ratio | ||
* **-au, --appendua** _\<string\>_: String to append to the user agent string. This is in addition to the default PTST/ver string | ||
* **-tt, --testtype** _\<string\>_: For running alternative test types, can specify traceroute or lighthouse | ||
* **-pr, --profiler** _\<number\>_: Set to 1 to enable the V8 sampling profiler (Chromium only) | ||
* **-avif, --disableAVIF** _\<number\>_: Set to 1 to disable AVIF support (Chromium 88+) | ||
* **-webp, --disableWEBP** _\<number\>_: Set to 1 to disable WEBP support (Chromium 88+) | ||
* **-jxl, --disableJXL** _\<number\>_: Set to 1 to disable JXL support (Chromium 88+) | ||
* **-dts, --dtShaper** _\<number\>_: Set to 1 to use Chrome's built-in traffic-shaping instead of the packet-level netem shaping usually used by the test agents | ||
* **-Y, --latency** _\<time\>_: first-hop Round Trip Time in ms (used when specifying a custom connectivity profile) | ||
@@ -156,3 +167,3 @@ * **-P, --plr** _\<percentage\>_: packet loss rate - percent of packets to drop (used when specifying a custom connectivity profile) | ||
#### API Key (works for **test**, **restart** and **cancel** commands) | ||
#### API Key (works for **test**, **restart**,**locations** and **cancel** commands) | ||
* **-k, --key** _\<api_key\>_:API key (if assigned). Contact the WebPageTest server administrator for a key if required or request an API key for limited testing at [webpagetest.org/getkey.php](https://www.webpagetest.org/getkey.php) | ||
@@ -209,3 +220,3 @@ | ||
### Examples | ||
#### 1. Get available locations | ||
#### 1. Get all available locations | ||
```bash | ||
@@ -238,6 +249,34 @@ $ webpagetest locations | ||
``` | ||
#### 2. Get API available locations | ||
```bash | ||
$ webpagetest locations --key 1F2A3K4E5 | ||
``` | ||
```javascript | ||
{ | ||
"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 | ||
} | ||
}, | ||
... | ||
] | ||
} | ||
} | ||
} | ||
``` | ||
#### 2. Run test on http://marcelduran.com/webpagetest-api from San Jose on IE9 | ||
#### 3. Run test on https://docs.webpagetest.org/api/integrations/ from San Jose on IE9 | ||
```bash | ||
$ webpagetest test http://marcelduran.com/webpagetest-api --key 1F2A3K4E5 --location SanJose_IE9 | ||
$ webpagetest test https://docs.webpagetest.org/api/integrations/ --key 1F2A3K4E5 --location SanJose_IE9 | ||
``` | ||
@@ -260,3 +299,3 @@ ```javascript | ||
#### 3. Check current test status | ||
#### 4. Check current test status | ||
```bash | ||
@@ -280,3 +319,3 @@ $ webpagetest status 121025_PT_N8K | ||
#### 4. Get test results | ||
#### 5. Get test results | ||
```bash | ||
@@ -292,3 +331,3 @@ $ webpagetest results 121025_PT_N8K | ||
"summary": "https://www.webpagetest.org/result/121025_PT_N8K/", | ||
"testUrl": "http://marcelduran.com/webpagetest-api", | ||
"testUrl": "https://docs.webpagetest.org/api/integrations/", | ||
"location": "SanJose_IE9", | ||
@@ -315,3 +354,3 @@ "connectivity": "DSL", | ||
#### 5. Get test waterfall thumbnail from repeat view as data URI | ||
#### 6. Get test waterfall thumbnail from repeat view as data URI | ||
```bash | ||
@@ -327,9 +366,9 @@ $ webpagetest waterfall 121025_PT_N8K --thumbnail --cached --uri | ||
#### Run test on http://marcelduran.com/webpagetest-api and poll results every 5 seconds timing out in 60 seconds | ||
#### Run test on https://docs.webpagetest.org/api/integrations/ and poll results every 5 seconds timing out in 60 seconds | ||
```bash | ||
$ webpagetest test http://marcelduran.com/webpagetest-api --poll 5 --timeout 60 | ||
$ webpagetest test https://docs.webpagetest.org/api/integrations/ --poll 5 --timeout 60 | ||
``` | ||
#### Or run test on http://marcelduran.com/webpagetest-api and wait for results listening on localhost\* port 8000\** | ||
#### Or run test on https://docs.webpagetest.org/api/integrations/ and wait for results listening on localhost\* port 8000\** | ||
```bash | ||
$ webpagetest test http://marcelduran.com/webpagetest-api --wait 8000 | ||
$ webpagetest test https://docs.webpagetest.org/api/integrations/ --wait 8000 | ||
``` | ||
@@ -342,3 +381,3 @@ ```javascript | ||
"testId": "121025_PT_N8K", | ||
"testUrl": "http://marcelduran.com/webpagetest-api", | ||
"testUrl": "https://docs.webpagetest.org/api/integrations/", | ||
... | ||
@@ -473,2 +512,14 @@ "median": { | ||
* **bandwidthUp**: _String_, upload bandwidth in Kbps (used when specifying a custom connectivity profile) | ||
* **browserwidth**: _String_, Browser window width (in display pixels) | ||
* **browserheight**: _String_, Browser window height (in display pixels) | ||
* **viewportheight**: _String_, Viewport Height in css pixels | ||
* **viewportwidth**: _String_, Viewport Width in css pixels | ||
* **devicetopixelratio**: _String_, Device To Pixel Ratio | ||
* **appendua**: _String_, String to append to the user agent string. This is in addition to the default PTST/ver string | ||
* **testtype**: _String_, For running alternative test types, can specify traceroute or lighthouse | ||
* **profiler**: _Number_, Set to 1 to enable the V8 sampling profiler (Chromium only) | ||
* **disableAVIF**: _Number_, Set to 1 to disable AVIF support (Chromium 88+) | ||
* **disableWEBP**: _Number_, Set to 1 to disable WEBP support (Chromium 88+) | ||
* **disableJXL**: _Number_, Set to 1 to disable JpegXL support (Chromium 88+) | ||
* **dtShaper**: _Number_, Set to 1 to use Chrome's built-in traffic-shaping instead of the packet-level netem shaping usually used by the test agents | ||
* **latency**: _String_, first-hop Round Trip Time in ms (used when specifying a custom connectivity profile) | ||
@@ -544,2 +595,5 @@ * **packetLossRate**: _Number_, packet loss rate - percent of packets to drop (used when specifying a custom connectivity profile) | ||
#### Location (works for `getLocations` method only) | ||
* **allLocations** _Boolean_: if true, returns all available locations irrespective of API availability | ||
### Examples | ||
@@ -562,5 +616,5 @@ | ||
#### 3. Run test on http://marcelduran.com/webpagetest-api from San Jose on IE9 | ||
#### 3. Run test on https://docs.webpagetest.org/api/integrations/ from San Jose on IE9 | ||
```javascript | ||
wpt.runTest('http://marcelduran.com/webpagetest-api', {location: 'SanJose_IE9'}, (err, data) => { | ||
wpt.runTest('https://docs.webpagetest.org/api/integrations/', {location: 'SanJose_IE9'}, (err, data) => { | ||
console.log(err || data); | ||
@@ -595,5 +649,5 @@ }); | ||
#### Run test on http://marcelduran.com/webpagetest-api and poll results every 5 seconds timing out in 60 seconds | ||
#### Run test on https://docs.webpagetest.org/api/integrations/ and poll results every 5 seconds timing out in 60 seconds | ||
```javascript | ||
wpt.runTest('http://marcelduran.com/webpagetest-api', {pollResults: 5, timeout: 60}, (err, data) => { | ||
wpt.runTest('https://docs.webpagetest.org/api/integrations/', {pollResults: 5, timeout: 60}, (err, data) => { | ||
console.log(err || data); | ||
@@ -603,5 +657,5 @@ }); | ||
#### Or run test on http://marcelduran.com/webpagetest-api and wait results listening on localhost\* port 8000\*\* | ||
#### Or run test on https://docs.webpagetest.org/api/integrations/ and wait results listening on localhost\* port 8000\*\* | ||
```javascript | ||
wpt.runTest('http://marcelduran.com/webpagetest-api', {waitResults: 'localhost:8000'}, (err, data) => { | ||
wpt.runTest('https://docs.webpagetest.org/api/integrations/', {waitResults: 'localhost:8000'}, (err, data) => { | ||
console.log(err || data); | ||
@@ -627,3 +681,3 @@ }); | ||
$ curl http://localhost:8080/help | ||
$ curl http://localhost:8080/test/marcelduran.com/?location=SanJose_IE9 | ||
$ curl http://localhost:8080/test/webpagetest.org/?location=SanJose_IE9 | ||
``` | ||
@@ -666,4 +720,4 @@ ```bash | ||
``` | ||
test marcelduran.com --first --location foo | ||
test marcelduran.com --first --location bar | ||
test https://docs.webpagetest.org/api/integrations/ --first --location foo | ||
test https://docs.webpagetest.org/api/integrations/ --first --location bar | ||
``` | ||
@@ -699,4 +753,4 @@ It schedules the 2 tests above returning an array of size 2 in the same order as in `commands.txt` file: | ||
``` | ||
test marcelduran.com --first --location foo --poll --timeout 60 | ||
test marcelduran.com --first --location bar --poll --timeout 60 | ||
test https://docs.webpagetest.org/api/integrations/ --first --location foo --poll --timeout 60 | ||
test https://docs.webpagetest.org/api/integrations/ --first --location bar --poll --timeout 60 | ||
``` | ||
@@ -708,3 +762,3 @@ | ||
[See dedicated page](https://github.com/marcelduran/webpagetest-api/wiki/Test-Specs) | ||
[See dedicated page](https://github.com/WebPageTest/webpagetest-api/wiki/Test-Specs) | ||
@@ -720,9 +774,9 @@ ## Tests | ||
https://github.com/marcelduran/webpagetest-api/issues | ||
https://github.com/WebPageTest/webpagetest-api/issues | ||
## Author | ||
**Marcel Duran** | ||
**WebPageTest** | ||
+ https://github.com/marcelduran | ||
+ https://github.com/WebPageTest | ||
@@ -735,2 +789,5 @@ ## License | ||
Licensed under the [MIT License](https://github.com/marcelduran/webpagetest-api/raw/master/LICENSE) | ||
Licensed under the [MIT License](https://github.com/WebPageTest/webpagetest-api/raw/master/LICENSE) | ||
--- | ||
<p align="center"><a href="https://docs.webpagetest.org/api/integrations/#officially-supported-integrations">Learn about more WebPageTest API Integrations in our docs</a></p> |
@@ -7,2 +7,5 @@ Usage: webpagetest locations [options] | ||
-e, --request <id> echo request ID, useful to track asynchronous requests | ||
-k, --key <api_key> API key (if assigned). Contact the | ||
WebPageTest server administrator for a | ||
key if required | ||
-h, --help display help for command |
@@ -89,2 +89,14 @@ Usage: webpagetest test [options] <url_or_script> | ||
specifying a custom connectivity profile) | ||
-bw, --browserwidth <pixels> Browser window width (in display pixels) | ||
-bh, --browserheight <pixels> Browser window height (in display pixels) | ||
-vh, --viewportheight <pixels> Viewport Height in css pixels | ||
-vw, --viewportwidth <pixels> Viewport Width in css pixels | ||
-dpr, --devicetopixelratio <ratio> Device To Pixel Ratio | ||
-au, --appendua <string> String to append to the user agent string. This is in addition to the default PTST/ver string | ||
-tt, --testtype <string> For running alternative test types, can specify traceroute or lighthouse | ||
-pr, --profiler <number> Set to 1 to enable the V8 sampling profiler (Chromium only) | ||
-avif, --disableAVIF <number> Set to 1 to disable AVIF support (Chromium 88+) | ||
-webp, --disableWEBP <number> Set to 1 to disable WEBP support (Chromium 88+) | ||
-jxl, --disableJXL <number> Set to 1 to disable JpegXL support (Chromium 88+) | ||
-dts, --dtShaper <number> Set to 1 to use Chrome's built-in traffic-shaping instead of the packet-level netem shaping usually used by the test agents | ||
-Y, --latency <time> first-hop Round Trip Time in ms (used | ||
@@ -91,0 +103,0 @@ when specifying a custom connectivity |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5799062
116678
769
11