browser-commander 0.19.0 → 0.21.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 (155) hide show
  1. package/CHANGELOG.md +156 -0
  2. package/README.md +216 -32
  3. package/bin/browser-commander.js +16 -0
  4. package/eslint.config.js +10 -0
  5. package/examples/react-test-app/src/App.jsx +24 -23
  6. package/extension/background.js +14 -0
  7. package/extension/manifest.json +12 -0
  8. package/extension/relay-handler.js +353 -0
  9. package/package.json +25 -6
  10. package/scripts/run-tests.mjs +4 -2
  11. package/src/browser/attach/differences.js +131 -0
  12. package/src/browser/attach/extension-relay.js +402 -0
  13. package/src/browser/attach/index.js +81 -0
  14. package/src/browser/attach/snapshot-launch.js +146 -0
  15. package/src/browser/attach/snapshot.js +374 -0
  16. package/src/browser/attach/websocket.js +615 -0
  17. package/src/browser/browser-cookie-cache.js +12 -17
  18. package/src/browser/browser-cookie-credentials.js +6 -9
  19. package/src/browser/browser-cookies.js +5 -2
  20. package/src/browser/cdp-session.js +94 -0
  21. package/src/browser/connector.js +42 -4
  22. package/src/browser/debugging-port.js +155 -0
  23. package/src/browser/launch-options.js +63 -52
  24. package/src/browser/launch-restrictions.json +147 -0
  25. package/src/browser/launcher.js +329 -133
  26. package/src/browser/media.js +5 -0
  27. package/src/browser/migration/bookmarks.js +73 -0
  28. package/src/browser/migration/chromium-crypto.js +89 -0
  29. package/src/browser/migration/cookies.js +155 -0
  30. package/src/browser/migration/extensions.js +187 -0
  31. package/src/browser/migration/firefox-bookmarks.js +144 -0
  32. package/src/browser/migration/firefox-der.js +84 -0
  33. package/src/browser/migration/firefox-nss.js +281 -0
  34. package/src/browser/migration/firefox.js +334 -0
  35. package/src/browser/migration/fs-utils.js +51 -0
  36. package/src/browser/migration/history.js +103 -0
  37. package/src/browser/migration/index.js +307 -0
  38. package/src/browser/migration/os-crypt-keys.js +106 -0
  39. package/src/browser/migration/passwords.js +171 -0
  40. package/src/browser/migration/preferences.js +132 -0
  41. package/src/browser/migration/sqlite-snapshot.js +138 -0
  42. package/src/browser/open-in-user-browser.js +112 -0
  43. package/src/browser/parity.js +439 -0
  44. package/src/browser/profile-directory.js +102 -0
  45. package/src/browser/real-browser.js +513 -306
  46. package/src/browser/restrictions.js +148 -0
  47. package/src/browser/system-browser.js +232 -0
  48. package/src/browser/webdriver.js +572 -0
  49. package/src/cli/args.js +253 -0
  50. package/src/cli/commands.js +332 -0
  51. package/src/cli/dispatcher.js +99 -0
  52. package/src/cli/handle-methods.js +136 -0
  53. package/src/cli/handles.js +273 -0
  54. package/src/cli/high-level-methods.js +310 -0
  55. package/src/cli/main.js +67 -0
  56. package/src/cli/modules.js +100 -0
  57. package/src/cli/rpc-error.js +77 -0
  58. package/src/cli/script.js +77 -0
  59. package/src/cli/serve.js +144 -0
  60. package/src/cli/sessions.js +195 -0
  61. package/src/core/constants.js +7 -1
  62. package/src/core/engine-adapter.js +107 -1
  63. package/src/core/engine-detection.js +18 -3
  64. package/src/core/navigation-safety.js +4 -0
  65. package/src/core/webdriver-conversions.js +347 -0
  66. package/src/core/webdriver-events.js +229 -0
  67. package/src/core/webdriver-page.js +716 -0
  68. package/src/downloads/attach.js +6 -0
  69. package/src/downloads/manager.js +9 -0
  70. package/src/downloads/sources.js +71 -0
  71. package/src/downloads/staging.js +21 -9
  72. package/src/elements/selectors.js +3 -2
  73. package/src/elements/visibility.js +4 -0
  74. package/src/exports.js +61 -2
  75. package/src/factory.js +19 -4
  76. package/src/fingerprint/apply.js +6 -0
  77. package/src/fingerprint/automation-parity.js +7 -8
  78. package/src/fingerprint/limitations.js +1 -1
  79. package/src/fingerprint/limitations.json +45 -2
  80. package/src/parity/harness.js +303 -0
  81. package/src/parity/probe.js +838 -0
  82. package/src/parity/version-page.js +144 -0
  83. package/src/traces/bundle.js +10 -2
  84. package/src/traces/recorder.js +16 -3
  85. package/src/utilities/subprocess.js +199 -0
  86. package/tests/e2e/api-coverage.e2e.test.js +174 -0
  87. package/tests/e2e/cli.e2e.test.js +160 -0
  88. package/tests/e2e/downloads.e2e.test.js +79 -2
  89. package/tests/e2e/fingerprint-parity.e2e.test.js +104 -46
  90. package/tests/e2e/google-signin-probe.e2e.test.js +112 -0
  91. package/tests/e2e/measure-parity.e2e.test.js +118 -0
  92. package/tests/e2e/playwright.e2e.test.js +25 -17
  93. package/tests/e2e/puppeteer.e2e.test.js +17 -23
  94. package/tests/e2e/webdriver.e2e.test.js +239 -0
  95. package/tests/fixtures/firefox-nss-fixtures.mjs +211 -0
  96. package/tests/helpers/cli-fakes.js +214 -0
  97. package/tests/helpers/declared-api.js +80 -0
  98. package/tests/helpers/e2e-browser.js +40 -14
  99. package/tests/helpers/fake-chrome.js +124 -0
  100. package/tests/helpers/migration-fixtures.js +242 -0
  101. package/tests/helpers/temp-directory.js +24 -0
  102. package/tests/helpers/trace-fixtures.js +18 -0
  103. package/tests/helpers/webdriver-mocks.js +183 -0
  104. package/tests/unit/browser/attach/extension-relay.test.js +360 -0
  105. package/tests/unit/browser/attach/snapshot-launch.test.js +312 -0
  106. package/tests/unit/browser/attach/snapshot.test.js +390 -0
  107. package/tests/unit/browser/attach/websocket.test.js +240 -0
  108. package/tests/unit/browser/browser-cookies.test.js +2 -32
  109. package/tests/unit/browser/cdp-session.test.js +162 -0
  110. package/tests/unit/browser/connector.test.js +23 -0
  111. package/tests/unit/browser/launch-building-blocks.test.js +238 -0
  112. package/tests/unit/browser/launch-options.test.js +41 -22
  113. package/tests/unit/browser/launcher.test.js +281 -102
  114. package/tests/unit/browser/media.test.js +13 -1
  115. package/tests/unit/browser/migration/bookmarks.test.js +69 -0
  116. package/tests/unit/browser/migration/chromium-crypto.test.js +94 -0
  117. package/tests/unit/browser/migration/cookies.test.js +94 -0
  118. package/tests/unit/browser/migration/extensions.test.js +104 -0
  119. package/tests/unit/browser/migration/firefox-nss.test.js +113 -0
  120. package/tests/unit/browser/migration/firefox.test.js +139 -0
  121. package/tests/unit/browser/migration/history.test.js +48 -0
  122. package/tests/unit/browser/migration/index.test.js +117 -0
  123. package/tests/unit/browser/migration/os-crypt-keys.test.js +95 -0
  124. package/tests/unit/browser/migration/passwords.test.js +144 -0
  125. package/tests/unit/browser/migration/preferences.test.js +77 -0
  126. package/tests/unit/browser/migration/sqlite-snapshot.test.js +75 -0
  127. package/tests/unit/browser/open-in-user-browser.test.js +123 -0
  128. package/tests/unit/browser/parity.test.js +281 -0
  129. package/tests/unit/browser/real-browser.test.js +458 -33
  130. package/tests/unit/browser/webdriver.test.js +473 -0
  131. package/tests/unit/cli/bin.test.js +69 -0
  132. package/tests/unit/cli/declared-api.test.js +49 -0
  133. package/tests/unit/cli/dispatcher.test.js +429 -0
  134. package/tests/unit/cli/handles.test.js +170 -0
  135. package/tests/unit/cli/main.test.js +409 -0
  136. package/tests/unit/cli/serve.test.js +167 -0
  137. package/tests/unit/core/webdriver-conversions.test.js +235 -0
  138. package/tests/unit/core/webdriver-page.test.js +534 -0
  139. package/tests/unit/downloads/manager.test.js +82 -9
  140. package/tests/unit/downloads/staging.test.js +24 -2
  141. package/tests/unit/fingerprint/automation-parity.test.js +17 -4
  142. package/tests/unit/fingerprint/limitations.test.js +1 -1
  143. package/tests/unit/parity/harness.test.js +138 -0
  144. package/tests/unit/scripts/ci-timeout-budgets.test.js +4 -0
  145. package/tests/unit/scripts/ci-workflow-policy.test.js +8 -0
  146. package/tests/unit/scripts/feature-parity.test.js +221 -0
  147. package/tests/unit/scripts/npm-release-helpers.test.js +3 -2
  148. package/tests/unit/scripts/pre-commit-config.test.js +2 -1
  149. package/tests/unit/traces/bundle.test.js +24 -3
  150. package/tests/unit/traces/links.test.js +7 -0
  151. package/tests/unit/traces/reader.test.js +11 -4
  152. package/tests/unit/traces/recorder.test.js +4 -0
  153. package/tests/unit/traces/viewer.test.js +4 -0
  154. package/tests/unit/utilities/command-stream-only.test.js +28 -0
  155. package/tests/unit/utilities/subprocess.test.js +80 -0
