browsertime 16.16.0 → 17.0.0-beta.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.
Files changed (121) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/bin/browsertime.js +43 -43
  3. package/bin/browsertimeWebPageReplay.js +10 -9
  4. package/browserscripts/pageinfo/generator.js +1 -1
  5. package/index.js +14 -13
  6. package/lib/android/gnirehtet.js +14 -15
  7. package/lib/android/index.js +92 -89
  8. package/lib/android/root.js +6 -9
  9. package/lib/chrome/chromeDevtoolsProtocol.js +46 -45
  10. package/lib/chrome/har.js +12 -13
  11. package/lib/chrome/longTaskMetrics.js +3 -5
  12. package/lib/chrome/parseCpuTrace.js +13 -10
  13. package/lib/chrome/settings/chromeAndroidOptions.js +1 -3
  14. package/lib/chrome/settings/chromeDesktopOptions.js +1 -3
  15. package/lib/chrome/settings/traceCategories.js +1 -3
  16. package/lib/chrome/traceCategoriesParser.js +35 -36
  17. package/lib/chrome/webdriver/builder.js +18 -26
  18. package/lib/chrome/webdriver/chromium.js +56 -46
  19. package/lib/chrome/webdriver/setupChromiumOptions.js +32 -27
  20. package/lib/connectivity/humble.js +13 -14
  21. package/lib/connectivity/index.js +74 -77
  22. package/lib/connectivity/trafficShapeParser.js +31 -35
  23. package/lib/core/engine/collector.js +25 -22
  24. package/lib/core/engine/command/addText.js +24 -27
  25. package/lib/core/engine/command/android.js +7 -11
  26. package/lib/core/engine/command/cache.js +3 -4
  27. package/lib/core/engine/command/chromeDevToolsProtocol.js +20 -20
  28. package/lib/core/engine/command/click.js +48 -49
  29. package/lib/core/engine/command/debug.js +3 -4
  30. package/lib/core/engine/command/javaScript.js +18 -19
  31. package/lib/core/engine/command/measure.js +31 -37
  32. package/lib/core/engine/command/meta.js +1 -4
  33. package/lib/core/engine/command/mouse/clickAndHold.js +36 -39
  34. package/lib/core/engine/command/mouse/contextClick.js +17 -18
  35. package/lib/core/engine/command/mouse/doubleClick.js +17 -19
  36. package/lib/core/engine/command/mouse/index.js +5 -9
  37. package/lib/core/engine/command/mouse/mouseMove.js +19 -23
  38. package/lib/core/engine/command/mouse/singleClick.js +15 -19
  39. package/lib/core/engine/command/navigation.js +12 -14
  40. package/lib/core/engine/command/screenshot.js +1 -4
  41. package/lib/core/engine/command/scroll.js +4 -7
  42. package/lib/core/engine/command/select.js +26 -26
  43. package/lib/core/engine/command/set.js +25 -23
  44. package/lib/core/engine/command/stopWatch.js +5 -8
  45. package/lib/core/engine/command/switch.js +18 -20
  46. package/lib/core/engine/command/util/lcpHighlightScript.js +1 -2
  47. package/lib/core/engine/command/util/lsHighlightScript.js +1 -2
  48. package/lib/core/engine/command/wait.js +18 -18
  49. package/lib/core/engine/index.js +81 -71
  50. package/lib/core/engine/iteration.js +93 -79
  51. package/lib/core/engine/run.js +5 -9
  52. package/lib/core/pageCompleteChecks/defaultPageCompleteCheck.js +1 -2
  53. package/lib/core/pageCompleteChecks/pageCompleteCheckByInactivity.js +1 -3
  54. package/lib/core/pageCompleteChecks/spaInactivity.js +1 -3
  55. package/lib/core/seleniumRunner.js +92 -100
  56. package/lib/core/webdriver/index.js +24 -21
  57. package/lib/edge/webdriver/builder.js +21 -26
  58. package/lib/extensionserver/httpServer.js +17 -21
  59. package/lib/extensionserver/index.js +8 -12
  60. package/lib/extensionserver/setup.js +12 -12
  61. package/lib/firefox/geckoProfiler.js +27 -21
  62. package/lib/firefox/getHAR.js +7 -8
  63. package/lib/firefox/memoryReport.js +9 -11
  64. package/lib/firefox/perfStats.js +5 -7
  65. package/lib/firefox/settings/disableSafeBrowsingPreferences.js +1 -3
  66. package/lib/firefox/settings/disableTrackingProtectionPreferences.js +1 -3
  67. package/lib/firefox/settings/firefoxPreferences.js +2 -4
  68. package/lib/firefox/settings/geckoProfilerDefaults.js +5 -9
  69. package/lib/firefox/webdriver/builder.js +66 -63
  70. package/lib/firefox/webdriver/firefox.js +43 -48
  71. package/lib/safari/webdriver/builder.js +4 -5
  72. package/lib/safari/webdriver/safari.js +4 -8
  73. package/lib/screenshot/defaults.js +1 -3
  74. package/lib/screenshot/index.js +24 -21
  75. package/lib/support/browserScript.js +65 -56
  76. package/lib/support/cli.js +123 -85
  77. package/lib/support/dns.js +6 -7
  78. package/lib/support/engineUtils.js +85 -38
  79. package/lib/support/errors.js +4 -13
  80. package/lib/support/fileUtil.js +81 -68
  81. package/lib/support/filters.js +15 -20
  82. package/lib/support/getViewPort.js +6 -7
  83. package/lib/support/har/index.js +208 -216
  84. package/lib/support/images/index.js +54 -26
  85. package/lib/support/logging.js +20 -17
  86. package/lib/support/pathToFolder.js +18 -23
  87. package/lib/support/preURL.js +5 -6
  88. package/lib/support/processes.js +4 -6
  89. package/lib/support/setResourceTimingBufferSize.js +2 -4
  90. package/lib/support/statistics.js +58 -56
  91. package/lib/support/stop.js +7 -8
  92. package/lib/support/storageManager.js +44 -44
  93. package/lib/support/tcpdump.js +22 -16
  94. package/lib/support/userTiming.js +7 -13
  95. package/lib/support/util.js +204 -224
  96. package/lib/support/xvfb.js +11 -13
  97. package/lib/video/defaults.js +6 -10
  98. package/lib/video/postprocessing/finetune/addTextToVideo.js +15 -15
  99. package/lib/video/postprocessing/finetune/convertFps.js +14 -8
  100. package/lib/video/postprocessing/finetune/getFont.js +7 -9
  101. package/lib/video/postprocessing/finetune/getTimingMetrics.js +19 -18
  102. package/lib/video/postprocessing/finetune/index.js +40 -36
  103. package/lib/video/postprocessing/finetune/removeOrange.js +10 -11
  104. package/lib/video/postprocessing/visualmetrics/extraMetrics.js +17 -13
  105. package/lib/video/postprocessing/visualmetrics/getVideoMetrics.js +12 -13
  106. package/lib/video/postprocessing/visualmetrics/visualMetrics.js +117 -128
  107. package/lib/video/screenRecording/android/recorder.js +12 -17
  108. package/lib/video/screenRecording/desktop/convert.js +13 -11
  109. package/lib/video/screenRecording/desktop/desktopRecorder.js +29 -24
  110. package/lib/video/screenRecording/desktop/ffmpegRecorder.js +60 -63
  111. package/lib/video/screenRecording/desktop/osx/getSPDisplaysDataType.js +4 -6
  112. package/lib/video/screenRecording/desktop/osx/getScreen.js +9 -10
  113. package/lib/video/screenRecording/firefox/firefoxWindowRecorder.js +54 -54
  114. package/lib/video/screenRecording/ios/convertToMp4.js +10 -11
  115. package/lib/video/screenRecording/ios/iosRecorder.js +23 -21
  116. package/lib/video/screenRecording/iosSimulator/convertToMp4.js +10 -11
  117. package/lib/video/screenRecording/iosSimulator/recorder.js +10 -9
  118. package/lib/video/screenRecording/recorder.js +8 -9
  119. package/lib/video/screenRecording/setOrangeBackground.js +5 -6
  120. package/lib/video/video.js +28 -34
  121. package/package.json +19 -17
