browsertime 17.0.0-beta.3 → 17.0.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 (98) hide show
  1. package/CHANGELOG.md +47 -12
  2. package/bin/browsertime.js +5 -8
  3. package/bin/browsertimeWebPageReplay.js +2 -2
  4. package/index.js +2 -2
  5. package/lib/android/gnirehtet.js +1 -2
  6. package/lib/android/root.js +57 -16
  7. package/lib/chrome/chromeDevtoolsProtocol.js +2 -3
  8. package/lib/chrome/har.js +1 -1
  9. package/lib/chrome/longTaskMetrics.js +1 -1
  10. package/lib/chrome/parseCpuTrace.js +2 -2
  11. package/lib/chrome/settings/chromeAndroidOptions.js +1 -1
  12. package/lib/chrome/settings/chromeDesktopOptions.js +1 -1
  13. package/lib/chrome/settings/traceCategories.js +1 -1
  14. package/lib/chrome/traceCategoriesParser.js +3 -3
  15. package/lib/chrome/webdriver/builder.js +1 -1
  16. package/lib/chrome/webdriver/chromium.js +13 -17
  17. package/lib/chrome/webdriver/setupChromiumOptions.js +18 -13
  18. package/lib/connectivity/humble.js +10 -12
  19. package/lib/connectivity/index.js +1 -1
  20. package/lib/core/engine/collector.js +2 -4
  21. package/lib/core/engine/command/addText.js +1 -2
  22. package/lib/core/engine/command/android.js +1 -1
  23. package/lib/core/engine/command/cache.js +1 -2
  24. package/lib/core/engine/command/chromeDevToolsProtocol.js +1 -2
  25. package/lib/core/engine/command/click.js +1 -2
  26. package/lib/core/engine/command/debug.js +1 -3
  27. package/lib/core/engine/command/javaScript.js +1 -2
  28. package/lib/core/engine/command/measure.js +13 -15
  29. package/lib/core/engine/command/meta.js +1 -1
  30. package/lib/core/engine/command/navigation.js +1 -1
  31. package/lib/core/engine/command/screenshot.js +1 -1
  32. package/lib/core/engine/command/scroll.js +1 -1
  33. package/lib/core/engine/command/select.js +1 -1
  34. package/lib/core/engine/command/set.js +1 -1
  35. package/lib/core/engine/command/stopWatch.js +1 -1
  36. package/lib/core/engine/command/switch.js +44 -1
  37. package/lib/core/engine/command/util/lcpHighlightScript.js +1 -1
  38. package/lib/core/engine/command/util/lsHighlightScript.js +1 -1
  39. package/lib/core/engine/command/wait.js +1 -1
  40. package/lib/core/engine/index.js +33 -15
  41. package/lib/core/engine/iteration.js +35 -42
  42. package/lib/core/engine/run.js +1 -1
  43. package/lib/core/pageCompleteChecks/defaultPageCompleteCheck.js +1 -1
  44. package/lib/core/pageCompleteChecks/pageCompleteCheckByInactivity.js +1 -1
  45. package/lib/core/pageCompleteChecks/spaInactivity.js +1 -1
  46. package/lib/core/seleniumRunner.js +9 -11
  47. package/lib/edge/webdriver/builder.js +1 -1
  48. package/lib/extensionserver/index.js +2 -4
  49. package/lib/extensionserver/setup.js +1 -1
  50. package/lib/firefox/geckoProfiler.js +46 -16
  51. package/lib/firefox/getHAR.js +1 -1
  52. package/lib/firefox/memoryReport.js +1 -1
  53. package/lib/firefox/settings/disableSafeBrowsingPreferences.js +1 -1
  54. package/lib/firefox/settings/disableTrackingProtectionPreferences.js +1 -1
  55. package/lib/firefox/settings/firefoxPreferences.js +1 -1
  56. package/lib/firefox/webdriver/builder.js +9 -9
  57. package/lib/firefox/webdriver/firefox.js +24 -6
  58. package/lib/safari/webdriver/safari.js +1 -1
  59. package/lib/screenshot/defaults.js +1 -1
  60. package/lib/screenshot/index.js +3 -5
  61. package/lib/support/cli.js +11 -5
  62. package/lib/support/dns.js +1 -1
  63. package/lib/support/engineUtils.js +60 -66
  64. package/lib/support/getViewPort.js +1 -1
  65. package/lib/support/har/index.js +6 -8
  66. package/lib/support/images/index.js +1 -1
  67. package/lib/support/logging.js +1 -1
  68. package/lib/support/pathToFolder.js +4 -4
  69. package/lib/support/preURL.js +1 -1
  70. package/lib/support/processes.js +1 -1
  71. package/lib/support/setResourceTimingBufferSize.js +1 -1
  72. package/lib/support/stop.js +1 -1
  73. package/lib/support/storageManager.js +1 -3
  74. package/lib/support/tcpdump.js +2 -2
  75. package/lib/support/xvfb.js +2 -4
  76. package/lib/video/postprocessing/finetune/addTextToVideo.js +3 -3
  77. package/lib/video/postprocessing/finetune/convertFps.js +1 -1
  78. package/lib/video/postprocessing/finetune/getFont.js +1 -1
  79. package/lib/video/postprocessing/finetune/getTimingMetrics.js +2 -2
  80. package/lib/video/postprocessing/finetune/index.js +4 -4
  81. package/lib/video/postprocessing/finetune/removeOrange.js +1 -1
  82. package/lib/video/postprocessing/visualmetrics/extraMetrics.js +1 -1
  83. package/lib/video/postprocessing/visualmetrics/getVideoMetrics.js +2 -2
  84. package/lib/video/screenRecording/android/recorder.js +1 -1
  85. package/lib/video/screenRecording/desktop/convert.js +1 -1
  86. package/lib/video/screenRecording/desktop/desktopRecorder.js +3 -3
  87. package/lib/video/screenRecording/desktop/ffmpegRecorder.js +6 -6
  88. package/lib/video/screenRecording/desktop/osx/getSPDisplaysDataType.js +1 -1
  89. package/lib/video/screenRecording/desktop/osx/getScreen.js +1 -1
  90. package/lib/video/screenRecording/firefox/firefoxWindowRecorder.js +1 -1
  91. package/lib/video/screenRecording/ios/convertToMp4.js +1 -1
  92. package/lib/video/screenRecording/ios/iosRecorder.js +2 -2
  93. package/lib/video/screenRecording/iosSimulator/convertToMp4.js +1 -1
  94. package/lib/video/screenRecording/iosSimulator/recorder.js +2 -2
  95. package/lib/video/screenRecording/recorder.js +6 -6
  96. package/lib/video/screenRecording/setOrangeBackground.js +1 -1
  97. package/lib/video/video.js +9 -11
  98. package/package.json +17 -17
