browsertime 14.13.0 → 14.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Browsertime changelog (we do [semantic versioning](https://semver.org))
2
2
 
3
+ ## 14.15.0 - 2022-01-12
4
+ ### Added
5
+ * Added so you can append a String to Firefox User Agent [#1694](https://github.com/sitespeedio/browsertime/pull/1694), thank you [Henrik Skupin](https://github.com/whimboo) for pointing me in the right direction. With [#1695](https://github.com/sitespeedio/browsertime/pull/1695) we now have `--appendToUserAgent` that works in Chrome/Edge and Firefox.
6
+ ## 14.14.1 - 2022-01-12
7
+ ### Fixed
8
+ * Updated Chromedriver library that pickup already installed driver on Raspberry Pis. This makes it easier to run tests on an Android device from a Raspberry Pi.
9
+ ## 14.14.0 - 2022-01-10
10
+ ### Added
11
+ * Add support for [Humble](https://calendar.perfplanet.com/2021/introducing-humble-the-raspberry-pi-wifi-network-link-conditioner/) as connectivity engine for mobile phone testing. Make sure to setup Humble on a Raspberry Pi 4 and the choose engine with `--connectivity.engine humble` and set the URL to your instance `--connectivity.humble.url http://raspberrypi.local:3000`. Added in [#1691](https://github.com/sitespeedio/browsertime/pull/1691).
12
+ * Upgraded to Chrome 97, Edge 97 and Firefox 95 in the Docker container.
13
+ * Upgraded to Chromedriver 97.
14
+
15
+ ## 14.13.1 - 2022-01-01
16
+ ### Fixed
17
+ * Added missing `--chrome.appendToUserAgent` in the CLI help.
18
+
3
19
  ## 14.13.0 - 2021-12-30
4
20
  ### Added
5
21
  * Append text to Chrome/Edge user agent using `--chrome.appendToUserAgent` [#1688](https://github.com/sitespeedio/browsertime/pull/1688).
@@ -228,6 +228,15 @@ class Android {
228
228
  return this._runCommand('input keyevent KEYCODE_POWER');
229
229
  }
230
230
 
231
+ async getWifi() {
232
+ const rawWifiInfo = await this._runCommand(
233
+ `dumpsys netstats | grep -E 'iface=wlan.*networkId'`
234
+ );
235
+ const wifiInfo = (await adb.util.readAll(rawWifiInfo)).toString().trim();
236
+ const wifi = wifiInfo.match(/(?:"[^"]*"|^[^"]*$)/)[0].replace(/"/g, '');
237
+ return wifi;
238
+ }
239
+
231
240
  async closeAppNotRespondingPopup() {
232
241
  const result = await this._runCommandAndGet('dumpsys window windows');
233
242
  if (result.indexOf('Application Not Responding') > -1) {
@@ -105,13 +105,15 @@ class Chromium {
105
105
  await this.cdpClient.setupCPUThrottling(this.chrome.CPUThrottlingRate);
106
106
  }
107
107
 
108
- if (this.chrome.appendToUserAgent) {
108
+ if (this.chrome.appendToUserAgent || this.options.appendToUserAgent) {
109
109
  const currentUserAgent = await runner.runScript(
110
110
  'return navigator.userAgent;',
111
111
  'GET_USER_AGENT'
112
112
  );
113
113
  await this.cdpClient.setUserAgent(
114
- currentUserAgent + ' ' + this.chrome.appendToUserAgent
114
+ currentUserAgent +
115
+ ' ' +
116
+ (this.chrome.appendToUserAgent || this.options.appendToUserAgent)
115
117
  );
116
118
  } else if (this.chrome.mobileEmulation && this.options.userAgent) {
117
119
  // Hack to set user agent for mobile emulation
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const http = require('http');
4
+ const https = require('https');
5
+ const get = require('lodash.get');
6
+ const log = require('intel').getLogger('browsertime.connectivity.humble');
7
+
8
+ class Humble {
9
+ constructor(options) {
10
+ this.url = get(options.connectivity, 'humble.url');
11
+ this.profile = options.connectivity.profile;
12
+ }
13
+
14
+ async start(profile) {
15
+ const lib = this.url.startsWith('https') ? https : http;
16
+ const res = await new Promise(resolve => {
17
+ if (this.profile !== 'custom') {
18
+ lib.get(`${this.url}/api/${this.profile}`, resolve);
19
+ } else {
20
+ lib.get(
21
+ `${this.url}/api/custom?up=${profile.up}&down=${profile.down}&rtt=${profile.rtt}`,
22
+ resolve
23
+ );
24
+ }
25
+ });
26
+
27
+ let data = await new Promise((resolve, reject) => {
28
+ let data = '';
29
+ res.on('data', chunk => (data += chunk));
30
+ res.on('error', err => reject(err));
31
+ res.on('end', () => resolve(data));
32
+ });
33
+
34
+ if (res.statusCode !== 200) {
35
+ log.error('Humble response: %s', data);
36
+ } else {
37
+ log.info('Switch Humble at %s to use profile %s', this.url, this.profile);
38
+ }
39
+ }
40
+
41
+ async stop() {
42
+ const lib = this.url.startsWith('https') ? https : http;
43
+ const res = await new Promise(resolve => {
44
+ lib.get(`${this.url}/api/stop`, resolve);
45
+ });
46
+
47
+ let data = await new Promise((resolve, reject) => {
48
+ let data = '';
49
+ res.on('data', chunk => (data += chunk));
50
+ res.on('error', err => reject(err));
51
+ res.on('end', () => resolve(data));
52
+ });
53
+
54
+ if (res.statusCode !== 200) {
55
+ log.error('Humble response: %s', data);
56
+ } else {
57
+ log.info('Humble throttling stopped successfully');
58
+ }
59
+ }
60
+ }
61
+
62
+ module.exports = Humble;
@@ -5,8 +5,10 @@ const get = require('lodash.get');
5
5
  const throttle = require('@sitespeed.io/throttle');
6
6
  const log = require('intel').getLogger('browsertime.connectivity');
7
7
  const TSProxy = require('./tsProxy');
8
+ const Humble = require('./humble');
8
9
 
9
10
  let tsProxyInstance = null;
11
+ let humble = null;
10
12
 
11
13
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
12
14
  function getRandomIntInclusive(min, max) {
@@ -73,6 +75,10 @@ module.exports = {
73
75
  tsProxyInstance = new TSProxy(options);
74
76
  return tsProxyInstance.start(profile);
75
77
  }
78
+ case 'humble': {
79
+ humble = new Humble(options);
80
+ return humble.start(profile);
81
+ }
76
82
  }
77
83
  },
78
84
  getConnectivitySettings(options) {
@@ -96,6 +102,9 @@ module.exports = {
96
102
  case 'tsproxy': {
97
103
  return tsProxyInstance.stop();
98
104
  }
105
+ case 'humble': {
106
+ return humble.stop();
107
+ }
99
108
  }
100
109
  }
101
110
  };
@@ -180,6 +180,14 @@ class Engine {
180
180
  log.info('Battery temperature is %s, lets start the tests', temp);
181
181
  }
182
182
  }
183
+
184
+ if (
185
+ this.options.connectivity &&
186
+ this.options.connectivity.engine === 'humble'
187
+ ) {
188
+ const wifiName = await android.getWifi();
189
+ log.info('The phone is using the WiFi: %s', wifiName);
190
+ }
183
191
  }
184
192
 
185
193
  if (this.options.safari && this.options.safari.useSimulator) {
@@ -55,7 +55,21 @@ class Firefox {
55
55
  /**
56
56
  * Before the first iteration of your tests start.
57
57
  */
58
- async beforeStartIteration() {}
58
+ async beforeStartIteration(runner) {
59
+ if (
60
+ this.firefoxConfig.appendToUserAgent ||
61
+ this.options.appendToUserAgent
62
+ ) {
63
+ const currentUserAgent = await runner.runScript(
64
+ 'return navigator.userAgent;',
65
+ 'GET_USER_AGENT'
66
+ );
67
+ let script = `Services.prefs.setStringPref('general.useragent.override', '${currentUserAgent} ${
68
+ this.firefoxConfig.appendToUserAgent || this.options.appendToUserAgent
69
+ }');`;
70
+ return runner.runPrivilegedScript(script, 'SET_USER_AGENT');
71
+ }
72
+ }
59
73
 
60
74
  /**
61
75
  * Before each URL/test runs.
@@ -93,6 +93,12 @@ function validateInput(argv) {
93
93
  }
94
94
  }
95
95
 
96
+ if (argv.connectivity && argv.connectivity.engine === 'humble') {
97
+ if (!argv.connectivity.humble || !argv.connectivity.humble.url) {
98
+ return 'You need to specify the URL to Humble by using the --connectivity.humble.url option.';
99
+ }
100
+ }
101
+
96
102
  if (
97
103
  argv.firefox &&
98
104
  ((argv.firefox.nightly && argv.firefox.beta) ||
@@ -282,6 +288,11 @@ module.exports.parseCommandLine = function parseCommandLine() {
282
288
  describe: 'Collect Chromes console log and save to disk.',
283
289
  group: 'chrome'
284
290
  })
291
+ .option('chrome.appendToUserAgent', {
292
+ type: 'string',
293
+ describe: 'Append to the user agent.',
294
+ group: 'chrome'
295
+ })
285
296
  .option('chrome.noDefaultOptions', {
286
297
  type: 'boolean',
287
298
  describe:
@@ -350,6 +361,11 @@ module.exports.parseCommandLine = function parseCommandLine() {
350
361
  group: 'firefox'
351
362
  })
352
363
 
364
+ .option('firefox.appendToUserAgent', {
365
+ type: 'string',
366
+ describe: 'Append to the user agent.',
367
+ group: 'firefox'
368
+ })
353
369
  .option('firefox.nightly', {
354
370
  describe:
355
371
  'Use Firefox Nightly. Works on OS X. For Linux you need to set the binary path.',
@@ -927,9 +943,9 @@ module.exports.parseCommandLine = function parseCommandLine() {
927
943
  })
928
944
  .option('connectivity.engine', {
929
945
  default: 'external',
930
- choices: ['external', 'throttle', 'tsproxy'],
946
+ choices: ['external', 'throttle', 'tsproxy', 'humble'],
931
947
  describe:
932
- 'The engine for connectivity. Throttle works on Mac and tc based Linux. Use external if you set the connectivity outside of Browsertime. The best way do to this is described in https://github.com/sitespeedio/browsertime#connectivity.',
948
+ 'The engine for connectivity. Throttle works on Mac and tc based Linux. For mobile you can use Humble if you have a Humble setup. Use external if you set the connectivity outside of Browsertime. The best way do to this is described in https://github.com/sitespeedio/browsertime#connectivity.',
933
949
  group: 'connectivity'
934
950
  })
935
951
  .option('connectivity.throttle.localhost', {
@@ -939,6 +955,12 @@ module.exports.parseCommandLine = function parseCommandLine() {
939
955
  'Add latency/delay on localhost. Perfect for testing with WebPageReplay',
940
956
  group: 'connectivity'
941
957
  })
958
+ .option('connectivity.humble.url', {
959
+ type: 'string',
960
+ describe:
961
+ 'The path to your Humble instance. For example http://raspberrypi:3000',
962
+ group: 'connectivity'
963
+ })
942
964
  .option('requestheader', {
943
965
  alias: 'r',
944
966
  describe:
@@ -1002,6 +1024,10 @@ module.exports.parseCommandLine = function parseCommandLine() {
1002
1024
  .option('userAgent', {
1003
1025
  describe: 'Override user agent'
1004
1026
  })
1027
+ .option('appendToUserAgent', {
1028
+ describe:
1029
+ 'Append a String to the user agent. Works in Chrome/Edge and Firefox.'
1030
+ })
1005
1031
  .option('silent', {
1006
1032
  alias: 'q',
1007
1033
  type: 'count',
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "description": "Browsertime",
3
- "version": "14.13.0",
3
+ "version": "14.15.0",
4
4
  "bin": "./bin/browsertime.js",
5
5
  "dependencies": {
6
6
  "@sitespeed.io/throttle": "3.0.0",
7
7
  "@devicefarmer/adbkit": "2.11.3",
8
8
  "btoa": "1.2.1",
9
- "@sitespeed.io/chromedriver": "96.0.4664-35",
9
+ "@sitespeed.io/chromedriver": "97.0.4692-7b",
10
10
  "chrome-har": "0.12.0",
11
11
  "chrome-remote-interface": "0.31.0",
12
12
  "dayjs": "1.10.7",