@@ -1,46 +1,51 @@
1
- 'use strict';
2
- const os = require('os');
3
- const webdriver = require('selenium-webdriver');
4
- const log = require('intel').getLogger('browsertime');
5
- const SeleniumRunner = require('../seleniumRunner');
6
- const preURL = require('../../support/preURL');
7
- const setResourceTimingBufferSize = require('../../support/setResourceTimingBufferSize');
8
- const ScreenshotManager = require('../../screenshot/');
9
- const ExtensionServer = require('../../extensionserver/');
10
- const engineUtils = require('../../support/engineUtils');
11
- const Video = require('../../video/video');
12
- const stop = require('../../support/stop');
13
- const AddText = require('./command/addText.js');
14
- const Click = require('./command/click.js');
15
- const Wait = require('./command/wait.js');
16
- const Measure = require('./command/measure.js');
17
- const JavaScript = require('./command/javaScript.js');
18
- const Switch = require('./command/switch.js');
19
- const Screenshot = require('./command/screenshot.js');
20
- const Set = require('./command/set.js');
21
- const Cache = require('./command/cache.js');
22
- const Meta = require('./command/meta.js');
23
- const StopWatch = require('./command/stopWatch.js');
24
- const Select = require('./command/select.js');
25
- const Debug = require('./command/debug.js');
26
- const AndroidCommand = require('./command/android.js');
27
- const ChromeDevToolsProtocol = require('./command/chromeDevToolsProtocol.js');
28
- const { addConnectivity, removeConnectivity } = require('../../connectivity');
29
- const util = require('../../support/util.js');
30
- const flushDNS = require('../../support/dns.js');
31
- const {
1
+ import { platform } from 'node:os';
2
+ import webdriver from 'selenium-webdriver';
3
+ import intel from 'intel';
4
+
5
+ import SeleniumRunner from '../seleniumRunner.js';
6
+ import preURL from '../../support/preURL.js';
7
+ import setResourceTimingBufferSize from '../../support/setResourceTimingBufferSize.js';
8
+ import ScreenshotManager from '../../screenshot/index.js';
9
+ import ExtensionServer from '../../extensionserver/index.js';
10
+ import {
11
+ loadPrePostScriptsSync,
12
+ loadScriptSync
13
+ } from '../../support/engineUtils.js';
14
+ import Video from '../../video/video.js';
15
+ import stop from '../../support/stop.js';
16
+ import AddText from './command/addText.js';
17
+ import Click from './command/click.js';
18
+ import Wait from './command/wait.js';
19
+ import Measure from './command/measure.js';
20
+ import JavaScript from './command/javaScript.js';
21
+ import Switch from './command/switch.js';
22
+ import Screenshot from './command/screenshot.js';
23
+ import Set from './command/set.js';
24
+ import Cache from './command/cache.js';
25
+ import Meta from './command/meta.js';
26
+ import StopWatch from './command/stopWatch.js';
27
+ import Select from './command/select.js';
28
+ import Debug from './command/debug.js';
29
+ import AndroidCommand from './command/android.js';
30
+ import ChromeDevelopmentToolsProtocol from './command/chromeDevToolsProtocol.js';
31
+ import {
32
+ addConnectivity,
33
+ removeConnectivity
34
+ } from '../../connectivity/index.js';
35
+ import { jsonifyVisualProgress } from '../../support/util.js';
36
+ import flushDNS from '../../support/dns.js';
37
+ import {
32
38
  SingleClick,
33
39
  DoubleClick,
34
40
  ClickAndHold,
35
41
  ContextClick,
36
42
  MouseMove
37
- } = require('./command/mouse/');
38
- const getNumberOfRunningProcesses = require('../../support/processes');
39
-
40
- const { isAndroidConfigured, Android } = require('../../android');
41
- const Scroll = require('./command/scroll');
42
- const Navigation = require('./command/navigation');
43
-
43
+ } from './command/mouse/index.js';
44
+ import getNumberOfRunningProcesses from '../../support/processes.js';
45
+ import { isAndroidConfigured, Android } from '../../android/index.js';
46
+ import Scroll from './command/scroll.js';
47
+ import Navigation from './command/navigation.js';
48
+ const log = intel.getLogger('browsertime');
44
49
  const delay = ms => new Promise(res => setTimeout(res, ms));
