Skip to content

Commit 37f3898

Browse files
Merge pull request #43 from WebPageTest/mobileDevice
Recipe for emulating a mobile device
2 parents a180ff0 + 88121ec commit 37f3898

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ WebPageTest API Recipes
1212
- [Emulate a slow network](#emulate-a-slow-network)
1313
- [Emulate a slow network and CPU throttling](#emulate-network-&-cputhrottle)
1414
- [Emulate a custom connectivity (Bandwidth, Latency, PacketLossRate)](#emulate-a-custom-connectivity)
15+
- [Emulate a test on mobile device](#Emulate-a-test-on-mobile-device)
1516
- [Retrieve your Core Web Vitals](#retrieve-your-core-web-vitals)
1617
- [Retrieve your Core Web Vitals + CrUX data for the tested URL](#retrieve-your-core-web-vitals-+-crux)
1718
- [Run a test with a third-party domain blocked](#run-a-test-with-a-third-party-domain-blocked)
@@ -116,6 +117,38 @@ wpt.runTest(testURL, options, (err, result) => {
116117

117118
[Source](connectivity-custom.js)
118119

120+
<h3 id="Emulate-a-test-on-mobile-device">Emulate a test on mobile device</h3>
121+
122+
```js
123+
import WebPageTest from "webpagetest";
124+
125+
const wpt = new WebPageTest("https://www.webpagetest.org", "YOUR_API_KEY");
126+
127+
let testURL = "https://docs.webpagetest.org/"; //Your URL here
128+
129+
let options = {
130+
location: "ec2-us-east-1:Chrome",
131+
label: "emulate mobile device",
132+
firstViewOnly: true,
133+
emulateMobile: true,
134+
device: "Nexus5", // optional (default: MotoG4)
135+
};
136+
137+
//Supported devices: https://github.com/WPO-Foundation/webpagetest/blob/master/www/settings/mobile_devices.ini
138+
139+
// Run the test
140+
wpt.runTest(testURL, options, (err, result) => {
141+
if (result) {
142+
console.log(result);
143+
} else {
144+
console.log(err);
145+
}
146+
});
147+
148+
```
149+
150+
[Source](mobile-device.js)
151+
119152
<h3 id="retrieve-your-core-web-vitals">Retrieve your Core Web Vitals</h3>
120153

121154
```js

mobile-device.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import WebPageTest from "webpagetest";
2+
3+
const wpt = new WebPageTest("https://www.webpagetest.org", "YOUR_API_KEY");
4+
5+
let testURL = "https://docs.webpagetest.org/"; //Your URL here
6+
7+
let options = {
8+
location: "ec2-us-east-1:Chrome",
9+
label: "emulate mobile device",
10+
firstViewOnly: true,
11+
emulateMobile: true,
12+
device: "Nexus5", // optional (default: MotoG4)
13+
};
14+
15+
//List of support devices https://github.com/WPO-Foundation/webpagetest/blob/master/www/settings/mobile_devices.ini
16+
17+
// Run the test
18+
wpt.runTest(testURL, options, (err, result) => {
19+
if (result) {
20+
console.log(result);
21+
} else {
22+
console.log(err);
23+
}
24+
});

0 commit comments

Comments
 (0)