browsertime 21.6.1 → 21.7.1

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,8 +1,21 @@
1
1
  # Browsertime changelog (we do [semantic versioning](https://semver.org))
2
2
 
3
+ ## 21.7.1 - 2024-04-03
4
+ ### Fixed
5
+ * Bug fix: If you test a URL that failed, we got an error that didn't produce the browsertime.json [#2120](https://github.com/sitespeedio/browsertime/pull/2120).
6
+ * Updated to Seleniuym webdriver 4.20.0 [#2121](https://github.com/sitespeedio/browsertime/pull/2121).
7
+
8
+ ## 21.7.0 - 2024-04-03
9
+ ### Added
10
+ * Edge and Edgedriver 123 [#2116](https://github.com/sitespeedio/browsertime/pull/2116).
11
+
12
+ ### Fixed
13
+ * Updated to Selenium 4.19.0 [#2117](https://github.com/sitespeedio/browsertime/pull/2117).
14
+ * Block domains using Bidi instead of the extension server for Firefox [#2118](https://github.com/sitespeedio/browsertime/pull/2118).
15
+
3
16
  ## 21.6.1 - 2024-03-22
4
17
  ### Fixed
5
- * Fix runnimg Safari TP. Thank you [KS](https://github.com/92kns) for PR [#2115](https://github.com/sitespeedio/browsertime/pull/2115).
18
+ * Fix running Safari TP. Thank you [KS](https://github.com/92kns) for PR [#2115](https://github.com/sitespeedio/browsertime/pull/2115).
6
19
 
7
20
  ## 21.6.0 - 2024-03-20
8
21
  ### Added
@@ -25,6 +25,7 @@ export class Debug {
25
25
  * Adds a breakpoint to the script. The browser will pause at the breakpoint, waiting for user input to continue.
26
26
  * This is useful for debugging and inspecting the browser state at a specific point in the script.
27
27
  *
28
+ * @example await commands.debug.breakpoint('break');
28
29
  * @async
29
30
  * @param {string} [name] - An optional name for the breakpoint for logging purposes.
30
31
  * @returns {Promise<void>} A promise that resolves when the user chooses to continue from the breakpoint.
@@ -24,6 +24,7 @@ export class Navigation {
24
24
  * Navigates backward in the browser's history.
25
25
  *
26
26
  * @async
27
+ * @example await commands.navigation.back();
27
28
  * @param {Object} [options] - Additional options for navigation. Set {wait:true} to wait for the page complete check to run.
28
29
  * @returns {Promise<void>} A promise that resolves when the navigation action is completed.
29
30
  * @throws {Error} Throws an error if navigation fails.
@@ -46,6 +47,7 @@ export class Navigation {
46
47
  * Navigates forward in the browser's history.
47
48
  *
48
49
  * @async
50
+ * @example await commands.navigation.forward();
49
51
  * @param {Object} [options] - Additional options for navigation. Set {wait:true} to wait for the page complete check to run.
50
52
  * @returns {Promise<void>} A promise that resolves when the navigation action is completed.
51
53
  * @throws {Error} Throws an error if navigation fails.
@@ -68,6 +70,7 @@ export class Navigation {
68
70
  * Refreshes the current page.
69
71
  *
70
72
  * @async
73
+ * @example await commands.navigation.refresh();
71
74
  * @param {Object} [options] - Additional options for refresh action. Set {wait:true} to wait for the page complete check to run.
72
75
  * @returns {Promise<void>} A promise that resolves when the page has been refreshed.
73
76
  * @throws {Error} Throws an error if refreshing the page fails.
@@ -335,11 +335,18 @@ export class Engine {
335
335
  const extras = await engineDelegate.getHARs();
336
336
 
337
337
  // Backfill the fully loaded data that we extract from the HAR
338
- if (!options.skipHar && extras.har) {
338
+ // Only do this if we actually had requests
339
+ if (
340
+ !options.skipHar &&
341
+ extras.har &&
342
+ extras.har.log &&
343
+ extras.har.log.entries.length > 0
344
+ ) {
339
345
  const fullyLoadedPerUrl = getFullyLoaded(extras.har);
340
346
  for (let data of fullyLoadedPerUrl) {
341
347
  collector.addFullyLoaded(data.url, data.fullyLoaded);
342
348
  }
349
+
343
350
  // Add the timings from the main document
344
351
  const timings = getMainDocumentTimings(extras.har);
345
352
  for (let timing of timings) {
@@ -17,7 +17,6 @@ export class ExtensionServer {
17
17
  return options.browser === 'firefox' &&
18
18
  (options.cacheClearRaw ||
19
19
  options.requestheader ||
20
- options.block ||
21
20
  options.clearCacheKeepCookies)
22
21
  ? true
23
22
  : false;
@@ -6,9 +6,7 @@ const delay = ms => new Promise(res => setTimeout(res, ms));
6
6
 
7
7
  function generateURL(port, testUrl, options) {
8
8
  const query = {};
9
- if (options.block) {
10
- query.bl = toArray(options.block);
11
- }
9
+
12
10
  if (options.requestheader) {
13
11
  query.rh = toArray(options.requestheader);
14
12
  }
@@ -29,6 +29,55 @@ export class FirefoxBidi {
29
29
  }
30
30
  }
31
31
 
32
+ async blockUrls(blockers) {
33
+ // bin/browsertime.js --block upload.wikimedia.org https://en.wikipedia.org/wiki/Barack_Obama -n 1 -b firefox
34
+ const patterns = [];
35
+ const block = toArray(blockers);
36
+ for (let b of block) {
37
+ // Block a specific URL
38
+ if (b.startsWith('http')) {
39
+ patterns.push({ type: 'string', pattern: b });
40
+ } else {
41
+ // Block by domain
42
+ patterns.push({ type: 'pattern', hostname: b });
43
+ }
44
+ }
45
+
46
+ const bidi = new Bidi(this.driver, this.options.browser);
47
+
48
+ const command = {
49
+ method: 'network.addIntercept',
50
+ params: {
51
+ phases: ['beforeRequestSent'],
52
+ urlPatterns: patterns
53
+ }
54
+ };
55
+ const result = await bidi.send(command);
56
+ if (result.type != 'success') {
57
+ log.error(result);
58
+ }
59
+
60
+ await bidi.subscribe('network.beforeRequestSent');
61
+
62
+ await bidi.onMessage(async function (event) {
63
+ const parsedEvent = JSON.parse(Buffer.from(event.toString()));
64
+ if (
65
+ parsedEvent.method === 'network.beforeRequestSent' &&
66
+ parsedEvent.params.isBlocked === true
67
+ ) {
68
+ const fail = {
69
+ method: 'network.failRequest',
70
+ params: {
71
+ request: parsedEvent.params.request.request
72
+ }
73
+ };
74
+ const result = await bidi.send(fail);
75
+ if (result.type != 'success') {
76
+ log.error(result);
77
+ }
78
+ }
79
+ });
80
+ }
32
81
  async setBasicAuth(basicAuth) {
33
82
  const parts = basicAuth.split('@');
34
83
  const bidi = new Bidi(this.driver, this.options.browser);
@@ -97,6 +97,10 @@ export class Firefox {
97
97
  await this.browsertimeBidi.setBasicAuth(this.options.basicAuth);
98
98
  }
99
99
 
100
+ if (this.options.block) {
101
+ await this.browsertimeBidi.blockUrls(this.options.block);
102
+ }
103
+
100
104
  if (
101
105
  this.firefoxConfig.appendToUserAgent ||
102
106
  this.options.appendToUserAgent
@@ -1099,7 +1099,7 @@ export function parseCommandLine() {
1099
1099
  })
1100
1100
  .option('block', {
1101
1101
  describe:
1102
- 'Domain to block or URL or URL pattern to block. If you use Chrome you can also use --blockDomainsExcept (that is more performant). Works in Chrome/Edge. For Firefox you can only block domains.'
1102
+ 'Domain to block or URL or URL pattern to block. If you use Chrome you can also use --blockDomainsExcept (that is more performant). Works in Chrome/Edge. For Firefox you block a URL if you start with http else you will block by setting a domain, like upload.wikimedia.org'
1103
1103
  })
1104
1104
  .option('percentiles', {
1105
1105
  type: 'array',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "browsertime",
3
3
  "description": "Get performance metrics from your web page using Browsertime.",
4
- "version": "21.6.1",
4
+ "version": "21.7.1",
5
5
  "bin": "./bin/browsertime.js",
6
6
  "type": "module",
7
7
  "types": "./types/scripting.d.ts",
@@ -9,7 +9,7 @@
9
9
  "@cypress/xvfb": "1.2.4",
10
10
  "@devicefarmer/adbkit": "3.2.6",
11
11
  "@sitespeed.io/chromedriver": "123.0.6312-58",
12
- "@sitespeed.io/edgedriver": "122.0.2365-92",
12
+ "@sitespeed.io/edgedriver": "123.0.2420-53",
13
13
  "@sitespeed.io/geckodriver": "0.34.0",
14
14
  "@sitespeed.io/throttle": "5.0.0",
15
15
  "@sitespeed.io/tracium": "0.3.3",
@@ -30,7 +30,7 @@
30
30
  "lodash.merge": "4.6.2",
31
31
  "lodash.pick": "4.4.0",
32
32
  "lodash.set": "4.3.2",
33
- "selenium-webdriver": "4.18.1",
33
+ "selenium-webdriver": "4.20.0",
34
34
  "yargs": "17.7.2"
35
35
  },
36
36
  "optionalDependencies": {
@@ -19,6 +19,7 @@ export class Debug {
19
19
  * Adds a breakpoint to the script. The browser will pause at the breakpoint, waiting for user input to continue.
20
20
  * This is useful for debugging and inspecting the browser state at a specific point in the script.
21
21
  *
22
+ * @example await commands.debug.breakpoint('break');
22
23
  * @async
23
24
  * @param {string} [name] - An optional name for the breakpoint for logging purposes.
24
25
  * @returns {Promise<void>} A promise that resolves when the user chooses to continue from the breakpoint.
@@ -1 +1 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../../lib/core/engine/command/debug.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH;IACE,wCASC;IARC;;OAEG;IACH,gBAAsB;IACtB;;OAEG;IACH,gBAAsB;IAGxB;;;;;;;OAOG;IACH,kBAHW,MAAM,GACJ,QAAQ,IAAI,CAAC,CA+BzB;CACF"}
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../../lib/core/engine/command/debug.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH;IACE,wCASC;IARC;;OAEG;IACH,gBAAsB;IACtB;;OAEG;IACH,gBAAsB;IAGxB;;;;;;;;OAQG;IACH,kBAHW,MAAM,GACJ,QAAQ,IAAI,CAAC,CA+BzB;CACF"}
@@ -18,6 +18,7 @@ export class Navigation {
18
18
  * Navigates backward in the browser's history.
19
19
  *
20
20
  * @async
21
+ * @example await commands.navigation.back();
21
22
  * @param {Object} [options] - Additional options for navigation. Set {wait:true} to wait for the page complete check to run.
22
23
  * @returns {Promise<void>} A promise that resolves when the navigation action is completed.
23
24
  * @throws {Error} Throws an error if navigation fails.
@@ -27,6 +28,7 @@ export class Navigation {
27
28
  * Navigates forward in the browser's history.
28
29
  *
29
30
  * @async
31
+ * @example await commands.navigation.forward();
30
32
  * @param {Object} [options] - Additional options for navigation. Set {wait:true} to wait for the page complete check to run.
31
33
  * @returns {Promise<void>} A promise that resolves when the navigation action is completed.
32
34
  * @throws {Error} Throws an error if navigation fails.
@@ -36,6 +38,7 @@ export class Navigation {
36
38
  * Refreshes the current page.
37
39
  *
38
40
  * @async
41
+ * @example await commands.navigation.refresh();
39
42
  * @param {Object} [options] - Additional options for refresh action. Set {wait:true} to wait for the page complete check to run.
40
43
  * @returns {Promise<void>} A promise that resolves when the page has been refreshed.
41
44
  * @throws {Error} Throws an error if refreshing the page fails.
@@ -1 +1 @@
1
- {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../../../lib/core/engine/command/navigation.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;IACE,kDASC;IARC;;OAEG;IACH,gBAAsB;IACtB;;OAEG;IACH,0BAA0C;IAG5C;;;;;;;OAOG;IACH,qBAHa,QAAQ,IAAI,CAAC,CAezB;IAED;;;;;;;OAOG;IACH,wBAHa,QAAQ,IAAI,CAAC,CAezB;IAED;;;;;;;OAOG;IACH,wBAHa,QAAQ,IAAI,CAAC,CAezB;CACF"}
1
+ {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../../../lib/core/engine/command/navigation.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;IACE,kDASC;IARC;;OAEG;IACH,gBAAsB;IACtB;;OAEG;IACH,0BAA0C;IAG5C;;;;;;;;OAQG;IACH,qBAHa,QAAQ,IAAI,CAAC,CAezB;IAED;;;;;;;;OAQG;IACH,wBAHa,QAAQ,IAAI,CAAC,CAezB;IAED;;;;;;;;OAQG;IACH,wBAHa,QAAQ,IAAI,CAAC,CAezB;CACF"}