@speedkit/cli 4.31.0 → 4.33.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/.env.sample +5 -0
- package/CHANGELOG.md +14 -0
- package/README.md +2 -1
- package/dist/helpers/chrome-flags.d.ts +65 -0
- package/dist/helpers/chrome-flags.js +191 -0
- package/dist/helpers/chrome-flags.spec.d.ts +1 -0
- package/dist/helpers/chrome-flags.spec.js +234 -0
- package/dist/helpers/cli-config.d.ts +2 -0
- package/dist/helpers/cli-config.js +6 -0
- package/dist/helpers/cli-config.spec.js +34 -0
- package/dist/services/onboarding/empty-service-worker.d.ts +8 -0
- package/dist/services/onboarding/empty-service-worker.js +17 -0
- package/dist/services/onboarding/empty-service-worker.spec.d.ts +1 -0
- package/dist/services/onboarding/empty-service-worker.spec.js +22 -0
- package/dist/services/onboarding/fetch-events/customer-service-worker-js.js +3 -2
- package/dist/services/onboarding/onboarding-model.d.ts +15 -0
- package/dist/services/onboarding/onboarding-model.js +63 -16
- package/dist/services/onboarding/onboarding-model.spec.js +57 -0
- package/dist/services/onboarding/onboarding-service-factory.js +7 -0
- package/dist/services/onboarding/onboarding-service.js +2 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/.env.sample
CHANGED
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
# Chrome Extension Local Paths
|
|
34
34
|
# CHROME_EXTENSION_PATHS='<SPEED_KIT_EXTENSION_DIST_PATH>,<CHROME_EXTENSION_DIST_PATH_1>,<CHROME_EXTENSION_DIST_PATH_2>'
|
|
35
35
|
|
|
36
|
+
# System-specific Chrome flags, appended to the onboarding browser after sk's own and the customer
|
|
37
|
+
# config's chromeFlags. Separate flags by whitespace, or pass a JSON array when a value has a space.
|
|
38
|
+
# A flag that is already set elsewhere is kept, and the CLI warns about it. Replaces "chromeFlags" of config.json.
|
|
39
|
+
# CHROME_FLAGS='--ozone-platform=wayland --enable-features=VaapiVideoDecoder'
|
|
40
|
+
|
|
36
41
|
# Default SK Test App Name
|
|
37
42
|
# TEST_APP='<APP_NAME>'
|
|
38
43
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [4.33.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.32.0...v4.33.0) (2026-09-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **onboarding:** add settings for chromeFlags ([955109d](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/955109d1c05caab7e6852569b88a52fcdda3861c))
|
|
7
|
+
|
|
8
|
+
# [4.32.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.31.0...v4.32.0) (2026-09-22)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **onboarding:** recognize r=empty as the empty service worker ([d37d0c7](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/d37d0c74ae536aa8697101ddc053073164d40547))
|
|
14
|
+
|
|
1
15
|
# [4.31.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.30.0...v4.31.0) (2026-09-22)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ $ npm install -g @speedkit/cli
|
|
|
21
21
|
$ sk COMMAND
|
|
22
22
|
running command...
|
|
23
23
|
$ sk (--version)
|
|
24
|
-
@speedkit/cli/4.
|
|
24
|
+
@speedkit/cli/4.33.0 linux-x64 node-v22.23.2
|
|
25
25
|
$ sk --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ sk COMMAND
|
|
@@ -49,6 +49,7 @@ On the first execution of any `sk` command a `config.json` will be created and s
|
|
|
49
49
|
"chromePath": "", // local path to the Chrome binary
|
|
50
50
|
"chromeUserProfilePath": "", // local path to the Custom Chrome User Profile (use if you want to have Chrome's state saved)
|
|
51
51
|
"chromeExtensionPaths": "", // comma separated list of local paths to unpacked extensions for Chrome to load
|
|
52
|
+
"chromeFlags": [], // system-specific flags appended to the onboarding browser, e.g. ["--ozone-platform=wayland"]; a duplicate is kept and warned about
|
|
52
53
|
"slackToken": "", // Slack token that will be injected to the deploymentDetection
|
|
53
54
|
"testApp": "", // name of your Test Speed Kit App
|
|
54
55
|
"ideaDirectory": "", // local directory path to the IntelliJ's shell binary
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Chrome flags of one origin, labelled so a duplicate can name where each occurrence came from. */
|
|
2
|
+
export interface ChromeFlagSource {
|
|
3
|
+
source: string;
|
|
4
|
+
flags: string[];
|
|
5
|
+
}
|
|
6
|
+
/** One switch passed more than once, in launch order. Chrome takes the last occurrence. */
|
|
7
|
+
export interface ChromeFlagDuplicate {
|
|
8
|
+
name: string;
|
|
9
|
+
occurrences: {
|
|
10
|
+
source: string;
|
|
11
|
+
flag: string;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reads the system-specific `chromeFlags` setting.
|
|
16
|
+
*
|
|
17
|
+
* config.json holds an array. An environment variable holds a string: a JSON array, or flags
|
|
18
|
+
* separated by whitespace. Commas can't separate flags, because values like
|
|
19
|
+
* `--enable-features=A,B` contain them. A value with a space in it needs the JSON form.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseChromeFlags(value: unknown): string[];
|
|
22
|
+
/** A feature named by one source, as written there: `Foo:param/1` for feature `Foo`. */
|
|
23
|
+
export interface ChromeFeatureOccurrence {
|
|
24
|
+
source: string;
|
|
25
|
+
entry: string;
|
|
26
|
+
}
|
|
27
|
+
/** A feature listed more than once in the same flag, in launch order. */
|
|
28
|
+
export interface ChromeFeatureDuplicate {
|
|
29
|
+
kind: "duplicate";
|
|
30
|
+
flag: string;
|
|
31
|
+
feature: string;
|
|
32
|
+
occurrences: ChromeFeatureOccurrence[];
|
|
33
|
+
}
|
|
34
|
+
/** A feature that is both enabled and disabled. Chrome disables it. */
|
|
35
|
+
export interface ChromeFeatureConflict {
|
|
36
|
+
kind: "conflict";
|
|
37
|
+
feature: string;
|
|
38
|
+
enabled: ChromeFeatureOccurrence[];
|
|
39
|
+
disabled: ChromeFeatureOccurrence[];
|
|
40
|
+
}
|
|
41
|
+
export type ChromeFeatureFinding = ChromeFeatureDuplicate | ChromeFeatureConflict;
|
|
42
|
+
export declare function isFeatureListFlag(flag: string): boolean;
|
|
43
|
+
/** The feature of a list entry, without its override, trial or params: `*Foo<Trial:p/1` → `Foo`. */
|
|
44
|
+
export declare function chromeFeatureName(entry: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Finds every feature that is listed twice in one flag, or both enabled and disabled,
|
|
47
|
+
* across all sources.
|
|
48
|
+
*/
|
|
49
|
+
export declare function findChromeFeatureFindings(sources: ChromeFlagSource[]): ChromeFeatureFinding[];
|
|
50
|
+
/**
|
|
51
|
+
* Folds every occurrence of a feature list flag into one, at the place of the first occurrence.
|
|
52
|
+
* A feature listed twice in one flag keeps its first entry, the one Chrome would use.
|
|
53
|
+
* A feature that is both enabled and disabled stays in both lists.
|
|
54
|
+
*/
|
|
55
|
+
export declare function mergeChromeFeatureFlags(flags: string[]): string[];
|
|
56
|
+
export declare function formatChromeFeatureFinding(finding: ChromeFeatureFinding): string;
|
|
57
|
+
/** The switch of a flag, without its value: `--foo=bar` → `--foo`. */
|
|
58
|
+
export declare function chromeFlagName(flag: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Finds every switch passed more than once across all sources, in launch order.
|
|
61
|
+
* Flags are matched on their name, so `--foo=a` and `--foo=b` are a duplicate too.
|
|
62
|
+
* Feature list flags are left to findChromeFeatureFindings.
|
|
63
|
+
*/
|
|
64
|
+
export declare function findDuplicateChromeFlags(sources: ChromeFlagSource[]): ChromeFlagDuplicate[];
|
|
65
|
+
export declare function formatChromeFlagDuplicate({ name, occurrences, }: ChromeFlagDuplicate): string;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the system-specific `chromeFlags` setting.
|
|
3
|
+
*
|
|
4
|
+
* config.json holds an array. An environment variable holds a string: a JSON array, or flags
|
|
5
|
+
* separated by whitespace. Commas can't separate flags, because values like
|
|
6
|
+
* `--enable-features=A,B` contain them. A value with a space in it needs the JSON form.
|
|
7
|
+
*/
|
|
8
|
+
export function parseChromeFlags(value) {
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
return value
|
|
11
|
+
.filter((flag) => typeof flag === "string")
|
|
12
|
+
.map((flag) => flag.trim())
|
|
13
|
+
.filter(Boolean);
|
|
14
|
+
}
|
|
15
|
+
if (typeof value !== "string") {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const trimmed = value.trim();
|
|
19
|
+
if (trimmed.startsWith("[")) {
|
|
20
|
+
try {
|
|
21
|
+
return parseChromeFlags(JSON.parse(trimmed));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new Error(`chromeFlags is not a valid JSON array: ${trimmed}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return trimmed.split(/\s+/).filter(Boolean);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Chrome flags that each hold a list of features. Puppeteer merges every occurrence of the
|
|
31
|
+
* `*-features` pair into one flag, Chrome itself the `*-blink-features` pair. In both, a disabled
|
|
32
|
+
* feature beats an enabled one, so they are merged here and checked feature by feature instead.
|
|
33
|
+
*/
|
|
34
|
+
const FEATURE_LISTS = [
|
|
35
|
+
{ enable: "--enable-features", disable: "--disable-features" },
|
|
36
|
+
{ enable: "--enable-blink-features", disable: "--disable-blink-features" },
|
|
37
|
+
];
|
|
38
|
+
const FEATURE_LIST_FLAGS = FEATURE_LISTS.flatMap(({ enable, disable }) => [
|
|
39
|
+
enable,
|
|
40
|
+
disable,
|
|
41
|
+
]);
|
|
42
|
+
export function isFeatureListFlag(flag) {
|
|
43
|
+
return FEATURE_LIST_FLAGS.includes(chromeFlagName(flag));
|
|
44
|
+
}
|
|
45
|
+
/** The feature of a list entry, without its override, trial or params: `*Foo<Trial:p/1` → `Foo`. */
|
|
46
|
+
export function chromeFeatureName(entry) {
|
|
47
|
+
return entry.replace(/^\*/, "").split(/[<:]/)[0].trim();
|
|
48
|
+
}
|
|
49
|
+
function featureEntries(flag) {
|
|
50
|
+
const separator = flag.indexOf("=");
|
|
51
|
+
if (separator === -1) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
return flag
|
|
55
|
+
.slice(separator + 1)
|
|
56
|
+
.split(",")
|
|
57
|
+
.map((entry) => entry.trim())
|
|
58
|
+
.filter(Boolean);
|
|
59
|
+
}
|
|
60
|
+
function collectFeatures(sources, listFlag) {
|
|
61
|
+
const byFeature = new Map();
|
|
62
|
+
for (const { source, flags } of sources) {
|
|
63
|
+
for (const flag of flags) {
|
|
64
|
+
if (chromeFlagName(flag) !== listFlag) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const entry of featureEntries(flag)) {
|
|
68
|
+
const feature = chromeFeatureName(entry);
|
|
69
|
+
byFeature.set(feature, [
|
|
70
|
+
...(byFeature.get(feature) ?? []),
|
|
71
|
+
{ source, entry },
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return byFeature;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Finds every feature that is listed twice in one flag, or both enabled and disabled,
|
|
80
|
+
* across all sources.
|
|
81
|
+
*/
|
|
82
|
+
export function findChromeFeatureFindings(sources) {
|
|
83
|
+
const findings = [];
|
|
84
|
+
for (const { enable, disable } of FEATURE_LISTS) {
|
|
85
|
+
const enabled = collectFeatures(sources, enable);
|
|
86
|
+
const disabled = collectFeatures(sources, disable);
|
|
87
|
+
for (const [flag, features] of [
|
|
88
|
+
[enable, enabled],
|
|
89
|
+
[disable, disabled],
|
|
90
|
+
]) {
|
|
91
|
+
for (const [feature, occurrences] of features) {
|
|
92
|
+
if (occurrences.length > 1) {
|
|
93
|
+
findings.push({ kind: "duplicate", flag, feature, occurrences });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const [feature, occurrences] of enabled) {
|
|
98
|
+
if (disabled.has(feature)) {
|
|
99
|
+
findings.push({
|
|
100
|
+
kind: "conflict",
|
|
101
|
+
feature,
|
|
102
|
+
enabled: occurrences,
|
|
103
|
+
disabled: disabled.get(feature),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return findings;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Folds every occurrence of a feature list flag into one, at the place of the first occurrence.
|
|
112
|
+
* A feature listed twice in one flag keeps its first entry, the one Chrome would use.
|
|
113
|
+
* A feature that is both enabled and disabled stays in both lists.
|
|
114
|
+
*/
|
|
115
|
+
export function mergeChromeFeatureFlags(flags) {
|
|
116
|
+
const merged = [];
|
|
117
|
+
const placed = new Set();
|
|
118
|
+
for (const flag of flags) {
|
|
119
|
+
const name = chromeFlagName(flag);
|
|
120
|
+
if (!FEATURE_LIST_FLAGS.includes(name)) {
|
|
121
|
+
merged.push(flag);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (placed.has(name)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
placed.add(name);
|
|
128
|
+
const entries = new Map();
|
|
129
|
+
for (const entry of flags
|
|
130
|
+
.filter((other) => chromeFlagName(other) === name)
|
|
131
|
+
.flatMap((other) => featureEntries(other))) {
|
|
132
|
+
const feature = chromeFeatureName(entry);
|
|
133
|
+
if (!entries.has(feature)) {
|
|
134
|
+
entries.set(feature, entry);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (entries.size > 0) {
|
|
138
|
+
merged.push(`${name}=${[...entries.values()].join(",")}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return merged;
|
|
142
|
+
}
|
|
143
|
+
export function formatChromeFeatureFinding(finding) {
|
|
144
|
+
const listed = (occurrences) => occurrences.map(({ source, entry }) => `${entry} (${source})`).join(", ");
|
|
145
|
+
if (finding.kind === "conflict") {
|
|
146
|
+
return `Chrome feature ${finding.feature} is both enabled, ${listed(finding.enabled)}, and disabled, ${listed(finding.disabled)}. Chrome disables it.`;
|
|
147
|
+
}
|
|
148
|
+
const { flag, feature, occurrences } = finding;
|
|
149
|
+
const message = `Chrome feature ${feature} is listed ${occurrences.length} times in ${flag}: ${listed(occurrences)}.`;
|
|
150
|
+
const sameEntry = new Set(occurrences.map(({ entry }) => entry)).size === 1;
|
|
151
|
+
return sameEntry
|
|
152
|
+
? message
|
|
153
|
+
: `${message} Chrome uses the first one, ${occurrences[0].entry}.`;
|
|
154
|
+
}
|
|
155
|
+
/** The switch of a flag, without its value: `--foo=bar` → `--foo`. */
|
|
156
|
+
export function chromeFlagName(flag) {
|
|
157
|
+
const separator = flag.indexOf("=");
|
|
158
|
+
return separator === -1 ? flag : flag.slice(0, separator);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Finds every switch passed more than once across all sources, in launch order.
|
|
162
|
+
* Flags are matched on their name, so `--foo=a` and `--foo=b` are a duplicate too.
|
|
163
|
+
* Feature list flags are left to findChromeFeatureFindings.
|
|
164
|
+
*/
|
|
165
|
+
export function findDuplicateChromeFlags(sources) {
|
|
166
|
+
const byName = new Map();
|
|
167
|
+
for (const { source, flags } of sources) {
|
|
168
|
+
for (const flag of flags) {
|
|
169
|
+
const name = chromeFlagName(flag);
|
|
170
|
+
// Merged instead, and checked by findChromeFeatureFindings.
|
|
171
|
+
if (FEATURE_LIST_FLAGS.includes(name)) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
byName.set(name, [...(byName.get(name) ?? []), { source, flag }]);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return [...byName]
|
|
178
|
+
.filter(([, occurrences]) => occurrences.length > 1)
|
|
179
|
+
.map(([name, occurrences]) => ({ name, occurrences }));
|
|
180
|
+
}
|
|
181
|
+
export function formatChromeFlagDuplicate({ name, occurrences, }) {
|
|
182
|
+
const listed = occurrences
|
|
183
|
+
.map(({ source, flag }) => `${flag} (${source})`)
|
|
184
|
+
.join(", ");
|
|
185
|
+
const sameValue = new Set(occurrences.map(({ flag }) => flag)).size === 1;
|
|
186
|
+
if (sameValue) {
|
|
187
|
+
return `Chrome flag ${name} is passed ${occurrences.length} times: ${listed}.`;
|
|
188
|
+
}
|
|
189
|
+
const last = occurrences.at(-1);
|
|
190
|
+
return `Chrome flag ${name} is passed ${occurrences.length} times: ${listed}. Chrome uses the last one, ${last.flag}.`;
|
|
191
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { chromeFeatureName, findChromeFeatureFindings, findDuplicateChromeFlags, formatChromeFeatureFinding, formatChromeFlagDuplicate, mergeChromeFeatureFlags, parseChromeFlags, } from "./chrome-flags.js";
|
|
4
|
+
describe("parseChromeFlags", () => {
|
|
5
|
+
it("keeps an array from config.json, trimmed and without empty entries", () => {
|
|
6
|
+
expect(parseChromeFlags([" --foo ", "", "--bar=1", 3])).to.deep.equal([
|
|
7
|
+
"--foo",
|
|
8
|
+
"--bar=1",
|
|
9
|
+
]);
|
|
10
|
+
});
|
|
11
|
+
it("splits an environment string on whitespace, not on commas", () => {
|
|
12
|
+
expect(parseChromeFlags(" --enable-features=A,B --ozone-platform=wayland ")).to.deep.equal(["--enable-features=A,B", "--ozone-platform=wayland"]);
|
|
13
|
+
});
|
|
14
|
+
it("reads a JSON array from the environment, so a value may contain spaces", () => {
|
|
15
|
+
expect(parseChromeFlags('["--user-agent=Mozilla/5.0 (X11)", "--foo"]')).to.deep.equal(["--user-agent=Mozilla/5.0 (X11)", "--foo"]);
|
|
16
|
+
});
|
|
17
|
+
it("names the value of a broken JSON array", () => {
|
|
18
|
+
expect(() => parseChromeFlags('["--foo"')).to.throw(/\["--foo"/);
|
|
19
|
+
});
|
|
20
|
+
it("returns no flags for an unset value", () => {
|
|
21
|
+
expect(parseChromeFlags(undefined)).to.deep.equal([]);
|
|
22
|
+
expect(parseChromeFlags("")).to.deep.equal([]);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe("findDuplicateChromeFlags", () => {
|
|
26
|
+
it("matches flags on their name across sources, in launch order", () => {
|
|
27
|
+
const duplicates = findDuplicateChromeFlags([
|
|
28
|
+
{
|
|
29
|
+
source: "sk",
|
|
30
|
+
flags: ["--window-size=1,1", "--no-first-run"],
|
|
31
|
+
},
|
|
32
|
+
{ source: "customer config", flags: ["--proxy-server=socks5://a"] },
|
|
33
|
+
{
|
|
34
|
+
source: "system",
|
|
35
|
+
flags: ["--window-size=2,2", "--proxy-server=socks5://a"],
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
expect(duplicates).to.deep.equal([
|
|
39
|
+
{
|
|
40
|
+
name: "--window-size",
|
|
41
|
+
occurrences: [
|
|
42
|
+
{ source: "sk", flag: "--window-size=1,1" },
|
|
43
|
+
{ source: "system", flag: "--window-size=2,2" },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "--proxy-server",
|
|
48
|
+
occurrences: [
|
|
49
|
+
{ source: "customer config", flag: "--proxy-server=socks5://a" },
|
|
50
|
+
{ source: "system", flag: "--proxy-server=socks5://a" },
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
it("finds a duplicate within one source", () => {
|
|
56
|
+
const duplicates = findDuplicateChromeFlags([
|
|
57
|
+
{ source: "system", flags: ["--mute-audio", "--mute-audio"] },
|
|
58
|
+
]);
|
|
59
|
+
expect(duplicates.map(({ name }) => name)).to.deep.equal(["--mute-audio"]);
|
|
60
|
+
});
|
|
61
|
+
it("leaves the feature list flags to the feature check", () => {
|
|
62
|
+
expect(findDuplicateChromeFlags([
|
|
63
|
+
{
|
|
64
|
+
source: "sk",
|
|
65
|
+
flags: ["--enable-features=A", "--disable-blink-features=B"],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
source: "system",
|
|
69
|
+
flags: ["--enable-features=C", "--disable-blink-features=D"],
|
|
70
|
+
},
|
|
71
|
+
])).to.deep.equal([]);
|
|
72
|
+
});
|
|
73
|
+
it("reports nothing for distinct flags", () => {
|
|
74
|
+
expect(findDuplicateChromeFlags([
|
|
75
|
+
{ source: "sk", flags: ["--foo"] },
|
|
76
|
+
{ source: "system", flags: ["--foobar"] },
|
|
77
|
+
])).to.deep.equal([]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe("formatChromeFlagDuplicate", () => {
|
|
81
|
+
it("names the flag Chrome uses when the values differ", () => {
|
|
82
|
+
expect(formatChromeFlagDuplicate({
|
|
83
|
+
name: "--enable-features",
|
|
84
|
+
occurrences: [
|
|
85
|
+
{ source: "sk", flag: "--enable-features=Translate" },
|
|
86
|
+
{ source: "system", flag: "--enable-features=Foo" },
|
|
87
|
+
],
|
|
88
|
+
})).to.equal("Chrome flag --enable-features is passed 2 times: --enable-features=Translate (sk), --enable-features=Foo (system). Chrome uses the last one, --enable-features=Foo.");
|
|
89
|
+
});
|
|
90
|
+
it("only lists the occurrences when the values match", () => {
|
|
91
|
+
expect(formatChromeFlagDuplicate({
|
|
92
|
+
name: "--mute-audio",
|
|
93
|
+
occurrences: [
|
|
94
|
+
{ source: "customer config", flag: "--mute-audio" },
|
|
95
|
+
{ source: "system", flag: "--mute-audio" },
|
|
96
|
+
],
|
|
97
|
+
})).to.equal("Chrome flag --mute-audio is passed 2 times: --mute-audio (customer config), --mute-audio (system).");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe("chromeFeatureName", () => {
|
|
101
|
+
it("drops the override, trial and params of an entry", () => {
|
|
102
|
+
expect(chromeFeatureName("Foo")).to.equal("Foo");
|
|
103
|
+
expect(chromeFeatureName("Foo:param/1")).to.equal("Foo");
|
|
104
|
+
expect(chromeFeatureName("*Foo<Trial.Group:param/1")).to.equal("Foo");
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe("findChromeFeatureFindings", () => {
|
|
108
|
+
it("finds a feature listed twice in one flag, across sources", () => {
|
|
109
|
+
expect(findChromeFeatureFindings([
|
|
110
|
+
{ source: "customer config", flags: ["--enable-features=Foo,Bar"] },
|
|
111
|
+
{ source: "system", flags: ["--enable-features=Foo:p/1"] },
|
|
112
|
+
])).to.deep.equal([
|
|
113
|
+
{
|
|
114
|
+
kind: "duplicate",
|
|
115
|
+
flag: "--enable-features",
|
|
116
|
+
feature: "Foo",
|
|
117
|
+
occurrences: [
|
|
118
|
+
{ source: "customer config", entry: "Foo" },
|
|
119
|
+
{ source: "system", entry: "Foo:p/1" },
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
]);
|
|
123
|
+
});
|
|
124
|
+
it("finds a feature that is both enabled and disabled", () => {
|
|
125
|
+
expect(findChromeFeatureFindings([
|
|
126
|
+
{
|
|
127
|
+
source: "puppeteer",
|
|
128
|
+
flags: ["--disable-features=Translate,MediaRouter"],
|
|
129
|
+
},
|
|
130
|
+
{ source: "system", flags: ["--enable-features=Translate"] },
|
|
131
|
+
])).to.deep.equal([
|
|
132
|
+
{
|
|
133
|
+
kind: "conflict",
|
|
134
|
+
feature: "Translate",
|
|
135
|
+
enabled: [{ source: "system", entry: "Translate" }],
|
|
136
|
+
disabled: [{ source: "puppeteer", entry: "Translate" }],
|
|
137
|
+
},
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
140
|
+
it("checks the blink lists apart from the base features", () => {
|
|
141
|
+
const findings = findChromeFeatureFindings([
|
|
142
|
+
{
|
|
143
|
+
source: "sk",
|
|
144
|
+
flags: ["--disable-blink-features=AutomationControlled"],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
source: "system",
|
|
148
|
+
flags: [
|
|
149
|
+
"--enable-features=AutomationControlled",
|
|
150
|
+
"--disable-blink-features=AutomationControlled",
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
]);
|
|
154
|
+
expect(findings).to.deep.equal([
|
|
155
|
+
{
|
|
156
|
+
kind: "duplicate",
|
|
157
|
+
flag: "--disable-blink-features",
|
|
158
|
+
feature: "AutomationControlled",
|
|
159
|
+
occurrences: [
|
|
160
|
+
{ source: "sk", entry: "AutomationControlled" },
|
|
161
|
+
{ source: "system", entry: "AutomationControlled" },
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
]);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
describe("mergeChromeFeatureFlags", () => {
|
|
168
|
+
it("folds each feature list into one flag at its first place", () => {
|
|
169
|
+
expect(mergeChromeFeatureFlags([
|
|
170
|
+
"--no-first-run",
|
|
171
|
+
"--enable-features=A,B",
|
|
172
|
+
"--disable-blink-features=X",
|
|
173
|
+
"--mute-audio",
|
|
174
|
+
"--enable-features=C",
|
|
175
|
+
"--disable-blink-features=Y",
|
|
176
|
+
])).to.deep.equal([
|
|
177
|
+
"--no-first-run",
|
|
178
|
+
"--enable-features=A,B,C",
|
|
179
|
+
"--disable-blink-features=X,Y",
|
|
180
|
+
"--mute-audio",
|
|
181
|
+
]);
|
|
182
|
+
});
|
|
183
|
+
it("keeps the first entry of a feature listed twice", () => {
|
|
184
|
+
expect(mergeChromeFeatureFlags([
|
|
185
|
+
"--enable-features=Foo:p/1,Bar",
|
|
186
|
+
"--enable-features=Foo:p/2",
|
|
187
|
+
])).to.deep.equal(["--enable-features=Foo:p/1,Bar"]);
|
|
188
|
+
});
|
|
189
|
+
it("keeps a feature that is both enabled and disabled in both lists", () => {
|
|
190
|
+
expect(mergeChromeFeatureFlags([
|
|
191
|
+
"--enable-features=Foo",
|
|
192
|
+
"--disable-features=Foo",
|
|
193
|
+
])).to.deep.equal(["--enable-features=Foo", "--disable-features=Foo"]);
|
|
194
|
+
});
|
|
195
|
+
it("drops a feature list flag without features", () => {
|
|
196
|
+
expect(mergeChromeFeatureFlags(["--enable-features=", "--foo"])).to.deep.equal(["--foo"]);
|
|
197
|
+
});
|
|
198
|
+
it("leaves every other flag as it is, duplicates included", () => {
|
|
199
|
+
const flags = ["--mute-audio", "--window-size=1,1", "--mute-audio"];
|
|
200
|
+
expect(mergeChromeFeatureFlags(flags)).to.deep.equal(flags);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
describe("formatChromeFeatureFinding", () => {
|
|
204
|
+
it("names both sides of a conflict and that the disable wins", () => {
|
|
205
|
+
expect(formatChromeFeatureFinding({
|
|
206
|
+
kind: "conflict",
|
|
207
|
+
feature: "Translate",
|
|
208
|
+
enabled: [{ source: "system", entry: "Translate" }],
|
|
209
|
+
disabled: [{ source: "puppeteer", entry: "Translate" }],
|
|
210
|
+
})).to.equal("Chrome feature Translate is both enabled, Translate (system), and disabled, Translate (puppeteer). Chrome disables it.");
|
|
211
|
+
});
|
|
212
|
+
it("names the entry Chrome uses when a duplicate differs", () => {
|
|
213
|
+
expect(formatChromeFeatureFinding({
|
|
214
|
+
kind: "duplicate",
|
|
215
|
+
flag: "--enable-features",
|
|
216
|
+
feature: "Foo",
|
|
217
|
+
occurrences: [
|
|
218
|
+
{ source: "customer config", entry: "Foo" },
|
|
219
|
+
{ source: "system", entry: "Foo:p/1" },
|
|
220
|
+
],
|
|
221
|
+
})).to.equal("Chrome feature Foo is listed 2 times in --enable-features: Foo (customer config), Foo:p/1 (system). Chrome uses the first one, Foo.");
|
|
222
|
+
});
|
|
223
|
+
it("only lists a duplicate with identical entries", () => {
|
|
224
|
+
expect(formatChromeFeatureFinding({
|
|
225
|
+
kind: "duplicate",
|
|
226
|
+
flag: "--disable-blink-features",
|
|
227
|
+
feature: "AutomationControlled",
|
|
228
|
+
occurrences: [
|
|
229
|
+
{ source: "sk", entry: "AutomationControlled" },
|
|
230
|
+
{ source: "system", entry: "AutomationControlled" },
|
|
231
|
+
],
|
|
232
|
+
})).to.equal("Chrome feature AutomationControlled is listed 2 times in --disable-blink-features: AutomationControlled (sk), AutomationControlled (system).");
|
|
233
|
+
});
|
|
234
|
+
});
|
|
@@ -10,6 +10,8 @@ export interface ManagedExtension {
|
|
|
10
10
|
}
|
|
11
11
|
export interface UserCliConfig {
|
|
12
12
|
chromeExtensionPaths: string;
|
|
13
|
+
/** system-specific flags, appended to the onboarding browser's launch args */
|
|
14
|
+
chromeFlags: string[];
|
|
13
15
|
chromePath: string;
|
|
14
16
|
chromeUserProfilePath: string;
|
|
15
17
|
diffExec: string;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as dotenv from "dotenv";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path, { resolve } from "node:path";
|
|
4
|
+
import { parseChromeFlags } from "./chrome-flags.js";
|
|
4
5
|
dotenv.config({ quiet: true });
|
|
5
6
|
const environmentMapping = {
|
|
6
7
|
chromeExtensionPaths: "CHROME_EXTENSION_PATHS",
|
|
8
|
+
chromeFlags: "CHROME_FLAGS",
|
|
7
9
|
chromePath: "CHROME_PATH",
|
|
8
10
|
chromeUserProfilePath: "CHROME_USER_PROFILE_PATH",
|
|
9
11
|
diffExec: "DIFF_EXEC",
|
|
@@ -23,6 +25,7 @@ export class CliConfig {
|
|
|
23
25
|
config;
|
|
24
26
|
userCliConfig = {
|
|
25
27
|
chromeExtensionPaths: "",
|
|
28
|
+
chromeFlags: [],
|
|
26
29
|
chromePath: "",
|
|
27
30
|
chromeUserProfilePath: "",
|
|
28
31
|
diffExec: "",
|
|
@@ -50,6 +53,8 @@ export class CliConfig {
|
|
|
50
53
|
this.loadConfigFromConfigFile();
|
|
51
54
|
// override config from environment
|
|
52
55
|
this.loadConfigFromEnvironment();
|
|
56
|
+
// The environment holds a string, config.json an array.
|
|
57
|
+
this.userCliConfig.chromeFlags = parseChromeFlags(this.userCliConfig.chromeFlags);
|
|
53
58
|
this.resolveExtensionConfigPaths();
|
|
54
59
|
this.userCliConfig.tempFolder = this.config.cacheDir;
|
|
55
60
|
this.userCliConfig.runtimeConfig = this.config;
|
|
@@ -63,6 +68,7 @@ export class CliConfig {
|
|
|
63
68
|
createEmptyUserConfig() {
|
|
64
69
|
return {
|
|
65
70
|
chromeExtensionPaths: "",
|
|
71
|
+
chromeFlags: [],
|
|
66
72
|
chromePath: "",
|
|
67
73
|
chromeUserProfilePath: "",
|
|
68
74
|
diffExec: "",
|
|
@@ -80,4 +80,38 @@ describe("CliConfig save/load", () => {
|
|
|
80
80
|
expect(reloaded.managedChromeExtensions[0].id).to.equal("abc");
|
|
81
81
|
expect(reloaded.managedChromeExtensions[0].version).to.equal("1.0.0");
|
|
82
82
|
});
|
|
83
|
+
describe("chromeFlags", () => {
|
|
84
|
+
const previous = process.env.CHROME_FLAGS;
|
|
85
|
+
afterEach(() => {
|
|
86
|
+
if (previous === undefined) {
|
|
87
|
+
delete process.env.CHROME_FLAGS;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
process.env.CHROME_FLAGS = previous;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
it("reads the array from config.json", () => {
|
|
94
|
+
delete process.env.CHROME_FLAGS;
|
|
95
|
+
new CliConfig(fakeOclifConfig(dir)).save({
|
|
96
|
+
chromeFlags: ["--ozone-platform=wayland"],
|
|
97
|
+
});
|
|
98
|
+
const loaded = new CliConfig(fakeOclifConfig(dir)).load();
|
|
99
|
+
expect(loaded.chromeFlags).to.deep.equal(["--ozone-platform=wayland"]);
|
|
100
|
+
});
|
|
101
|
+
it("lets CHROME_FLAGS replace config.json, parsed into an array", () => {
|
|
102
|
+
new CliConfig(fakeOclifConfig(dir)).save({
|
|
103
|
+
chromeFlags: ["--ozone-platform=wayland"],
|
|
104
|
+
});
|
|
105
|
+
process.env.CHROME_FLAGS = "--enable-features=A,B --mute-audio";
|
|
106
|
+
const loaded = new CliConfig(fakeOclifConfig(dir)).load();
|
|
107
|
+
expect(loaded.chromeFlags).to.deep.equal([
|
|
108
|
+
"--enable-features=A,B",
|
|
109
|
+
"--mute-audio",
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
it("defaults to no flags", () => {
|
|
113
|
+
delete process.env.CHROME_FLAGS;
|
|
114
|
+
expect(new CliConfig(fakeOclifConfig(dir)).load().chromeFlags).to.deep.equal([]);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
83
117
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns whether a service worker script URL asks for the empty worker that the snippet installs on
|
|
3
|
+
* each disabled scope.
|
|
4
|
+
*
|
|
5
|
+
* `r=empty` carries the marker in the reference parameter, so it survives an edge that forwards only
|
|
6
|
+
* the query parameters it expects. `empty=1` is the marker older snippets register, and stays valid.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isEmptyServiceWorkerUrl(url: string): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns whether a service worker script URL asks for the empty worker that the snippet installs on
|
|
3
|
+
* each disabled scope.
|
|
4
|
+
*
|
|
5
|
+
* `r=empty` carries the marker in the reference parameter, so it survives an edge that forwards only
|
|
6
|
+
* the query parameters it expects. `empty=1` is the marker older snippets register, and stays valid.
|
|
7
|
+
*/
|
|
8
|
+
export function isEmptyServiceWorkerUrl(url) {
|
|
9
|
+
let params;
|
|
10
|
+
try {
|
|
11
|
+
params = new URL(url).searchParams;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return params.get("r") === "empty" || params.get("empty") === "1";
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { isEmptyServiceWorkerUrl } from "./empty-service-worker.js";
|
|
4
|
+
describe("isEmptyServiceWorkerUrl", () => {
|
|
5
|
+
it("recognizes the r=empty marker", () => {
|
|
6
|
+
expect(isEmptyServiceWorkerUrl("https://www.example.com/wrapper-sw.js?r=empty")).to.equal(true);
|
|
7
|
+
});
|
|
8
|
+
it("still recognizes the empty=1 marker older snippets register", () => {
|
|
9
|
+
expect(isEmptyServiceWorkerUrl("https://www.example.com/wrapper-sw.js?empty=1")).to.equal(true);
|
|
10
|
+
});
|
|
11
|
+
it("is false for the real worker, which carries a config reference", () => {
|
|
12
|
+
expect(isEmptyServiceWorkerUrl("https://www.example.com/wrapper-sw.js?r=6993efd7&v=2.22.3&gr=A")).to.equal(false);
|
|
13
|
+
expect(isEmptyServiceWorkerUrl("https://www.example.com/wrapper-sw.js")).to.equal(false);
|
|
14
|
+
});
|
|
15
|
+
it("is false for other values of the marker parameters", () => {
|
|
16
|
+
expect(isEmptyServiceWorkerUrl("https://www.example.com/wrapper-sw.js?empty=0")).to.equal(false);
|
|
17
|
+
expect(isEmptyServiceWorkerUrl("https://www.example.com/wrapper-sw.js?r=emptyish")).to.equal(false);
|
|
18
|
+
});
|
|
19
|
+
it("is false for a string that is not a URL", () => {
|
|
20
|
+
expect(isEmptyServiceWorkerUrl("not a url")).to.equal(false);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaqendResponse } from "../browser/baqend-response.js";
|
|
2
|
+
import { isEmptyServiceWorkerUrl } from "../empty-service-worker.js";
|
|
2
3
|
/**
|
|
3
4
|
* Intercepts request to /wrapper-sw.js
|
|
4
5
|
*
|
|
@@ -20,10 +21,10 @@ export class CustomerServiceWorkerJs {
|
|
|
20
21
|
this.customerConfig = customerConfig;
|
|
21
22
|
}
|
|
22
23
|
async handle(event) {
|
|
23
|
-
// When the SW is registered
|
|
24
|
+
// When the SW is registered for a disabled scope, the caller wants a no-op
|
|
24
25
|
// service worker on that scope — serve an empty script instead of the
|
|
25
26
|
// skonboarding wrapper that imports Speed Kit's sw.js.
|
|
26
|
-
if (
|
|
27
|
+
if (isEmptyServiceWorkerUrl(event.request.url)) {
|
|
27
28
|
return new BaqendResponse("// skonboarding empty sw", "text/javascript; charset=utf-8");
|
|
28
29
|
}
|
|
29
30
|
const wrapperSwCode = `importScripts(\`https://${this.customerConfig.appDomain}/v1/speedkit/sw.js\${location.search}\`); // skonboarding`;
|
|
@@ -5,6 +5,7 @@ import { AbortResponse } from "./browser/abort-response.js";
|
|
|
5
5
|
import { task } from "./todo-collector.js";
|
|
6
6
|
import { VanillaPuppeteer } from "puppeteer-extra";
|
|
7
7
|
import { Command } from "@oclif/core/command";
|
|
8
|
+
import { ChromeFeatureFinding, ChromeFlagDuplicate } from "../../helpers/chrome-flags.js";
|
|
8
9
|
export declare const HEADLESS_PARITY_ARGS: string[];
|
|
9
10
|
declare const HEADLESS_DEFAULT_ARGS_TO_DROP: string[];
|
|
10
11
|
export { HEADLESS_DEFAULT_ARGS_TO_DROP };
|
|
@@ -44,6 +45,8 @@ export declare class BrowserContext {
|
|
|
44
45
|
readonly debuggingPort: boolean;
|
|
45
46
|
readonly headless: boolean;
|
|
46
47
|
readonly debugPort: number;
|
|
48
|
+
/** Everything sk passes before the customer's chromeFlags. */
|
|
49
|
+
private readonly skArgs;
|
|
47
50
|
readonly browserArgs: string[];
|
|
48
51
|
readonly chromePath: string;
|
|
49
52
|
constructor(domain: string, browserVersionString?: string, chromeFlags?: string[], userConfig?: UserCliConfig, userAgent?: string, debuggingPort?: boolean, headless?: boolean, debugPort?: number);
|
|
@@ -55,6 +58,18 @@ export declare class BrowserContext {
|
|
|
55
58
|
private getHeadlessParityArgs;
|
|
56
59
|
private isChromeBrowser;
|
|
57
60
|
private getBrowserExtensionPath;
|
|
61
|
+
/** The system-specific chromeFlags of the user config, appended to every other arg. */
|
|
62
|
+
private getSystemChromeFlags;
|
|
63
|
+
private getFlagSources;
|
|
64
|
+
/** Every switch passed more than once to the launch, across sk, customer and system flags. */
|
|
65
|
+
findDuplicateFlags(): ChromeFlagDuplicate[];
|
|
66
|
+
/**
|
|
67
|
+
* Every feature listed twice, or both enabled and disabled. Puppeteer's own feature lists count
|
|
68
|
+
* too: it merges ours into them at launch, and its disabled features win like any other.
|
|
69
|
+
*/
|
|
70
|
+
findFeatureFindings(): ChromeFeatureFinding[];
|
|
71
|
+
/** Args that depend on how Chrome is launched, added after the customer's chromeFlags. */
|
|
72
|
+
private getLaunchOnlyArgs;
|
|
58
73
|
getPuppeteerLaunchOptions(): Parameters<VanillaPuppeteer["launch"]>[0];
|
|
59
74
|
}
|
|
60
75
|
export interface FetchRequestPausedEventHandler {
|
|
@@ -3,8 +3,11 @@ import { CLI_CONFIG_IS_TEST, CLI_CONFIG_NAME, CLIParameters, CLIParametersChar,
|
|
|
3
3
|
import { BrowserConfig } from "./browser/config/browser-config.js";
|
|
4
4
|
import { buildHeadedUserAgent } from "./browser/executable/headed-user-agent.js";
|
|
5
5
|
import { resolve } from "node:path";
|
|
6
|
+
import { defaultArgs } from "puppeteer";
|
|
7
|
+
import { findChromeFeatureFindings, findDuplicateChromeFlags, isFeatureListFlag, mergeChromeFeatureFlags, } from "../../helpers/chrome-flags.js";
|
|
6
8
|
const DEFAULT_BROWSER_ARGS = [
|
|
7
|
-
|
|
9
|
+
// No `Translate`: Chrome's translate code has no feature of that name, and Puppeteer disables it anyway.
|
|
10
|
+
"--enable-features=NetworkService",
|
|
8
11
|
"--no-first-run",
|
|
9
12
|
"--no-default-browser-check",
|
|
10
13
|
// Hides the `navigator.webdriver` fingerprint so customer CDN/WAF rules don't treat the session as a bot.
|
|
@@ -68,6 +71,8 @@ export class BrowserContext {
|
|
|
68
71
|
debuggingPort;
|
|
69
72
|
headless;
|
|
70
73
|
debugPort;
|
|
74
|
+
/** Everything sk passes before the customer's chromeFlags. */
|
|
75
|
+
skArgs;
|
|
71
76
|
browserArgs;
|
|
72
77
|
chromePath;
|
|
73
78
|
constructor(domain, browserVersionString = "unknown", chromeFlags, userConfig, userAgent, debuggingPort = false, headless = false, debugPort = 9222) {
|
|
@@ -96,11 +101,14 @@ export class BrowserContext {
|
|
|
96
101
|
this.userAgent =
|
|
97
102
|
this.userAgent ?? buildHeadedUserAgent(browserVersionString);
|
|
98
103
|
}
|
|
99
|
-
this.
|
|
104
|
+
this.skArgs = [
|
|
100
105
|
...browserArguments,
|
|
101
106
|
`--unsafely-treat-insecure-origin-as-secure=${domain}`,
|
|
102
107
|
...this.getHeadlessParityArgs(),
|
|
103
|
-
|
|
108
|
+
];
|
|
109
|
+
this.browserArgs = [
|
|
110
|
+
...this.skArgs,
|
|
111
|
+
// After our defaults, so a customer's chromeFlags override them — Chrome takes the last occurrence.
|
|
104
112
|
...this.chromeFlags,
|
|
105
113
|
];
|
|
106
114
|
}
|
|
@@ -127,6 +135,50 @@ export class BrowserContext {
|
|
|
127
135
|
}
|
|
128
136
|
return [];
|
|
129
137
|
}
|
|
138
|
+
/** The system-specific chromeFlags of the user config, appended to every other arg. */
|
|
139
|
+
getSystemChromeFlags() {
|
|
140
|
+
return this.userConfig?.chromeFlags ?? [];
|
|
141
|
+
}
|
|
142
|
+
getFlagSources() {
|
|
143
|
+
return [
|
|
144
|
+
{ source: "sk", flags: [...this.skArgs, ...this.getLaunchOnlyArgs()] },
|
|
145
|
+
{ source: "customer config", flags: this.chromeFlags },
|
|
146
|
+
{ source: "system", flags: this.getSystemChromeFlags() },
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
/** Every switch passed more than once to the launch, across sk, customer and system flags. */
|
|
150
|
+
findDuplicateFlags() {
|
|
151
|
+
return findDuplicateChromeFlags(this.getFlagSources());
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Every feature listed twice, or both enabled and disabled. Puppeteer's own feature lists count
|
|
155
|
+
* too: it merges ours into them at launch, and its disabled features win like any other.
|
|
156
|
+
*/
|
|
157
|
+
findFeatureFindings() {
|
|
158
|
+
const puppeteerFeatureFlags = defaultArgs({
|
|
159
|
+
headless: this.headless,
|
|
160
|
+
}).filter(isFeatureListFlag);
|
|
161
|
+
return findChromeFeatureFindings([
|
|
162
|
+
{ source: "puppeteer", flags: puppeteerFeatureFlags },
|
|
163
|
+
...this.getFlagSources(),
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
/** Args that depend on how Chrome is launched, added after the customer's chromeFlags. */
|
|
167
|
+
getLaunchOnlyArgs() {
|
|
168
|
+
const args = [];
|
|
169
|
+
if (this.userConfig?.chromeExtensionPaths) {
|
|
170
|
+
if (this.isChromeBrowser()) {
|
|
171
|
+
args.push("--remote-debugging-pipe");
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
args.push(`--load-extension=${this.userConfig?.chromeExtensionPaths}`, `--disable-extensions-except=${this.userConfig?.chromeExtensionPaths}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (this.debuggingPort || this.headless) {
|
|
178
|
+
args.push(`--remote-debugging-port=${this.debugPort}`);
|
|
179
|
+
}
|
|
180
|
+
return args;
|
|
181
|
+
}
|
|
130
182
|
getPuppeteerLaunchOptions() {
|
|
131
183
|
const options = {
|
|
132
184
|
devtools: !this.headless,
|
|
@@ -134,7 +186,11 @@ export class BrowserContext {
|
|
|
134
186
|
defaultViewport: null,
|
|
135
187
|
headless: this.headless,
|
|
136
188
|
executablePath: this.chromePath,
|
|
137
|
-
args:
|
|
189
|
+
args: mergeChromeFeatureFlags([
|
|
190
|
+
...this.browserArgs,
|
|
191
|
+
...this.getLaunchOnlyArgs(),
|
|
192
|
+
...this.getSystemChromeFlags(),
|
|
193
|
+
]),
|
|
138
194
|
// Strip Puppeteer's default `--enable-automation` so Chrome doesn't show
|
|
139
195
|
// the "Chrome is being controlled by automated test software" infobar.
|
|
140
196
|
ignoreDefaultArgs: [
|
|
@@ -142,18 +198,9 @@ export class BrowserContext {
|
|
|
142
198
|
...(this.headless ? HEADLESS_DEFAULT_ARGS_TO_DROP : []),
|
|
143
199
|
],
|
|
144
200
|
};
|
|
145
|
-
if (this.userConfig?.chromeExtensionPaths) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
options["pipe"] = true;
|
|
149
|
-
options.args.push("--remote-debugging-pipe");
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
options.args.push(`--load-extension=${this.userConfig?.chromeExtensionPaths}`, `--disable-extensions-except=${this.userConfig?.chromeExtensionPaths}`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (this.debuggingPort || this.headless) {
|
|
156
|
-
options.args.push(`--remote-debugging-port=${this.debugPort}`);
|
|
201
|
+
if (this.userConfig?.chromeExtensionPaths && this.isChromeBrowser()) {
|
|
202
|
+
options["enableExtensions"] = this.getBrowserExtensionPath();
|
|
203
|
+
options["pipe"] = true;
|
|
157
204
|
}
|
|
158
205
|
return options;
|
|
159
206
|
}
|
|
@@ -96,3 +96,60 @@ describe("BrowserContext headless/headed parity", () => {
|
|
|
96
96
|
expect(launchArgs(true).length).to.equal(first);
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
|
+
describe("BrowserContext system chromeFlags", () => {
|
|
100
|
+
function systemContext(chromeFlags, systemFlags, debuggingPort = false) {
|
|
101
|
+
return new BrowserContext("example.com", "Chrome/120", chromeFlags, { ...userConfig, chromeFlags: systemFlags }, undefined, debuggingPort, false, undefined);
|
|
102
|
+
}
|
|
103
|
+
it("appends the system flags after every other arg", () => {
|
|
104
|
+
const args = systemContext(["--customer"], ["--system-a", "--system-b"], true).getPuppeteerLaunchOptions().args;
|
|
105
|
+
expect(args.slice(-2)).to.deep.equal(["--system-a", "--system-b"]);
|
|
106
|
+
expect(args.indexOf("--customer")).to.be.lessThan(args.indexOf("--remote-debugging-port=9222"));
|
|
107
|
+
});
|
|
108
|
+
it("keeps a duplicate in the launch args", () => {
|
|
109
|
+
const args = systemContext(["--mute-audio"], ["--mute-audio"]).getPuppeteerLaunchOptions().args;
|
|
110
|
+
expect(args.filter((arg) => arg === "--mute-audio")).to.have.length(2);
|
|
111
|
+
});
|
|
112
|
+
it("finds duplicates against sk, customer and launch-only args", () => {
|
|
113
|
+
const duplicates = systemContext(["--mute-audio"], ["--mute-audio", "--no-first-run", "--remote-debugging-port=1234"], true).findDuplicateFlags();
|
|
114
|
+
expect(duplicates.map(({ name, occurrences }) => [
|
|
115
|
+
name,
|
|
116
|
+
occurrences.map(({ source }) => source),
|
|
117
|
+
])).to.deep.equal([
|
|
118
|
+
["--no-first-run", ["sk", "system"]],
|
|
119
|
+
["--remote-debugging-port", ["sk", "system"]],
|
|
120
|
+
["--mute-audio", ["customer config", "system"]],
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
it("reports nothing without system flags", () => {
|
|
124
|
+
expect(systemContext([], []).findDuplicateFlags()).to.deep.equal([]);
|
|
125
|
+
});
|
|
126
|
+
it("merges the feature lists of every source into one flag each", () => {
|
|
127
|
+
const args = systemContext(["--enable-features=Customer"], ["--enable-features=System", "--disable-blink-features=Foo"]).getPuppeteerLaunchOptions().args;
|
|
128
|
+
expect(args.filter((arg) => arg.startsWith("--enable-features="))).to.deep.equal(["--enable-features=NetworkService,Customer,System"]);
|
|
129
|
+
expect(args.filter((arg) => arg.startsWith("--disable-blink-features="))).to.deep.equal(["--disable-blink-features=AutomationControlled,Foo"]);
|
|
130
|
+
});
|
|
131
|
+
it("checks features against Puppeteer's own lists", () => {
|
|
132
|
+
const findings = systemContext([], [
|
|
133
|
+
"--enable-features=AcceptCHFrame",
|
|
134
|
+
"--disable-blink-features=AutomationControlled",
|
|
135
|
+
]).findFeatureFindings();
|
|
136
|
+
expect(findings.map((finding) => finding.kind === "conflict"
|
|
137
|
+
? [
|
|
138
|
+
"conflict",
|
|
139
|
+
finding.feature,
|
|
140
|
+
finding.disabled.map(({ source }) => source),
|
|
141
|
+
]
|
|
142
|
+
: [
|
|
143
|
+
"duplicate",
|
|
144
|
+
finding.feature,
|
|
145
|
+
finding.occurrences.map(({ source }) => source),
|
|
146
|
+
])).to.deep.equal([
|
|
147
|
+
["conflict", "AcceptCHFrame", ["puppeteer"]],
|
|
148
|
+
["duplicate", "AutomationControlled", ["sk", "system"]],
|
|
149
|
+
]);
|
|
150
|
+
});
|
|
151
|
+
it("finds no feature issue in sk's own launch", () => {
|
|
152
|
+
expect(systemContext([], []).findFeatureFindings()).to.deep.equal([]);
|
|
153
|
+
expect(newContext(true).findFeatureFindings()).to.deep.equal([]);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -43,6 +43,7 @@ import { ExecutableValidator } from "./browser/executable/executable-validator.j
|
|
|
43
43
|
import { applyOriginProxy, withOriginProxyFlag, } from "../../helpers/origin-proxy.js";
|
|
44
44
|
import { QueryBuilderFactory } from "../query-builder/query-builder-factory.js";
|
|
45
45
|
import { QueryType } from "../query-builder/query-builder-model.js";
|
|
46
|
+
import { formatChromeFeatureFinding, formatChromeFlagDuplicate, } from "../../helpers/chrome-flags.js";
|
|
46
47
|
export class OnboardingServiceFactory {
|
|
47
48
|
context;
|
|
48
49
|
cliConfig;
|
|
@@ -86,6 +87,12 @@ export class OnboardingServiceFactory {
|
|
|
86
87
|
const browserValidator = new ExecutableValidator(this.cliConfig, cli);
|
|
87
88
|
const browserVersionString = await browserValidator.validateOrInstall();
|
|
88
89
|
const browserContext = new BrowserContext(domainToStart, browserVersionString, withOriginProxyFlag(customerConfig.chromeFlags), this.cliConfig, undefined, this.context.debuggingPort, this.context.headless, this.context.debugPort);
|
|
90
|
+
for (const duplicate of browserContext.findDuplicateFlags()) {
|
|
91
|
+
cli.writeWarning(formatChromeFlagDuplicate(duplicate));
|
|
92
|
+
}
|
|
93
|
+
for (const finding of browserContext.findFeatureFindings()) {
|
|
94
|
+
cli.writeWarning(formatChromeFeatureFinding(finding));
|
|
95
|
+
}
|
|
89
96
|
if (this.context.debuggingPort || this.context.headless) {
|
|
90
97
|
cli.writeWarning(`Chrome remote debugging enabled on port ${this.context.debugPort}.`);
|
|
91
98
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import puppeteerExtra from "puppeteer-extra";
|
|
2
2
|
import { BROWSER_EVENTS, CDP_SESSION, } from "./onboarding-model.js";
|
|
3
3
|
import { safe } from "../../helpers/safe.js";
|
|
4
|
+
import { isEmptyServiceWorkerUrl } from "./empty-service-worker.js";
|
|
4
5
|
// A SW version activating later than this after the last locally served sw.js
|
|
5
6
|
// cannot originate from our interception — it is a deployed-build takeover.
|
|
6
7
|
const LOCAL_SW_SERVE_GRACE_MS = 10_000;
|
|
@@ -179,7 +180,7 @@ export class OnboardingService {
|
|
|
179
180
|
if (!version.scriptURL.includes(this.customerConfig.swPath)) {
|
|
180
181
|
return false;
|
|
181
182
|
}
|
|
182
|
-
if (version.scriptURL
|
|
183
|
+
if (isEmptyServiceWorkerUrl(version.scriptURL)) {
|
|
183
184
|
return false;
|
|
184
185
|
}
|
|
185
186
|
// Activation events repeat per version (runningStatus changes) — handle each version once.
|
package/oclif.manifest.json
CHANGED