@@ -12,6 +12,7 @@ WebPageTest API Recipes
12
12
- [ Emulate a slow network] ( #emulate-a-slow-network )
13
13
- [ Emulate a slow network and CPU throttling] ( #emulate-network-&-cputhrottle )
14
14
- [ Emulate a custom connectivity (Bandwidth, Latency, PacketLossRate)] ( #emulate-a-custom-connectivity )
15
+ - [ Emulate a test on mobile device] ( #Emulate-a-test-on-mobile-device )
15
16
- [ Retrieve your Core Web Vitals] ( #retrieve-your-core-web-vitals )
16
17
- [ Retrieve your Core Web Vitals + CrUX data for the tested URL] ( #retrieve-your-core-web-vitals-+-crux )
17
18
- [ 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) => {
116
117
117
118
[ Source] ( connectivity-custom.js )
118
119
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
+
119
152
<h3 id =" retrieve-your-core-web-vitals " >Retrieve your Core Web Vitals</h3 >
120
153
121
154
``` js
0 commit comments