browsertime 21.5.1 → 21.5.3

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,14 @@
1
1
  # Browsertime changelog (we do [semantic versioning](https://semver.org))
2
2
 
3
+ ## 21.5.3 - 2024-03-12
4
+ ### Fixed
5
+ * Fixed `commands.bidi.*` that stopped working [#2101](https://github.com/sitespeedio/browsertime/pull/2101).
6
+ * Fixed missing Loaf data [#2100](https://github.com/sitespeedio/browsertime/pull/2100).
7
+
8
+ ## 21.5.2 - 2024-03-12
9
+ ### Fixed
10
+ * Another bug fix: Getting Long Animation Frame (loaf) was broken [#2099](https://github.com/sitespeedio/browsertime/pull/2099).
11
+
3
12
  ## 21.5.1 - 2024-03-12
4
13
  ### Fixed
5
14
  * There was a bug in how we collect CPU power from Firefox and add it to the statistics. Fixed in [#2098](https://github.com/sitespeedio/browsertime/pull/2098).
@@ -1,36 +1,45 @@
1
- (function() {
2
- // See https://developer.chrome.com/docs/web-platform/long-animation-frames
3
- if (PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')) {
4
-
1
+ (function () {
2
+ // See https://developer.chrome.com/docs/web-platform/long-animation-frames
3
+ if (
4
+ PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')
5
+ ) {
5
6
  const MAX_LOAFS_TO_CONSIDER = 10;
6
7
  const relevantLoadEntries = [];
7
- const observer = new PerformanceObserver(list => {
8
- let longestBlockingLoAFs = [].concat(list.getEntries()).sort(
9
- (a, b) => b.blockingDuration - a.blockingDuration
10
- ).slice(0, MAX_LOAFS_TO_CONSIDER);
8
+ const observer = new PerformanceObserver(list => {});
9
+ observer.observe({type: 'long-animation-frame', buffered: true});
10
+ const entries = observer.takeRecords();
11
11
 
12
- // re-package
13
- for (let entry of longestBlockingLoAFs) {
14
- const info = {};
15
- info.blockingDuration = entry.blockingDuration;
16
- info.duration = entry.duration;
17
- info.styleAndLayoutStart = entry.styleAndLayoutStart;
18
- info.renderStart = entry.renderStart;
19
- info.scripts = [];
20
- for (let script of entry.scripts) {
21
- const s = {};
22
- s.forcedStyleAndLayoutDuration = script.forcedStyleAndLayoutDuration;
23
- s.invoker = script.invoker;
24
- s.invokerType = script.invokerType;
25
- s.sourceFunctionName = script.sourceFunctionName;
26
- s.sourceURL = script.sourceURL;
27
- info.scripts.push(s);
28
- }
29
- relevantLoadEntries.push(info);
30
- }
31
- return relevantLoadEntries;
32
- });
33
- observer.observe({ type: 'long-animation-frame', buffered: true });
12
+ let longestBlockingLoAFs = []
13
+ .concat(entries)
14
+ .sort((a, b) => b.blockingDuration - a.blockingDuration)
15
+ .slice(0, MAX_LOAFS_TO_CONSIDER);
16
+
17
+ // re-package
18
+ for (let entry of longestBlockingLoAFs) {
19
+ const info = {};
20
+ info.blockingDuration = entry.blockingDuration;
21
+ info.duration = entry.duration;
22
+ info.styleAndLayoutStart = entry.styleAndLayoutStart;
23
+ info.renderStart = entry.renderStart;
24
+ info.workDuration = entry.renderStart ? entry.renderStart - entry.startTime : entry.duration;
25
+ info.renderDuration = entry.renderStart ? (entry.startTime + entry.duration) - entry.renderStart: 0;
26
+ info.preLayoutDuration = entry.styleAndLayoutStart ? entry.styleAndLayoutStart - entry.renderStart : 0;
27
+ info.styleAndLayoutDuration = entry.styleAndLayoutStart ? (entry.startTime + entry.duration) - entry.styleAndLayoutStart : 0
28
+
29
+ info.scripts = [];
30
+ for (let script of entry.scripts) {
31
+ const s = {};
32
+ s.forcedStyleAndLayoutDuration = script.forcedStyleAndLayoutDuration;
33
+ s.invoker = script.invoker;
34
+ s.invokerType = script.invokerType;
35
+ s.sourceFunctionName = script.sourceFunctionName;
36
+ s.sourceURL = script.sourceURL;
37
+ s.sourceCharPosition = script.sourceCharPosition;
38
+ s.windowAttribution = script.windowAttribution;
39
+ info.scripts.push(s);
40
+ }
41
+ relevantLoadEntries.push(info);
34
42
  }
43
+ return relevantLoadEntries;
44
+ }
35
45
  })();
36
-
@@ -23,12 +23,16 @@ export class Bidi {
23
23
  /**
24
24
  * Add a fanction that will get the events that you subscribes.
25
25
  * @async
26
+ * @example await commands.bidi.onMessage(function(event) {
27
+ * const myEvent = JSON.parse(Buffer.from(event.toString()));
28
+ * console.log(myEvent);
29
+ * });
26
30
  * @param {Function} f - The callback function to handle incoming messages. The function will get an event passed on to it. Remember to subscribe to the event.
27
31
  * @throws {Error} Throws an error if the method is called in a browser other than Firefox.
28
32
  */
29
33
  async onMessage(f) {
30
34
  if (this.browserName === 'firefox') {
31
- const client = await this.engineDelegate.getBidi();
35
+ const client = this.engineDelegate.getBidi();
32
36
  const ws = await client.socket;
33
37
  ws.on('message', f);
34
38
  } else {
@@ -38,12 +42,11 @@ export class Bidi {
38
42
 
39
43
  /**
40
44
  * Retrieves the raw client for Bidi.
41
- * @async
42
- * @example const bidi = await commands.bidi.getRawClient();
45
+ * @example const bidi = commands.bidi.getRawClient();
43
46
  * @returns {Promise<Object>} A promise that resolves to the Bidi client.
44
47
  * @throws {Error} Throws an error if the browser is not supported.
45
48
  */
46
- async getRawClient() {
49
+ getRawClient() {
47
50
  if (this.browserName === 'firefox') {
48
51
  return this.engineDelegate.getBidi();
49
52
  } else {
@@ -54,13 +57,15 @@ export class Bidi {
54
57
  /**
55
58
  * Subscribe to a event.
56
59
  * @async
60
+ * @example // Subscribe to requests before they are sent
61
+ * await commands.bidi.subscribe('network.beforeRequestSent');
57
62
  * @param {string} messageType The type of message to subscribe to.
58
63
  * @returns {Promise<Object>} A promise that resolves you have subscribed.
59
64
  * @throws {Error} Throws an error if the method is called in a browser other than Firefox.
60
65
  */
61
66
  async subscribe(messageType) {
62
67
  if (this.browserName === 'firefox') {
63
- const client = await this.engineDelegate.getBidi();
68
+ const client = this.engineDelegate.getBidi();
64
69
  return client.subscribe(messageType, [
65
70
  await this.engineDelegate.getWindowHandle()
66
71
  ]);
@@ -72,13 +77,15 @@ export class Bidi {
72
77
  /**
73
78
  * Unsubscribe to an event.
74
79
  * @async
80
+ * @example // Unsubscribe to requests before they are sent
81
+ * await commands.bidi.unsubscribe('network.beforeRequestSent');
75
82
  * @param {string} messageType The type of message to unsubscribe to.
76
83
  * @returns {Promise<Object>} A promise that resolves you have unsubscribed.
77
84
  * @throws {Error} Throws an error if the method is called in a browser other than Firefox.
78
85
  */
79
86
  async unsubscribe(messageType) {
80
87
  if (this.browserName === 'firefox') {
81
- const client = await this.engineDelegate.getBidi();
88
+ const client = this.engineDelegate.getBidi();
82
89
  return client.unsubscribe(messageType, [
83
90
  this.engineDelegate.getWindowHandle()
84
91
  ]);
@@ -91,7 +98,14 @@ export class Bidi {
91
98
  * Sends a command using Bidi.
92
99
  *
93
100
  * @async
94
- * @example await commands.bidi.send({});
101
+ * @example
102
+ * const params = {
103
+ * method: 'script.addPreloadScript',
104
+ * params: {
105
+ * functionDeclaration: "function() {alert('hello')}"
106
+ * }
107
+ * };
108
+ * await commands.bidi.send(params);
95
109
  * @param {Object} parameters - The paramaters for the command.
96
110
  * @throws {Error} Throws an error if the browser is not supported or if the command fails.
97
111
  * @returns {Promise<Object>} A promise that resolves when the command has been sent.
@@ -99,10 +113,14 @@ export class Bidi {
99
113
  async send(parameters) {
100
114
  if (this.browserName === 'firefox') {
101
115
  try {
102
- const client = await this.engineDelegate.getBidi();
116
+ const client = this.engineDelegate.getBidi();
103
117
  return client.send(parameters);
104
118
  } catch (error) {
105
- log.error('Could not send to Bidi command %j', parameters);
119
+ log.error(
120
+ 'Could not send to Bidi command %j, error: %s',
121
+ parameters,
122
+ error
123
+ );
106
124
  log.verbose(error);
107
125
  `Could not send to Bidi command ${parameters} `;
108
126
  }
@@ -13,7 +13,6 @@ import { GeckoProfiler } from '../geckoProfiler.js';
13
13
  import { MemoryReport } from '../memoryReport.js';
14
14
  import { PerfStats } from '../perfStats.js';
15
15
  import { NetworkManager } from '../networkManager.js';
16
- import { FirefoxBidi } from '../firefoxBidi.js';
17
16
  import { getHAR } from '../getHAR.js';
18
17
 
19
18
  const log = intel.getLogger('browsertime.firefox');
@@ -64,11 +63,7 @@ export class Firefox {
64
63
  });
65
64
  }
66
65
 
67
- this.bidi = new FirefoxBidi(
68
- await runner.getDriver().getBidi(),
69
- this.windowId,
70
- this.options
71
- );
66
+ this.bidi = await runner.getDriver().getBidi();
72
67
  }
73
68
 
74
69
  /**
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.5.1",
4
+ "version": "21.5.3",
5
5
  "bin": "./bin/browsertime.js",
6
6
  "type": "module",
7
7
  "types": "./types/scripting.d.ts",
@@ -18,14 +18,17 @@ export class Bidi {
18
18
  /**
19
19
  * Add a fanction that will get the events that you subscribes.
20
20
  * @async
21
+ * @example await commands.bidi.onMessage(function(event) {
22
+ * const myEvent = JSON.parse(Buffer.from(event.toString()));
23
+ * console.log(myEvent);
24
+ * });
21
25
  * @param {Function} f - The callback function to handle incoming messages. The function will get an event passed on to it. Remember to subscribe to the event.
22
26
  * @throws {Error} Throws an error if the method is called in a browser other than Firefox.
23
27
  */
24
28
  onMessage(f: Function): Promise<void>;
25
29
  /**
26
30
  * Retrieves the raw client for Bidi.
27
- * @async
28
- * @example const bidi = await commands.bidi.getRawClient();
31
+ * @example const bidi = commands.bidi.getRawClient();
29
32
  * @returns {Promise<Object>} A promise that resolves to the Bidi client.
30
33
  * @throws {Error} Throws an error if the browser is not supported.
31
34
  */
@@ -33,6 +36,8 @@ export class Bidi {
33
36
  /**
34
37
  * Subscribe to a event.
35
38
  * @async
39
+ * @example // Subscribe to requests before they are sent
40
+ * await commands.bidi.subscribe('network.beforeRequestSent');
36
41
  * @param {string} messageType The type of message to subscribe to.
37
42
  * @returns {Promise<Object>} A promise that resolves you have subscribed.
38
43
  * @throws {Error} Throws an error if the method is called in a browser other than Firefox.
@@ -41,6 +46,8 @@ export class Bidi {
41
46
  /**
42
47
  * Unsubscribe to an event.
43
48
  * @async
49
+ * @example // Unsubscribe to requests before they are sent
50
+ * await commands.bidi.unsubscribe('network.beforeRequestSent');
44
51
  * @param {string} messageType The type of message to unsubscribe to.
45
52
  * @returns {Promise<Object>} A promise that resolves you have unsubscribed.
46
53
  * @throws {Error} Throws an error if the method is called in a browser other than Firefox.
@@ -50,7 +57,14 @@ export class Bidi {
50
57
  * Sends a command using Bidi.
51
58
  *
52
59
  * @async
53
- * @example await commands.bidi.send({});
60
+ * @example
61
+ * const params = {
62
+ * method: 'script.addPreloadScript',
63
+ * params: {
64
+ * functionDeclaration: "function() {alert('hello')}"
65
+ * }
66
+ * };
67
+ * await commands.bidi.send(params);
54
68
  * @param {Object} parameters - The paramaters for the command.
55
69
  * @throws {Error} Throws an error if the browser is not supported or if the command fails.
56
70
  * @returns {Promise<Object>} A promise that resolves when the command has been sent.
@@ -1 +1 @@
1
- {"version":3,"file":"bidi.d.ts","sourceRoot":"","sources":["../../../../lib/core/engine/command/bidi.js"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH;IACE,mDASC;IARC;;OAEG;IACH,uBAAoC;IACpC;;OAEG;IACH,oBAA8B;IAGhC;;;;;OAKG;IACH,sCAQC;IAED;;;;;;OAMG;IACH,gBAHa,YAAe,CAS3B;IAED;;;;;;OAMG;IACH,uBAJW,MAAM,GACJ,YAAe,CAY3B;IAED;;;;;;OAMG;IACH,yBAJW,MAAM,GACH,YAAe,CAY5B;IAED;;;;;;;;OAQG;IACH,uBAFa,YAAe,CAe3B;CACF"}
1
+ {"version":3,"file":"bidi.d.ts","sourceRoot":"","sources":["../../../../lib/core/engine/command/bidi.js"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH;IACE,mDASC;IARC;;OAEG;IACH,uBAAoC;IACpC;;OAEG;IACH,oBAA8B;IAGhC;;;;;;;;;OASG;IACH,sCAQC;IAED;;;;;OAKG;IACH,gBAHa,YAAe,CAS3B;IAED;;;;;;;;OAQG;IACH,uBAJW,MAAM,GACJ,YAAe,CAY3B;IAED;;;;;;;;OAQG;IACH,yBAJW,MAAM,GACH,YAAe,CAY5B;IAED;;;;;;;;;;;;;;;OAeG;IACH,uBAFa,YAAe,CAmB3B;CACF"}