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.
- package/CHANGELOG.md +156 -0
- package/README.md +216 -32
- package/bin/browser-commander.js +16 -0
- package/eslint.config.js +10 -0
- package/examples/react-test-app/src/App.jsx +24 -23
- package/extension/background.js +14 -0
- package/extension/manifest.json +12 -0
- package/extension/relay-handler.js +353 -0
- package/package.json +25 -6
- package/scripts/run-tests.mjs +4 -2
- package/src/browser/attach/differences.js +131 -0
- package/src/browser/attach/extension-relay.js +402 -0
- package/src/browser/attach/index.js +81 -0
- package/src/browser/attach/snapshot-launch.js +146 -0
- package/src/browser/attach/snapshot.js +374 -0
- package/src/browser/attach/websocket.js +615 -0
- package/src/browser/browser-cookie-cache.js +12 -17
- package/src/browser/browser-cookie-credentials.js +6 -9
- package/src/browser/browser-cookies.js +5 -2
- package/src/browser/cdp-session.js +94 -0
- package/src/browser/connector.js +42 -4
- package/src/browser/debugging-port.js +155 -0
- package/src/browser/launch-options.js +63 -52
- package/src/browser/launch-restrictions.json +147 -0
- package/src/browser/launcher.js +329 -133
- package/src/browser/media.js +5 -0
- package/src/browser/migration/bookmarks.js +73 -0
- package/src/browser/migration/chromium-crypto.js +89 -0
- package/src/browser/migration/cookies.js +155 -0
- package/src/browser/migration/extensions.js +187 -0
- package/src/browser/migration/firefox-bookmarks.js +144 -0
- package/src/browser/migration/firefox-der.js +84 -0
- package/src/browser/migration/firefox-nss.js +281 -0
- package/src/browser/migration/firefox.js +334 -0
- package/src/browser/migration/fs-utils.js +51 -0
- package/src/browser/migration/history.js +103 -0
- package/src/browser/migration/index.js +307 -0
- package/src/browser/migration/os-crypt-keys.js +106 -0
- package/src/browser/migration/passwords.js +171 -0
- package/src/browser/migration/preferences.js +132 -0
- package/src/browser/migration/sqlite-snapshot.js +138 -0
- package/src/browser/open-in-user-browser.js +112 -0
- package/src/browser/parity.js +439 -0
- package/src/browser/profile-directory.js +102 -0
- package/src/browser/real-browser.js +513 -306
- package/src/browser/restrictions.js +148 -0
- package/src/browser/system-browser.js +232 -0
- package/src/browser/webdriver.js +572 -0
- package/src/cli/args.js +253 -0
- package/src/cli/commands.js +332 -0
- package/src/cli/dispatcher.js +99 -0
- package/src/cli/handle-methods.js +136 -0
- package/src/cli/handles.js +273 -0
- package/src/cli/high-level-methods.js +310 -0
- package/src/cli/main.js +67 -0
- package/src/cli/modules.js +100 -0
- package/src/cli/rpc-error.js +77 -0
- package/src/cli/script.js +77 -0
- package/src/cli/serve.js +144 -0
- package/src/cli/sessions.js +195 -0
- package/src/core/constants.js +7 -1
- package/src/core/engine-adapter.js +107 -1
- package/src/core/engine-detection.js +18 -3
- package/src/core/navigation-safety.js +4 -0
- package/src/core/webdriver-conversions.js +347 -0
- package/src/core/webdriver-events.js +229 -0
- package/src/core/webdriver-page.js +716 -0
- package/src/downloads/attach.js +6 -0
- package/src/downloads/manager.js +9 -0
- package/src/downloads/sources.js +71 -0
- package/src/downloads/staging.js +21 -9
- package/src/elements/selectors.js +3 -2
- package/src/elements/visibility.js +4 -0
- package/src/exports.js +61 -2
- package/src/factory.js +19 -4
- package/src/fingerprint/apply.js +6 -0
- package/src/fingerprint/automation-parity.js +7 -8
- package/src/fingerprint/limitations.js +1 -1
- package/src/fingerprint/limitations.json +45 -2
- package/src/parity/harness.js +303 -0
- package/src/parity/probe.js +838 -0
- package/src/parity/version-page.js +144 -0
- package/src/traces/bundle.js +10 -2
- package/src/traces/recorder.js +16 -3
- package/src/utilities/subprocess.js +199 -0
- package/tests/e2e/api-coverage.e2e.test.js +174 -0
- package/tests/e2e/cli.e2e.test.js +160 -0
- package/tests/e2e/downloads.e2e.test.js +79 -2
- package/tests/e2e/fingerprint-parity.e2e.test.js +104 -46
- package/tests/e2e/google-signin-probe.e2e.test.js +112 -0
- package/tests/e2e/measure-parity.e2e.test.js +118 -0
- package/tests/e2e/playwright.e2e.test.js +25 -17
- package/tests/e2e/puppeteer.e2e.test.js +17 -23
- package/tests/e2e/webdriver.e2e.test.js +239 -0
- package/tests/fixtures/firefox-nss-fixtures.mjs +211 -0
- package/tests/helpers/cli-fakes.js +214 -0
- package/tests/helpers/declared-api.js +80 -0
- package/tests/helpers/e2e-browser.js +40 -14
- package/tests/helpers/fake-chrome.js +124 -0
- package/tests/helpers/migration-fixtures.js +242 -0
- package/tests/helpers/temp-directory.js +24 -0
- package/tests/helpers/trace-fixtures.js +18 -0
- package/tests/helpers/webdriver-mocks.js +183 -0
- package/tests/unit/browser/attach/extension-relay.test.js +360 -0
- package/tests/unit/browser/attach/snapshot-launch.test.js +312 -0
- package/tests/unit/browser/attach/snapshot.test.js +390 -0
- package/tests/unit/browser/attach/websocket.test.js +240 -0
- package/tests/unit/browser/browser-cookies.test.js +2 -32
- package/tests/unit/browser/cdp-session.test.js +162 -0
- package/tests/unit/browser/connector.test.js +23 -0
- package/tests/unit/browser/launch-building-blocks.test.js +238 -0
- package/tests/unit/browser/launch-options.test.js +41 -22
- package/tests/unit/browser/launcher.test.js +281 -102
- package/tests/unit/browser/media.test.js +13 -1
- package/tests/unit/browser/migration/bookmarks.test.js +69 -0
- package/tests/unit/browser/migration/chromium-crypto.test.js +94 -0
- package/tests/unit/browser/migration/cookies.test.js +94 -0
- package/tests/unit/browser/migration/extensions.test.js +104 -0
- package/tests/unit/browser/migration/firefox-nss.test.js +113 -0
- package/tests/unit/browser/migration/firefox.test.js +139 -0
- package/tests/unit/browser/migration/history.test.js +48 -0
- package/tests/unit/browser/migration/index.test.js +117 -0
- package/tests/unit/browser/migration/os-crypt-keys.test.js +95 -0
- package/tests/unit/browser/migration/passwords.test.js +144 -0
- package/tests/unit/browser/migration/preferences.test.js +77 -0
- package/tests/unit/browser/migration/sqlite-snapshot.test.js +75 -0
- package/tests/unit/browser/open-in-user-browser.test.js +123 -0
- package/tests/unit/browser/parity.test.js +281 -0
- package/tests/unit/browser/real-browser.test.js +458 -33
- package/tests/unit/browser/webdriver.test.js +473 -0
- package/tests/unit/cli/bin.test.js +69 -0
- package/tests/unit/cli/declared-api.test.js +49 -0
- package/tests/unit/cli/dispatcher.test.js +429 -0
- package/tests/unit/cli/handles.test.js +170 -0
- package/tests/unit/cli/main.test.js +409 -0
- package/tests/unit/cli/serve.test.js +167 -0
- package/tests/unit/core/webdriver-conversions.test.js +235 -0
- package/tests/unit/core/webdriver-page.test.js +534 -0
- package/tests/unit/downloads/manager.test.js +82 -9
- package/tests/unit/downloads/staging.test.js +24 -2
- package/tests/unit/fingerprint/automation-parity.test.js +17 -4
- package/tests/unit/fingerprint/limitations.test.js +1 -1
- package/tests/unit/parity/harness.test.js +138 -0
- package/tests/unit/scripts/ci-timeout-budgets.test.js +4 -0
- package/tests/unit/scripts/ci-workflow-policy.test.js +8 -0
- package/tests/unit/scripts/feature-parity.test.js +221 -0
- package/tests/unit/scripts/npm-release-helpers.test.js +3 -2
- package/tests/unit/scripts/pre-commit-config.test.js +2 -1
- package/tests/unit/traces/bundle.test.js +24 -3
- package/tests/unit/traces/links.test.js +7 -0
- package/tests/unit/traces/reader.test.js +11 -4
- package/tests/unit/traces/recorder.test.js +4 -0
- package/tests/unit/traces/viewer.test.js +4 -0
- package/tests/unit/utilities/command-stream-only.test.js +28 -0
- 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
|
+
});
|