45
50
 
46
51
  // Make this configurable
@@ -50,7 +55,7 @@ const ANDROID_DELAY_TIME = 2000;
50
55
  * Browsertime will do through one iteration of testing a URL.
51
56
  * @class
52
57
  */
53
- class Iteration {
58
+ export default class Iteration {
54
59
  constructor(
55
60
  storageManager,
56
61
  engineDelegate,
@@ -59,17 +64,15 @@ class Iteration {
59
64
  options
60
65
  ) {
61
66
  try {
62
- this.preScripts = engineUtils.loadPrePostScripts(options.preScript);
63
- this.postScripts = engineUtils.loadPrePostScripts(options.postScript);
64
- this.postURLScripts = engineUtils.loadPrePostScripts(
65
- options.postURLScript
66
- );
67
- this.pageCompleteCheck = engineUtils.loadScript(
68
- options.pageCompleteCheck
69
- );
70
- } catch (e) {
71
- log.error(e.message);
72
- throw e;
67
+ this.preScripts = loadPrePostScriptsSync(options.preScript);
68
+ this.postScripts = loadPrePostScriptsSync(options.postScript);
69
+ this.postURLScripts = loadPrePostScriptsSync(options.postURLScript);
70
+ this.pageCompleteCheck = options.pageCompleteCheck
71
+ ? loadScriptSync(options.pageCompleteCheck)
72
+ : undefined;
73
+ } catch (error) {
74
+ log.error(error.message);
75
+ throw error;
73
76
  }
74
77
  this.options = options;
75
78
  this.storageManager = storageManager;
@@ -85,8 +88,8 @@ class Iteration {
85
88
  * @param {*} index - Which iteration it is
86
89
  */
87
90
  async run(navigationScript, index) {
88
- if (os.platform() === 'darwin' || os.platform() === 'linux') {
89
- this.processesAtStart = new Number(await getNumberOfRunningProcesses());
91
+ if (platform() === 'darwin' || platform() === 'linux') {
92
+ this.processesAtStart = Number(await getNumberOfRunningProcesses());
90
93
  }
91
94
  const screenshotManager = new ScreenshotManager(
92
95
  this.storageManager,
@@ -151,7 +154,10 @@ class Iteration {
151
154
  options
152
155
  );
153
156
 
154
- const cdp = new ChromeDevToolsProtocol(engineDelegate, options.browser);
157
+ const cdp = new ChromeDevelopmentToolsProtocol(
158
+ engineDelegate,
159
+ options.browser
160
+ );
155
161
  const android = new Android(options);
156
162
  const debug = new Debug(browser, options);
157
163
  const commands = {
@@ -225,10 +231,10 @@ class Iteration {
225
231
 
226
232
  try {
227
233
  await navigationScript(context, commands, this.postURLScripts);
228
- } catch (e) {
229
- commands.error(e.message);
230
- commands.markAsFailure(e.message);
231
- throw e;
234
+ } catch (error) {
235
+ commands.error(error.message);
236
+ commands.markAsFailure(error.message);
237
+ throw error;
232
238
  }
233
239
  if (commands.measure.areWeMeasuring === true) {
234
240
  // someone forgot to call stop();
@@ -259,7 +265,17 @@ class Iteration {
259
265
  if (options.browser === 'firefox' && options.debug) {
260
266
  log.info('Firefox is kept open in debug mode');
261
267
  } else {
262
- await browser.stop();
268
+ if (isAndroidConfigured(options) && options.ignoreShutdownFailures) {
269
+ try {
270
+ log.info('Ignoring shutdown failures on android...');
271
+ await browser.stop();
272
+ } catch {
273
+ // Ignore shutdown failures on android
274
+ log.info('Shutdown problem hit, ignoring...');
275
+ }
276
+ } else {
277
+ await browser.stop();
278
+ }
263
279
  }
264
280
  // Give the browsers some time to stop
265
281
  await delay(2000);
@@ -271,12 +287,12 @@ class Iteration {
271
287
  }
272
288
 
273
289
  if (options.visualMetrics && !options.videoParams.debug) {
274
- let i = 0;
290
+ let index_ = 0;
275
291
  for (let myVideo of videos) {
276
292
  try {
277
293
  const videoMetrics = await myVideo.postProcessing(
278
- result[i].browserScripts.timings.pageTimings,
279
- result[i].browserScripts.pageinfo.visualElements
294
+ result[index_].browserScripts.timings.pageTimings,
295
+ result[index_].browserScripts.pageinfo.visualElements
280
296
  );
281
297
 
282
298
  for (let progress of [
@@ -285,20 +301,20 @@ class Iteration {
285
301
  'PerceptualSpeedIndexProgress'
286
302
  ]) {
287
303
  if (videoMetrics.visualMetrics[progress]) {
288
- videoMetrics.visualMetrics[progress] =
289
- util.jsonifyVisualProgress(
290
- videoMetrics.visualMetrics[progress]
291
- );
304
+ videoMetrics.visualMetrics[progress] = jsonifyVisualProgress(
305
+ videoMetrics.visualMetrics[progress]
306
+ );
292
307
  }
293
308
  }
294
- result[i].videoRecordingStart = videoMetrics.videoRecordingStart;
295
- result[i].visualMetrics = videoMetrics.visualMetrics;
296
- i++;
297
- } catch (e) {
309
+ result[index_].videoRecordingStart =
310
+ videoMetrics.videoRecordingStart;
311
+ result[index_].visualMetrics = videoMetrics.visualMetrics;
312
+ index_++;
313
+ } catch (error) {
298
314
  // If one of the Visual Metrics runs fail, try the next one
299
- log.error('Visual Metrics failed to analyse the video', e);
300
- if (result[i]) {
301
- result[i].error.push(e.message);
315
+ log.error('Visual Metrics failed to analyse the video', error);
316
+ if (result[index_]) {
317
+ result[index_].error.push(error.message);
302
318
  }
303
319
  }
304
320
  }
@@ -323,8 +339,8 @@ class Iteration {
323
339
 
324
340
  result.processesAtStart = this.processesAtStart;
325
341
  return result;
326
- } catch (e) {
327
- log.error(e);
342
+ } catch (error) {
343
+ log.error(error);
328
344
  if (recordVideo && options.videoParams.debug) {
329
345
  // Just use the first URL
330
346
  const url =
@@ -336,9 +352,9 @@ class Iteration {
336
352
  if (options.docker && recordVideo && !isAndroidConfigured(options)) {
337
353
  await stop('ffmpeg');
338
354
  }
339
- result.error = [e.name];
355
+ result.error = [error.name];
340
356
  result.markedAsFailure = 1;
341
- result.failureMessages = [e.message];
357
+ result.failureMessages = [error.message];
342
358
  return result;
343
359
  } finally {
344
360
  // Here we should also make sure FFMPEG is really killed/stopped
@@ -352,11 +368,9 @@ class Iteration {
352
368
  } else {
353
369
  await browser.stop();
354
370
  }
355
- } catch (e) {
371
+ } catch {
356
372
  // Most cases the browser been stopped already
357
373
  }
358
374
  }
359
375
  }
360
376
  }
361
-
362
- module.exports = Iteration;
@@ -1,13 +1,9 @@
1
- 'use strict';
2
-
3
- module.exports = function (urlOrFunctions) {
1
+ export default function (urlOrFunctions) {
4
2
  return async function (context, commands) {
5
3
  for (let urlOrFunction of urlOrFunctions) {
6
- if (typeof urlOrFunction === 'function') {
7
- await urlOrFunction(context, commands);
8
- } else {
9
- await commands.measure.start(urlOrFunction);
10
- }
4
+ await (typeof urlOrFunction === 'function'
5
+ ? urlOrFunction(context, commands)
6
+ : commands.measure.start(urlOrFunction));
11
7
  }
12
8
  };
13
- };
9
+ }
@@ -1,5 +1,4 @@
1
- 'use strict';
2
- module.exports = `
1
+ export default `
3
2
  return (function(waitTime) {
4
3
  try {
5
4
  var end = window.performance.timing.loadEventEnd;
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports = `
1
+ export default `
4
2
  return (function(waitTime) {
5
3
  const timing = window.performance.timing;
6
4
  const p = window.performance;
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports = `
1
+ export default `
4
2
  return (function(waitTime) {
5
3
  const timing = window.performance.timing;
6
4
  const p = window.performance;