@@ -1,6 +1,6 @@
1
1
  import intel from 'intel';
2
2
  const log = intel.getLogger('browsertime.command.cache');
3
- class Cache {
3
+ export class Cache {
4
4
  constructor(browser, browserName, extensionServer, cdp) {
5
5
  this.browser = browser;
6
6
  this.browserName = browserName;
@@ -45,4 +45,3 @@ class Cache {
45
45
  }
46
46
  }
47
47
  }
48
- export default Cache;
@@ -2,7 +2,7 @@ import intel from 'intel';
2
2
  const log = intel.getLogger('browsertime.command.devtoolsprotocol');
3
3
 
4
4
  // https://chromedevtools.github.io/devtools-protocol/
5
- class DevelopmentToolsProtocol {
5
+ export class ChromeDevelopmentToolsProtocol {
6
6
  constructor(engineDelegate, browserName) {
7
7
  this.engineDelegate = engineDelegate;
8
8
  this.browserName = browserName;
@@ -70,4 +70,3 @@ class DevelopmentToolsProtocol {
70
70
  }
71
71
  }
72
72
  }
73
- export default DevelopmentToolsProtocol;
@@ -10,7 +10,7 @@ function addClick(js) {
10
10
  return script;
11
11
  }
12
12
 
13
- class Click {
13
+ export class Click {
14
14
  constructor(browser, pageCompleteCheck) {
15
15
  this.browser = browser;
16
16
  this.pageCompleteCheck = pageCompleteCheck;
@@ -269,4 +269,3 @@ class Click {
269
269
  }
270
270
  }
271
271
  }
272
- export default Click;
@@ -2,7 +2,7 @@ import intel from 'intel';
2
2
  const log = intel.getLogger('browsertime.command.debug');
3
3
  const delay = ms => new Promise(res => setTimeout(res, ms));
4
4
 
5
- class Debug {
5
+ export class Debug {
6
6
  constructor(browser, options) {
7
7
  this.browser = browser;
8
8
  this.options = options;
@@ -43,5 +43,3 @@ class Debug {
43
43
  }
44
44
  }
45
45
  }
46
-
47
- export default Debug;
@@ -1,6 +1,6 @@
1
1
  import intel from 'intel';
2
2
  const log = intel.getLogger('browsertime.command.javascript');
3
- class JavaScript {
3
+ export class JavaScript {
4
4
  constructor(browser, pageCompleteCheck) {
5
5
  this.browser = browser;
6
6
  this.pageCompleteCheck = pageCompleteCheck;
@@ -97,4 +97,3 @@ class JavaScript {
97
97
  }
98
98
  }
99
99
  }
100
- export default JavaScript;
@@ -3,14 +3,14 @@ import intel from 'intel';
3
3
  import get from 'lodash.get';
4
4
  import merge from 'lodash.merge';
5
5
  import { timestamp as _timestamp } from '../../../support/engineUtils.js';
6
- import Video from '../../../video/video.js';
7
- import pathToFolder from '../../../support/pathToFolder.js';
8
- import setOrangeBackground from '../../../video/screenRecording/setOrangeBackground.js';
6
+ import { Video } from '../../../video/video.js';
7
+ import { pathToFolder } from '../../../support/pathToFolder.js';
8
+ import { setOrangeBackground } from '../../../video/screenRecording/setOrangeBackground.js';
9
9
  import { filterWhitelisted } from '../../../support/userTiming.js';
10
10
  import { isAndroidConfigured, Android } from '../../../android/index.js';
11
- import TCPDump from '../../../support/tcpdump.js';
12
- import highlightLargestContentfulPaint from './util/lcpHighlightScript.js';
13
- import highlightLS from './util/lsHighlightScript.js';
11
+ import { TCPDump } from '../../../support/tcpdump.js';
12
+ import { lcpHighlightScript as highlightLargestContentfulPaint } from './util/lcpHighlightScript.js';
13
+ import { clsHighlightScript as highlightLS } from './util/lsHighlightScript.js';
14
14
  const delay = ms => new Promise(res => setTimeout(res, ms));
15
15
  const log = intel.getLogger('browsertime.command.measure');
16
16
 
@@ -27,7 +27,7 @@ function getNewResult() {
27
27
  };
28
28
  }
29
29
 
30
- class Measure {
30
+ export class Measure {
31
31
  constructor(
32
32
  browser,
33
33
  index,
@@ -105,10 +105,10 @@ class Measure {
105
105
  _error(message) {
106
106
  // If we already are measuring a page, associate the error woth that page
107
107
  if (this.areWeMeasuring === true) {
108
- if (!this.result[this.numberOfMeasuredPages].error) {
109
- this.result[this.numberOfMeasuredPages].error = [message];
110
- } else {
108
+ if (this.result[this.numberOfMeasuredPages].error) {
111
109
  this.result[this.numberOfMeasuredPages].error.push(message);
110
+ } else {
111
+ this.result[this.numberOfMeasuredPages].error = [message];
112
112
  }
113
113
  } else {
114
114
  // If we have tested pages before, but not in the making of
@@ -360,10 +360,10 @@ class Measure {
360
360
  this.result[this.numberOfMeasuredPages].alias
361
361
  ) {
362
362
  const alias = this.result[this.numberOfMeasuredPages].alias;
363
- if (!aliasAndUrl[alias]) {
364
- aliasAndUrl[alias] = url;
365
- } else {
363
+ if (aliasAndUrl[alias]) {
366
364
  url = aliasAndUrl[alias];
365
+ } else {
366
+ aliasAndUrl[alias] = url;
367
367
  }
368
368
  }
369
369
 
@@ -522,5 +522,3 @@ class Measure {
522
522
  this.areWeMeasuring = false;
523
523
  }
524
524
  }
525
-
526
- export default Measure;
@@ -1,4 +1,4 @@
1
- export default class Meta {
1
+ export class Meta {
2
2
  constructor() {}
3
3
 
4
4
  setDescription(text) {
@@ -1,7 +1,7 @@
1
1
  import intel from 'intel';
2
2
  const log = intel.getLogger('browsertime.command.navigation');
3
3
 
4
- export default class Navigation {
4
+ export class Navigation {
5
5
  constructor(browser, pageCompleteCheck) {
6
6
  this.browser = browser;
7
7
  this.pageCompleteCheck = pageCompleteCheck;
@@ -1,4 +1,4 @@
1
- export default class Screenshot {
1
+ export class Screenshot {
2
2
  constructor(screenshotManager, browser, index) {
3
3
  this.screenshotManager = screenshotManager;
4
4
  this.browser = browser;
@@ -1,7 +1,7 @@
1
1
  import intel from 'intel';
2
2
  const log = intel.getLogger('browsertime.command.scroll');
3
3
  const delay = ms => new Promise(res => setTimeout(res, ms));
4
- export default class Scroll {
4
+ export class Scroll {
5
5
  constructor(browser, options) {
6
6
  this.browser = browser;
7
7
  this.options = options;
@@ -1,7 +1,7 @@
1
1
  import intel from 'intel';
2
2
  const log = intel.getLogger('browsertime.command.select');
3
3
 
4
- export default class Select {
4
+ export class Select {
5
5
  constructor(browser) {
6
6
  this.browser = browser;
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import intel from 'intel';
2
2
  const log = intel.getLogger('browsertime.command.set');
3
3
 
4
- export default class Set {
4
+ export class Set {
5
5
  constructor(browser) {
6
6
  this.browser = browser;
7
7
  }
@@ -47,7 +47,7 @@ export class StopWatch {
47
47
  }
48
48
  }
49
49
 
50
- export default class Watch {
50
+ export class Watch {
51
51
  constructor(measure) {
52
52
  this.measure = measure;
53
53
  }
@@ -1,7 +1,8 @@
1
1
  import intel from 'intel';
2
+ import { By } from 'selenium-webdriver';
2
3
  const log = intel.getLogger('browsertime.command.switch');
3
4
 
4
- export default class Switch {
5
+ export class Switch {
5
6
  constructor(browser, pageCompleteCheck, navigate) {
6
7
  this.browser = browser;
7
8
  this.pageCompleteCheck = pageCompleteCheck;
@@ -23,6 +24,48 @@ export default class Switch {
23
24
  }
24
25
  }
25
26
 
27
+ /**
28
+ * Switch to frame by xpath
29
+ * @param {*} xpath
30
+ */
31
+ async toFrameByXpath(xpath) {
32
+ const driver = this.browser.getDriver();
33
+ try {
34
+ const element = await driver.findElement(By.xpath(xpath));
35
+ if (element) {
36
+ await driver.switchTo().frame(element);
37
+ } else {
38
+ log.error('Could not find frame using xpath %s ', xpath);
39
+ throw new Error(`Could not find frame using xpath ${xpath}`);
40
+ }
41
+ } catch (error) {
42
+ log.error('Could not switch to frame using xpath %s ', xpath);
43
+ log.verbose(error);
44
+ throw new Error(`Could not switch to frame using xpath ${xpath}`);
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Switch to frame by xpath
50
+ * @param {*} xpath
51
+ */
52
+ async toFrameBySelector(selector) {
53
+ const driver = this.browser.getDriver();
54
+ try {
55
+ const element = await driver.findElement(By.css(selector));
56
+ if (element) {
57
+ await driver.switchTo().frame(element);
58
+ } else {
59
+ log.error('Could not find frame using selector%s ', selector);
60
+ throw new Error(`Could not find frame using selector ${selector}`);
61
+ }
62
+ } catch (error) {
63
+ log.error('Could not switch to frame using selector %s ', selector);
64
+ log.verbose(error);
65
+ throw new Error(`Could not switch to frame using selector${selector}`);
66
+ }
67
+ }
68
+
26
69
  /**
27
70
  * Switch to a window by name
28
71
  * @param {*} name
@@ -1,4 +1,4 @@
1
- export default `
1
+ export const lcpHighlightScript = `
2
2
  return (function(color) {
3
3
  const observer = new PerformanceObserver(list => {});
4
4
  observer.observe({ type: 'largest-contentful-paint', buffered: true });
@@ -1,4 +1,4 @@
1
- export default `
1
+ export const clsHighlightScript = `
2
2
  (function(options) {
3
3
  const rectColor = options.color;
4
4
  const limit = options.limit;
@@ -3,7 +3,7 @@ import intel from 'intel';
3
3
  const log = intel.getLogger('browsertime.command.wait');
4
4
  const delay = ms => new Promise(res => setTimeout(res, ms));
5
5
 
6
- export default class Wait {
6
+ export class Wait {
7
7
  constructor(browser, pageCompleteCheck) {
8
8
  this.browser = browser;
9
9
  this.pageCompleteCheck = pageCompleteCheck;
@@ -4,10 +4,10 @@ import merge from 'lodash.merge';
4
4
  import getPort, { portNumbers } from 'get-port';
5
5
  import { execaCommand as command } from 'execa';
6
6
  import get from 'lodash.get';
7
- import StorageManager from '../../support/storageManager.js';
8
- import Firefox from '../../firefox/webdriver/firefox.js';
9
- import Chromium from '../../chrome/webdriver/chromium.js';
10
- import Safari from '../../safari/webdriver/safari.js';
7
+ import { StorageManager } from '../../support/storageManager.js';
8
+ import { Firefox } from '../../firefox/webdriver/firefox.js';
9
+ import { Chromium } from '../../chrome/webdriver/chromium.js';
10
+ import { Safari } from '../../safari/webdriver/safari.js';
11
11
  import {
12
12
  addConnectivity,
13
13
  removeConnectivity
@@ -18,15 +18,15 @@ import {
18
18
  getMainDocumentTimings,
19
19
  addExtraFieldsToHar
20
20
  } from '../../support/har/index.js';
21
- import XVFB from '../../support/xvfb.js';
22
- import Gnirehtet from '../../android/gnirehtet.js';
23
- import Iteration from './iteration.js';
24
- import Collector from './collector.js';
21
+ import { XVFB } from '../../support/xvfb.js';
22
+ import { Gnirehtet } from '../../android/gnirehtet.js';
23
+ import { Iteration } from './iteration.js';
24
+ import { Collector } from './collector.js';
25
25
  import { Android, isAndroidConfigured } from '../../android/index.js';
26
- import RootedDevice from '../../android/root.js';
27
- import run from './run.js';
28
- import { loadScript } from '../../support/engineUtils.js';
29
- import IOSRecorder from '../../video/screenRecording/ios/iosRecorder.js';
26
+ import { RootedDevice } from '../../android/root.js';
27
+ import { run } from './run.js';
28
+ import { IOSRecorder } from '../../video/screenRecording/ios/iosRecorder.js';
29
+ import { loadPrePostScripts, loadScript } from '../../support/engineUtils.js';
30
30
  const log = intel.getLogger('browsertime');
31
31
  const defaults = {
32
32
  scripts: [],
@@ -45,7 +45,7 @@ function shouldDelay(index, total, delay) {
45
45
  * Create a new Browsertime Engine.
46
46
  * @class
47
47
  */
48
- export default class Engine {
48
+ export class Engine {
49
49
  constructor(options) {
50
50
  this.options = merge({}, defaults, options);
51
51
  if (log.isEnabledFor(log.DEBUG)) {
@@ -252,11 +252,30 @@ export default class Engine {
252
252
  engineDelegate = new Safari(storageManager, options);
253
253
  }
254
254
  }
255
+
256
+ let preScripts, postScripts, postURLScripts, pageCompleteCheck;
257
+
258
+ try {
259
+ preScripts = await loadPrePostScripts(options.preScript, options);
260
+ postScripts = await loadPrePostScripts(options.postScript, options);
261
+ postURLScripts = await loadPrePostScripts(options.postURLScript, options);
262
+ pageCompleteCheck = options.pageCompleteCheck
263
+ ? await loadScript(options.pageCompleteCheck, options)
264
+ : undefined;
265
+ } catch (error) {
266
+ log.error(error.message);
267
+ throw error;
268
+ }
269
+
255
270
  const iteration = new Iteration(
256
271
  storageManager,
257
272
  engineDelegate,
258
273
  scriptsByCategory,
259
274
  asyncScriptsByCategory,
275
+ preScripts,
276
+ postScripts,
277
+ postURLScripts,
278
+ pageCompleteCheck,
260
279
  options
261
280
  );
262
281
 
@@ -425,8 +444,7 @@ export default class Engine {
425
444
  if (Array.isArray(urlOrFile)) {
426
445
  script = urlOrFile[1];
427
446
  }
428
-
429
- script = await loadScript(script, true);
447
+ script = await loadScript(script, options, true);
430
448
 
431
449
  if (script.setUp) {
432
450
  if (!options.preScript) {
@@ -2,38 +2,34 @@ import { platform } from 'node:os';
2
2
  import webdriver from 'selenium-webdriver';
3
3
  import intel from 'intel';
4
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';
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 { Video } from '../../video/video.js';
11
+ import { stop } from '../../support/stop.js';
12
+ import { AddText } from './command/addText.js';
13
+ import { Click } from './command/click.js';
14
+ import { Wait } from './command/wait.js';
15
+ import { Measure } from './command/measure.js';
16
+ import { JavaScript } from './command/javaScript.js';
17
+ import { Switch } from './command/switch.js';
18
+ import { Screenshot } from './command/screenshot.js';
19
+ import { Set } from './command/set.js';
20
+ import { Cache } from './command/cache.js';
21
+ import { Meta } from './command/meta.js';
22
+ import { Watch as StopWatch } from './command/stopWatch.js';
23
+ import { Select } from './command/select.js';
24
+ import { Debug } from './command/debug.js';
25
+ import { AndroidCommand } from './command/android.js';
26
+ import { ChromeDevelopmentToolsProtocol } from './command/chromeDevToolsProtocol.js';
31
27
  import {
32
28
  addConnectivity,
33
29
  removeConnectivity
34
30
  } from '../../connectivity/index.js';
35
31
  import { jsonifyVisualProgress } from '../../support/util.js';
36
- import flushDNS from '../../support/dns.js';
32
+ import { flushDNS } from '../../support/dns.js';
37
33
  import {
38
34
  SingleClick,
39
35
  DoubleClick,
@@ -41,10 +37,10 @@ import {
41
37
  ContextClick,
42
38
  MouseMove
43
39
  } from './command/mouse/index.js';
44
- import getNumberOfRunningProcesses from '../../support/processes.js';
40
+ import { getNumberOfRunningProcesses } from '../../support/processes.js';
45
41
  import { isAndroidConfigured, Android } from '../../android/index.js';
46
- import Scroll from './command/scroll.js';
47
- import Navigation from './command/navigation.js';
42
+ import { Scroll } from './command/scroll.js';
43
+ import { Navigation } from './command/navigation.js';
48
44
  const log = intel.getLogger('browsertime');
49
45
  const delay = ms => new Promise(res => setTimeout(res, ms));
50
46
 
@@ -55,25 +51,22 @@ const ANDROID_DELAY_TIME = 2000;
55
51
  * Browsertime will do through one iteration of testing a URL.
56
52
  * @class
57
53
  */
58
- export default class Iteration {
54
+ export class Iteration {
59
55
  constructor(
60
56
  storageManager,
61
57
  engineDelegate,
62
58
  scriptsByCategory,
63
59
  asyncScriptsByCategory,
60
+ preScripts,
61
+ postScripts,
62
+ postURLScripts,
63
+ pageCompleteCheck,
64
64
  options
65
65
  ) {
66
- try {
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;
76
- }
66
+ this.preScripts = preScripts;
67
+ this.postScripts = postScripts;
68
+ this.postURLScripts = postURLScripts;
69
+ this.pageCompleteCheck = pageCompleteCheck;
77
70
  this.options = options;
78
71
  this.storageManager = storageManager;
79
72
  this.engineDelegate = engineDelegate;
@@ -1,4 +1,4 @@
1
- export default function (urlOrFunctions) {
1
+ export function run(urlOrFunctions) {
2
2
  return async function (context, commands) {
3
3
  for (let urlOrFunction of urlOrFunctions) {
4
4
  await (typeof urlOrFunction === 'function'
@@ -1,4 +1,4 @@
1
- export default `
1
+ export const defaultPageCompleteCheck = `
2
2
  return (function(waitTime) {
3
3
  try {
4
4
  var end = window.performance.timing.loadEventEnd;
@@ -1,4 +1,4 @@
1
- export default `
1
+ export const pageCompleteCheckByInactivity = `
2
2
  return (function(waitTime) {
3
3
  const timing = window.performance.timing;
4
4
  const p = window.performance;
@@ -1,4 +1,4 @@
1
- export default `
1
+ export const spaInactivity = `
2
2
  return (function(waitTime) {
3
3
  const timing = window.performance.timing;
4
4
  const p = window.performance;
@@ -5,10 +5,10 @@ import { Condition } from 'selenium-webdriver';
5
5
  import { isAndroidConfigured } from '../android/index.js';
6
6
  import { UrlLoadError, BrowserError, TimeoutError } from '../support/errors.js';
7
7
  import { createWebDriver } from './webdriver/index.js';
8
- import getViewPort from '../support/getViewPort.js';
9
- import defaultPageCompleteCheck from './pageCompleteChecks/defaultPageCompleteCheck.js';
10
- import pageCompleteCheckByInactivity from './pageCompleteChecks/pageCompleteCheckByInactivity.js';
11
- import spaCheck from './pageCompleteChecks/spaInactivity.js';
8
+ import { getViewPort } from '../support/getViewPort.js';
9
+ import { defaultPageCompleteCheck } from './pageCompleteChecks/defaultPageCompleteCheck.js';
10
+ import { pageCompleteCheckByInactivity } from './pageCompleteChecks/pageCompleteCheckByInactivity.js';
11
+ import { spaInactivity as spaCheck } from './pageCompleteChecks/spaInactivity.js';
12
12
  const log = intel.getLogger('browsertime');
13
13
 
14
14
  const defaults = {
@@ -49,7 +49,7 @@ async function timeout(promise, ms, errorMessage) {
49
49
  * Wrapper for Selenium.
50
50
  * @class
51
51
  */
52
- class SeleniumRunner {
52
+ export class SeleniumRunner {
53
53
  constructor(baseDir, options) {
54
54
  this.options = merge({}, defaults, options);
55
55
  this.baseDir = baseDir;
@@ -296,10 +296,7 @@ class SeleniumRunner {
296
296
  `Could not load ${url} is the web page down?`,
297
297
  url
298
298
  );
299
- } else if (newURI !== startURI) {
300
- // We navigated to a new page, we don't need to test anymore
301
- break;
302
- } else {
299
+ } else if (newURI === startURI) {
303
300
  const waitTime = (this.options.retryWaitTime || 10_000) * (index + 1);
304
301
  totalWaitTime += waitTime;
305
302
  log.debug(
@@ -322,6 +319,9 @@ class SeleniumRunner {
322
319
  'Will check again if the browser has navigated to the page'
323
320
  );
324
321
  }
322
+ } else {
323
+ // We navigated to a new page, we don't need to test anymore
324
+ break;
325
325
  }
326
326
  } catch (error) {
327
327
  log.info(
@@ -667,5 +667,3 @@ class SeleniumRunner {
667
667
  return results;
668
668
  }
669
669
  }
670
-
671
- export default SeleniumRunner;
@@ -4,7 +4,7 @@ import get from 'lodash.get';
4
4
  import pick from 'lodash.pick';
5
5
  import isEmpty from 'lodash.isempty';
6
6
  import { logging } from 'selenium-webdriver';
7
- import setupChromiumOptions from '../../chrome/webdriver/setupChromiumOptions.js';
7
+ import { setupChromiumOptions } from '../../chrome/webdriver/setupChromiumOptions.js';
8
8
  const log = intel.getLogger('browsertime.edge');
9
9
  const { pac, manual } = 'selenium-webdriver/proxy.js';
10
10
 
@@ -1,5 +1,5 @@
1
1
  import { startServer, stopServer } from './httpServer.js';
2
- import setup from './setup.js';
2
+ import { setup } from './setup.js';
3
3
 
4
4
  /**
5
5
  * Create a ExtensionServer. The extension server helps us with
@@ -7,7 +7,7 @@ import setup from './setup.js';
7
7
  * use a WebExtension to prepare our tests.
8
8
  * @class
9
9
  */
10
- class ExtensionServer {
10
+ export class ExtensionServer {
11
11
  constructor(options) {
12
12
  this.options = options;
13
13
  }
@@ -48,5 +48,3 @@ class ExtensionServer {
48
48
  }
49
49
  }
50
50
  }
51
-
52
- export default ExtensionServer;
@@ -46,7 +46,7 @@ function generateURL(port, testUrl, options) {
46
46
  });
47
47
  }
48
48
 
49
- export default async function (url, browser, port, options) {
49
+ export async function setup(url, browser, port, options) {
50
50
  const configUrl = generateURL(port, url, options);
51
51
  log.debug('Configuring browser plugin via %s', configUrl);
52
52
  await browser.loadAndWait(configUrl);