@@ -0,0 +1,281 @@
1
+ // feature-parity: parity.measure
2
+ import assert from 'node:assert';
3
+ import { describe, it } from 'node:test';
4
+
5
+ import {
6
+ classifyDifferences,
7
+ compareCommandLines,
8
+ measureParity,
9
+ parseSwitches,
10
+ } from '../../../src/browser/parity.js';
11
+
12
+ const CHROME = '/opt/google/chrome/chrome';
13
+
14
+ describe('parsing a chrome://version command line', () => {
15
+ it('splits switches and drops the executable and start URL', () => {
16
+ const switches = parseSwitches(
17
+ `${CHROME} --user-data-dir=/tmp/a --ozone-platform=x11 --flag-switches-begin --flag-switches-end about:blank`
18
+ );
19
+ assert.deepEqual(
20
+ [...switches],
21
+ [
22
+ ['--user-data-dir', '/tmp/a'],
23
+ ['--ozone-platform', 'x11'],
24
+ ['--flag-switches-begin', null],
25
+ ['--flag-switches-end', null],
26
+ ]
27
+ );
28
+ });
29
+
30
+ it('keeps a value that contains spaces and drops only a trailing URL', () => {
31
+ assert.deepEqual(
32
+ [
33
+ ...parseSwitches(
34
+ `${CHROME} --user-data-dir=/tmp/My Profile --flag data:text/html,hi`
35
+ ),
36
+ ],
37
+ [
38
+ ['--user-data-dir', '/tmp/My Profile'],
39
+ ['--flag', null],
40
+ ]
41
+ );
42
+ assert.deepEqual(
43
+ [...parseSwitches(`${CHROME} --enable-features=A,B`)],
44
+ [['--enable-features', 'A,B']]
45
+ );
46
+ });
47
+
48
+ it('stays linear on a long run of whitespace', () => {
49
+ const started = Date.now();
50
+ parseSwitches(`--a${' '.repeat(200000)}x`);
51
+ assert.ok(Date.now() - started < 1000);
52
+ });
53
+
54
+ it('accepts an argument array', () => {
55
+ assert.deepEqual(
56
+ [...parseSwitches(['--headless=new', 'https://example.com'])],
57
+ [['--headless', 'new']]
58
+ );
59
+ });
60
+ });
61
+
62
+ describe('comparing command lines', () => {
63
+ it('reports only what the reference browser did not have', () => {
64
+ const comparison = compareCommandLines(
65
+ `${CHROME} --user-data-dir=/tmp/a --remote-debugging-port=41000 --ozone-platform=x11 about:blank`,
66
+ `${CHROME} --user-data-dir=/tmp/b --remote-debugging-port=42000 --disable-sync --ozone-platform=x11 --flag-switches-begin --flag-switches-end about:blank`
67
+ );
68
+ assert.deepEqual(comparison.extra, ['--disable-sync']);
69
+ assert.deepEqual(comparison.missing, []);
70
+ assert.deepEqual(comparison.changed, []);
71
+ // The port is how the library attaches; it is not a difference.
72
+ assert.deepEqual(comparison.attachment, ['--remote-debugging-port=42000']);
73
+ });
74
+
75
+ it('reports missing and changed switches and feature lists', () => {
76
+ const comparison = compareCommandLines(
77
+ ['--user-data-dir=/tmp/a', '--lang=de', '--mute-audio'],
78
+ ['--user-data-dir=/tmp/b', '--lang=en', '--disable-features=B,A']
79
+ );
80
+ assert.deepEqual(comparison.missing, ['--mute-audio']);
81
+ assert.deepEqual(comparison.changed, [
82
+ { name: '--lang', reference: 'de', candidate: 'en' },
83
+ ]);
84
+ assert.deepEqual(comparison.features, {
85
+ '--disable-features': { reference: [], candidate: ['A', 'B'] },
86
+ });
87
+ });
88
+ });
89
+
90
+ describe('explaining differences', () => {
91
+ const extraSwitch = {
92
+ path: 'commandLine.extra.--disable-sync',
93
+ reference: null,
94
+ candidate: '--disable-sync',
95
+ };
96
+
97
+ it('leaves an unexplained difference unlisted', () => {
98
+ const { unlisted } = classifyDifferences([extraSwitch], {
99
+ launch: 'real',
100
+ requestedArgs: [],
101
+ });
102
+ assert.deepEqual(unlisted, [
103
+ {
104
+ path: 'commandLine.extra.--disable-sync',
105
+ expected: null,
106
+ actual: '--disable-sync',
107
+ limitation: null,
108
+ requested: false,
109
+ },
110
+ ]);
111
+ });
112
+
113
+ it('accepts a switch the caller asked for', () => {
114
+ const { differences, unlisted } = classifyDifferences([extraSwitch], {
115
+ launch: 'real',
116
+ requestedArgs: ['--disable-sync'],
117
+ });
118
+ assert.equal(differences[0].requested, true);
119
+ assert.deepEqual(unlisted, []);
120
+ });
121
+
122
+ it('ties engine switches and known leaks to catalogue entries', () => {
123
+ const { differences, unlisted } = classifyDifferences(
124
+ [
125
+ extraSwitch,
126
+ {
127
+ path: 'navigator.userAgentData.brands.0.brand',
128
+ reference: 'Not)A;Brand',
129
+ candidate: 'Not.A/Brand',
130
+ },
131
+ { path: 'navigator.webdriver', reference: false, candidate: true },
132
+ ],
133
+ { launch: 'engine', attached: true, requestedArgs: [] }
134
+ );
135
+ assert.deepEqual(
136
+ differences.map((entry) => entry.limitation),
137
+ [
138
+ 'engine-launch-switches',
139
+ 'grease-brand-not-reproduced',
140
+ 'automation-controlled-is-launch-only',
141
+ ]
142
+ );
143
+ assert.deepEqual(unlisted, []);
144
+ });
145
+
146
+ it('ties field-trial surfaces to the engine switches that move them', () => {
147
+ const surfaces = [
148
+ {
149
+ path: 'navigator.keys',
150
+ reference: ['clipboard'],
151
+ candidate: ['clipboard', 'runAdAuction'],
152
+ },
153
+ {
154
+ path: 'worker.navigator.languages',
155
+ reference: ['en-US'],
156
+ candidate: ['en-US', 'en'],
157
+ },
158
+ ];
159
+ const engine = classifyDifferences(surfaces, {
160
+ launch: 'engine',
161
+ extraSwitches: ['--disable-field-trial-config'],
162
+ requestedArgs: [],
163
+ });
164
+ assert.deepEqual(engine.unlisted, []);
165
+ assert.deepEqual(
166
+ engine.differences.map((entry) => entry.limitation),
167
+ ['engine-launch-switches', 'engine-launch-switches']
168
+ );
169
+
170
+ // The same surfaces stay unexplained for the real launch, and for an
171
+ // engine launch that did not touch the feature configuration.
172
+ for (const context of [
173
+ { launch: 'real', extraSwitches: ['--disable-field-trial-config'] },
174
+ { launch: 'engine', extraSwitches: ['--disable-sync'] },
175
+ ]) {
176
+ const { unlisted } = classifyDifferences(surfaces, {
177
+ ...context,
178
+ requestedArgs: [],
179
+ });
180
+ assert.equal(unlisted.length, 2);
181
+ }
182
+ });
183
+
184
+ it('does not excuse navigator.webdriver for a launched browser', () => {
185
+ const { unlisted } = classifyDifferences(
186
+ [{ path: 'navigator.webdriver', reference: false, candidate: true }],
187
+ { launch: 'real', attached: false, requestedArgs: [] }
188
+ );
189
+ assert.equal(unlisted.length, 1);
190
+ });
191
+ });
192
+
193
+ function fakes({ candidateCommandLine, candidateReport = { a: 1 } }) {
194
+ const calls = [];
195
+ const session = {
196
+ launch: 'real',
197
+ args: [],
198
+ page: {
199
+ goto: async (url) => calls.push(['goto', url]),
200
+ },
201
+ browser: { close: async () => calls.push(['close']) },
202
+ };
203
+ const reports = [{ a: 1 }, candidateReport];
204
+ const dependencies = {
205
+ resolveLaunchExecutable: async () => CHROME,
206
+ launchBrowser: async (options) => {
207
+ calls.push(['launch', options]);
208
+ return session;
209
+ },
210
+ readProbe: async () => 'async () => ({})',
211
+ startServer: async () => ({
212
+ url: (token) => `http://127.0.0.1:1/probe/${token}`,
213
+ waitForReport: async () => reports.pop(),
214
+ close: async () => calls.push(['server-close']),
215
+ }),
216
+ captureReference: async () => reports.pop(),
217
+ readReferenceVersion: async ({ headless }) => ({
218
+ commandLine: `${CHROME} --user-data-dir=/tmp/r --remote-debugging-port=1${
219
+ headless ? ' --headless=new --ozone-platform=headless' : ''
220
+ } about:blank`,
221
+ }),
222
+ readVersionPage: async () => ({
223
+ commandLine: candidateCommandLine,
224
+ version: '153.0.8010.36\n (Official Build)\n (64-bit)',
225
+ executablePath: CHROME,
226
+ }),
227
+ };
228
+ return { calls, session, dependencies };
229
+ }
230
+
231
+ describe('measureParity', () => {
232
+ it('is ok when the launched browser matches the hand-started one', async () => {
233
+ const { calls, dependencies } = fakes({
234
+ candidateCommandLine: `${CHROME} --user-data-dir=/tmp/c --remote-debugging-port=2 --headless=new --ozone-platform=headless about:blank`,
235
+ });
236
+ const report = await measureParity({ headless: true }, dependencies);
237
+ assert.equal(report.ok, true);
238
+ assert.deepEqual(report.unlisted, []);
239
+ assert.deepEqual(report.commandLine.extra, []);
240
+ assert.deepEqual(report.commandLine.attachment, [
241
+ '--remote-debugging-port=2',
242
+ ]);
243
+ assert.equal(
244
+ report.browser.version,
245
+ '153.0.8010.36 (Official Build) (64-bit)'
246
+ );
247
+ assert.equal(report.browser.launch, 'real');
248
+ assert.deepEqual(
249
+ calls.map(([name]) => name),
250
+ ['launch', 'goto', 'close', 'server-close']
251
+ );
252
+ });
253
+
254
+ it('fails on an unlisted switch or probe difference', async () => {
255
+ const { dependencies } = fakes({
256
+ candidateCommandLine: `${CHROME} --user-data-dir=/tmp/c --remote-debugging-port=2 --disable-sync about:blank`,
257
+ candidateReport: { a: 2 },
258
+ });
259
+ const report = await measureParity({}, dependencies);
260
+ assert.equal(report.ok, false);
261
+ assert.deepEqual(
262
+ report.unlisted.map((entry) => entry.path),
263
+ ['commandLine.extra.--disable-sync', 'a']
264
+ );
265
+ });
266
+
267
+ it('measures a provided session and leaves it open', async () => {
268
+ const { calls, session, dependencies } = fakes({
269
+ candidateCommandLine: `${CHROME} --user-data-dir=/tmp/c --remote-debugging-port=2 about:blank`,
270
+ });
271
+ const report = await measureParity(
272
+ { session: { ...session, executablePath: CHROME } },
273
+ dependencies
274
+ );
275
+ assert.equal(report.ok, true);
276
+ assert.deepEqual(
277
+ calls.map(([name]) => name),
278
+ ['goto', 'server-close']
279
+ );
280
+ });
281
+ });