@speedkit/cli 4.39.0 → 4.41.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 +26 -0
- package/README.md +10 -1
- package/dist/commands/airports_iata.json +9202 -1
- package/dist/commands/generate-customer-config.d.ts +2 -0
- package/dist/commands/generate-customer-config.js +7 -1
- package/dist/services/customer-config/customer-config-service-build-context.d.ts +8 -0
- package/dist/services/customer-config/customer-config-service-build-context.js +8 -0
- package/dist/services/customer-config/customer-config-service-factory.js +3 -1
- package/dist/services/customer-config/customer-config-service.d.ts +10 -7
- package/dist/services/customer-config/customer-config-service.js +138 -308
- package/dist/services/customer-config/index.d.ts +2 -0
- package/dist/services/customer-config/index.js +2 -0
- package/dist/services/customer-config/spec/wizard-answers.spec.d.ts +1 -0
- package/dist/services/customer-config/spec/wizard-answers.spec.js +207 -0
- package/dist/services/customer-config/wizard-answers.d.ts +48 -0
- package/dist/services/customer-config/wizard-answers.js +67 -0
- package/dist/services/customer-config/wizard-questions.d.ts +86 -0
- package/dist/services/customer-config/wizard-questions.js +400 -0
- package/dist/services/onboarding/browser/executable/executable-validator.js +1 -1
- package/dist/services/onboarding/browser/extension/devtools-panel.d.ts +36 -0
- package/dist/services/onboarding/browser/extension/devtools-panel.js +82 -0
- package/dist/services/onboarding/browser/extension/extension-bridge.d.ts +55 -24
- package/dist/services/onboarding/browser/extension/extension-bridge.js +161 -66
- package/dist/services/onboarding/onboarding-model.d.ts +29 -1
- package/dist/services/onboarding/onboarding-model.js +7 -13
- package/dist/services/onboarding/onboarding-service-factory.d.ts +1 -0
- package/dist/services/onboarding/onboarding-service-factory.js +24 -3
- package/dist/services/onboarding/onboarding-service.d.ts +8 -0
- package/dist/services/onboarding/onboarding-service.js +28 -0
- package/dist/services/onboarding/spec/browser/extension/devtools-panel.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/browser/extension/devtools-panel.spec.js +99 -0
- package/dist/services/onboarding/spec/browser/extension/extension-bridge.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/browser/extension/extension-bridge.spec.js +235 -0
- package/dist/services/onboarding/spec/onboarding-model.spec.js +29 -0
- package/dist/templates/speedKit.Revalidated.js +5 -1
- package/oclif.manifest.json +17 -2
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { safe } from "../../../../helpers/safe.js";
|
|
2
2
|
const STORAGE_KEY = "skCli";
|
|
3
3
|
const PROTOCOL_VERSION = 1;
|
|
4
|
-
const
|
|
4
|
+
const SW_WAIT_MS = 2000;
|
|
5
5
|
const INIT_POLL_INTERVAL_MS = 200;
|
|
6
|
-
const INIT_POLL_TIMEOUT_MS =
|
|
6
|
+
const INIT_POLL_TIMEOUT_MS = 10000;
|
|
7
7
|
const EXTENSION_NAME_MATCHERS = ["speed-kit devtools", "devtools extension"];
|
|
8
8
|
/**
|
|
9
9
|
* Name heuristic for the devtools extension, shared by ExtensionValidator
|
|
10
|
-
* (is one among the loaded extensions?) and the
|
|
10
|
+
* (is one among the loaded extensions?) and the extension lookup below.
|
|
11
11
|
*/
|
|
12
12
|
export function isDevtoolsExtensionName(name) {
|
|
13
13
|
const lower = name.toLowerCase();
|
|
@@ -15,22 +15,36 @@ export function isDevtoolsExtensionName(name) {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Writes onboarding state (messages, status) into the devtools extension's
|
|
18
|
-
* chrome.storage.local
|
|
19
|
-
* service-worker target. The devtools extension subscribes via
|
|
18
|
+
* chrome.storage.local, which the panel subscribes to via
|
|
20
19
|
* chrome.storage.onChanged. Replaces the legacy `window.skCliMessages` page
|
|
21
20
|
* injection — no more customer-visible global state.
|
|
22
21
|
*
|
|
22
|
+
* **The write does not go through the extension's service worker.** It used
|
|
23
|
+
* to, and an MV3 worker that has stopped is not a target anyone can attach to:
|
|
24
|
+
* nothing restarted it, so every write after it stopped failed for the rest of
|
|
25
|
+
* the run and the panel kept showing whatever it had last received.
|
|
26
|
+
* `Extensions.setStorageItems` writes the storage from the browser side, works
|
|
27
|
+
* whether the worker runs or not, and restarts it as a side effect. It has to
|
|
28
|
+
* be sent from a session on a page the extension can access — an http(s) page,
|
|
29
|
+
* given its `<all_urls>` — because a browser-level session is refused. The
|
|
30
|
+
* worker stays as the fallback for a Chrome that refuses the command.
|
|
31
|
+
*
|
|
23
32
|
* Lifecycle: construct once per browser, call `init()` after the browser is
|
|
24
|
-
* launched
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
33
|
+
* launched, then call `writeMessages` whenever the message list changes.
|
|
34
|
+
* Constructed with `devtoolsExtensionLoaded: false` (no devtools extension
|
|
35
|
+
* among the browser's extensions) the bridge stays unavailable and never
|
|
36
|
+
* looks for one.
|
|
28
37
|
*/
|
|
29
38
|
export class ExtensionBridge {
|
|
30
39
|
cli;
|
|
31
40
|
devtoolsExtensionLoaded;
|
|
32
41
|
browser = null;
|
|
33
42
|
extensionId = null;
|
|
43
|
+
/** The newest snapshot not yet stored. Older ones are never worth writing. */
|
|
44
|
+
pending = null;
|
|
45
|
+
writing = null;
|
|
46
|
+
/** Set while writes fail, so an outage is reported once, not per write. */
|
|
47
|
+
failing = false;
|
|
34
48
|
constructor(cli, devtoolsExtensionLoaded) {
|
|
35
49
|
this.cli = cli;
|
|
36
50
|
this.devtoolsExtensionLoaded = devtoolsExtensionLoaded;
|
|
@@ -43,11 +57,11 @@ export class ExtensionBridge {
|
|
|
43
57
|
return this.devtoolsExtensionLoaded;
|
|
44
58
|
}
|
|
45
59
|
/**
|
|
46
|
-
* Bind the bridge to a freshly-launched browser
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
60
|
+
* Bind the bridge to a freshly-launched browser and find the devtools
|
|
61
|
+
* extension's ID.
|
|
62
|
+
*
|
|
63
|
+
* Polls, because Puppeteer's `launch` returns before `enableExtensions` has
|
|
64
|
+
* finished installing. Throws if the extension does not show up in time.
|
|
51
65
|
*/
|
|
52
66
|
async init(browser) {
|
|
53
67
|
if (!this.isAvailable) {
|
|
@@ -55,61 +69,143 @@ export class ExtensionBridge {
|
|
|
55
69
|
}
|
|
56
70
|
this.browser = browser;
|
|
57
71
|
const deadline = Date.now() + INIT_POLL_TIMEOUT_MS;
|
|
58
|
-
let
|
|
59
|
-
while (!
|
|
72
|
+
let id = await this.findExtensionId();
|
|
73
|
+
while (!id && Date.now() < deadline) {
|
|
60
74
|
await sleep(INIT_POLL_INTERVAL_MS);
|
|
61
|
-
|
|
75
|
+
id = await this.findExtensionId();
|
|
62
76
|
}
|
|
63
|
-
if (!
|
|
64
|
-
throw new Error(
|
|
65
|
-
|
|
66
|
-
"and its name matches one of: " +
|
|
77
|
+
if (!id) {
|
|
78
|
+
throw new Error(`ExtensionBridge: no devtools extension found within ${INIT_POLL_TIMEOUT_MS} ms. ` +
|
|
79
|
+
"Confirm the extension is loaded and its name matches one of: " +
|
|
67
80
|
EXTENSION_NAME_MATCHERS.join(", "));
|
|
68
81
|
}
|
|
69
|
-
this.extensionId =
|
|
82
|
+
this.extensionId = id;
|
|
83
|
+
// A snapshot that could not be stored waits for the next page load. That
|
|
84
|
+
// is when an http(s) page to send it from is most likely to exist, and
|
|
85
|
+
// when the panel is most likely to be looked at.
|
|
86
|
+
browser.on("targetchanged", (target) => {
|
|
87
|
+
if (this.pending && target.type() === "page" && isWebUrl(target.url())) {
|
|
88
|
+
void this.drain();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
70
91
|
}
|
|
71
92
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* a
|
|
93
|
+
* Store the current messages snapshot in chrome.storage.local.
|
|
94
|
+
*
|
|
95
|
+
* Only the newest snapshot is written: one write is in flight at a time, and
|
|
96
|
+
* a snapshot that arrives meanwhile replaces the one waiting behind it, so an
|
|
97
|
+
* older snapshot can never land after a newer one. A snapshot that fails
|
|
98
|
+
* stays pending and is retried on the next page load. Failures are reported
|
|
99
|
+
* but never thrown — a missed write is degraded UX, not a fatal onboarding
|
|
100
|
+
* failure.
|
|
76
101
|
*/
|
|
77
102
|
async writeMessages(messages) {
|
|
78
|
-
if (!this.
|
|
103
|
+
if (!this.available) {
|
|
79
104
|
this.cli.writeWarning("ExtensionBridge.writeMessages called before init()");
|
|
80
105
|
return;
|
|
81
106
|
}
|
|
82
|
-
|
|
107
|
+
this.pending = {
|
|
83
108
|
protocolVersion: PROTOCOL_VERSION,
|
|
84
109
|
writtenAt: new Date().toISOString(),
|
|
85
110
|
messages,
|
|
86
111
|
};
|
|
87
|
-
|
|
88
|
-
|
|
112
|
+
await this.drain();
|
|
113
|
+
}
|
|
114
|
+
/** Whether the bridge found an extension to talk to at all. */
|
|
115
|
+
get available() {
|
|
116
|
+
return Boolean(this.browser && this.extensionId);
|
|
117
|
+
}
|
|
118
|
+
/** The devtools extension's ID, once `init()` has found it. */
|
|
119
|
+
get devtoolsExtensionId() {
|
|
120
|
+
return this.extensionId;
|
|
121
|
+
}
|
|
122
|
+
drain() {
|
|
123
|
+
this.writing ??= this.writePending().finally(() => {
|
|
124
|
+
this.writing = null;
|
|
125
|
+
});
|
|
126
|
+
return this.writing;
|
|
127
|
+
}
|
|
128
|
+
async writePending() {
|
|
129
|
+
while (this.pending) {
|
|
130
|
+
const payload = this.pending;
|
|
131
|
+
const result = await safe(this.store({ [STORAGE_KEY]: payload }));
|
|
132
|
+
if (result.success !== true) {
|
|
133
|
+
this.reportFailure(result.error);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (this.pending === payload) {
|
|
137
|
+
this.pending = null;
|
|
138
|
+
}
|
|
139
|
+
this.reportRecovery();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async store(values) {
|
|
143
|
+
const direct = await safe(this.setStorageItems(values));
|
|
144
|
+
if (direct.success === true)
|
|
89
145
|
return;
|
|
90
|
-
await
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
146
|
+
const viaWorker = await safe(this.evaluateInServiceWorker(`chrome.storage.local.set(${JSON.stringify(values)})`));
|
|
147
|
+
if (viaWorker.success === true)
|
|
148
|
+
return;
|
|
149
|
+
throw new Error(`${direct.error} (through the service worker: ${viaWorker.error})`);
|
|
150
|
+
}
|
|
151
|
+
reportFailure(error) {
|
|
152
|
+
if (this.failing)
|
|
153
|
+
return;
|
|
154
|
+
this.failing = true;
|
|
155
|
+
this.cli.writeWarning(`The devtools panel is not receiving updates: ${error}. Retrying on the next page load.`);
|
|
156
|
+
}
|
|
157
|
+
reportRecovery() {
|
|
158
|
+
if (!this.failing)
|
|
159
|
+
return;
|
|
160
|
+
this.failing = false;
|
|
161
|
+
this.cli.writeSuccess("The devtools panel is receiving updates again.");
|
|
162
|
+
}
|
|
163
|
+
async setStorageItems(values) {
|
|
164
|
+
const page = await this.findWebPage();
|
|
165
|
+
if (!page) {
|
|
166
|
+
throw new Error("no http(s) page is open to write the storage from");
|
|
94
167
|
}
|
|
168
|
+
const session = await page.createCDPSession();
|
|
169
|
+
try {
|
|
170
|
+
await session.send("Extensions.setStorageItems", {
|
|
171
|
+
id: this.extensionId,
|
|
172
|
+
storageArea: "local",
|
|
173
|
+
values,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
await safe(session.detach());
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async findWebPage() {
|
|
181
|
+
const pages = await this.browser.pages();
|
|
182
|
+
return pages.find((page) => isWebUrl(page.url())) ?? null;
|
|
95
183
|
}
|
|
96
|
-
|
|
97
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Run an expression inside the devtools extension's service worker, waiting
|
|
186
|
+
* briefly for one when none is running. Only the fallback: waiting does not
|
|
187
|
+
* start a worker, it only catches one that is starting anyway.
|
|
188
|
+
*/
|
|
189
|
+
async evaluateInServiceWorker(expression) {
|
|
190
|
+
const prefix = `chrome-extension://${this.extensionId}/`;
|
|
191
|
+
const isWorker = (target) => target.type() === "service_worker" && target.url().startsWith(prefix);
|
|
192
|
+
const target = this.browser.targets().find(isWorker) ??
|
|
193
|
+
(await this.browser
|
|
194
|
+
.waitForTarget(isWorker, { timeout: SW_WAIT_MS })
|
|
195
|
+
.catch(() => null));
|
|
98
196
|
if (!target) {
|
|
99
197
|
throw new Error("service-worker target not found");
|
|
100
198
|
}
|
|
101
199
|
const session = await target.createCDPSession();
|
|
102
200
|
try {
|
|
103
|
-
const expression = `chrome.storage.local.set(${JSON.stringify({
|
|
104
|
-
[STORAGE_KEY]: payload,
|
|
105
|
-
})})`;
|
|
106
201
|
const evalResult = await session.send("Runtime.evaluate", {
|
|
107
202
|
expression,
|
|
108
203
|
awaitPromise: true,
|
|
109
204
|
returnByValue: true,
|
|
110
205
|
});
|
|
111
206
|
if (evalResult.exceptionDetails) {
|
|
112
|
-
throw new Error(evalResult.exceptionDetails.
|
|
207
|
+
throw new Error(evalResult.exceptionDetails.exception?.description ||
|
|
208
|
+
evalResult.exceptionDetails.text ||
|
|
113
209
|
"Runtime.evaluate threw an unknown exception");
|
|
114
210
|
}
|
|
115
211
|
}
|
|
@@ -118,31 +214,31 @@ export class ExtensionBridge {
|
|
|
118
214
|
}
|
|
119
215
|
}
|
|
120
216
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
217
|
+
* The devtools extension's ID, from `Extensions.getExtensions` — which needs
|
|
218
|
+
* no running worker — or, when Chrome refuses that, from the manifest name
|
|
219
|
+
* of a running extension worker. Discovered by name rather than computed
|
|
220
|
+
* from the unpacked path, because unpacked-extension IDs depend on the
|
|
221
|
+
* absolute path and OS path normalization.
|
|
123
222
|
*/
|
|
124
|
-
async
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
223
|
+
async findExtensionId() {
|
|
224
|
+
const listed = await safe(this.listExtensions());
|
|
225
|
+
if (listed.success === true) {
|
|
226
|
+
return (listed.data.find((e) => isDevtoolsExtensionName(e.name))?.id ?? null);
|
|
227
|
+
}
|
|
228
|
+
const worker = await this.findDevtoolsServiceWorker();
|
|
229
|
+
return worker ? this.extractExtensionId(worker.url()) : null;
|
|
230
|
+
}
|
|
231
|
+
async listExtensions() {
|
|
232
|
+
const session = await this.browser.target().createCDPSession();
|
|
233
|
+
try {
|
|
234
|
+
const { extensions } = await session.send("Extensions.getExtensions");
|
|
235
|
+
return extensions;
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
await safe(session.detach());
|
|
133
239
|
}
|
|
134
|
-
return null;
|
|
135
240
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Scan service-worker targets, evaluate `chrome.runtime.getManifest().name`
|
|
138
|
-
* on each, and return the first whose name matches the devtools-extension
|
|
139
|
-
* heuristic. We discover the extension by name (not by computing the ID
|
|
140
|
-
* from the unpacked path) because unpacked-extension IDs depend on the
|
|
141
|
-
* absolute path and OS path normalization.
|
|
142
|
-
*/
|
|
143
241
|
async findDevtoolsServiceWorker() {
|
|
144
|
-
if (!this.browser)
|
|
145
|
-
return null;
|
|
146
242
|
const swTargets = this.browser
|
|
147
243
|
.targets()
|
|
148
244
|
.filter((t) => t.type() === "service_worker");
|
|
@@ -173,13 +269,12 @@ export class ExtensionBridge {
|
|
|
173
269
|
}
|
|
174
270
|
}
|
|
175
271
|
extractExtensionId(url) {
|
|
176
|
-
|
|
177
|
-
if (!match) {
|
|
178
|
-
throw new Error(`Could not extract extension ID from URL: ${url}`);
|
|
179
|
-
}
|
|
180
|
-
return match[1];
|
|
272
|
+
return url.match(/^chrome-extension:\/\/([a-p]{32})\//)?.[1] ?? null;
|
|
181
273
|
}
|
|
182
274
|
}
|
|
275
|
+
function isWebUrl(url) {
|
|
276
|
+
return /^https?:\/\//.test(url);
|
|
277
|
+
}
|
|
183
278
|
function sleep(ms) {
|
|
184
279
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
185
280
|
}
|
|
@@ -55,7 +55,6 @@ export declare class BrowserContext {
|
|
|
55
55
|
* refetch would still leak the headless token and re-poison the merged body.
|
|
56
56
|
*/
|
|
57
57
|
private getHeadlessParityArgs;
|
|
58
|
-
private isChromeBrowser;
|
|
59
58
|
private getBrowserExtensionPath;
|
|
60
59
|
/** The system-specific chromeFlags of the user config, appended to every other arg. */
|
|
61
60
|
private getSystemChromeFlags;
|
|
@@ -119,9 +118,38 @@ export interface SpeedKitServerConfig {
|
|
|
119
118
|
};
|
|
120
119
|
}
|
|
121
120
|
export interface SkCliInfo {
|
|
121
|
+
/** The CLI that wrote this — the writer, not the run, so it stays outside. */
|
|
122
122
|
version: string;
|
|
123
|
+
/** What this run is for and how it was started. */
|
|
124
|
+
session: SkCliSessionInfo;
|
|
125
|
+
}
|
|
126
|
+
export interface SkCliSessionInfo {
|
|
123
127
|
app: string;
|
|
124
128
|
customerConfigPath: string;
|
|
129
|
+
/**
|
|
130
|
+
* The customer config's `origins`. The extension marks only tabs on these,
|
|
131
|
+
* so a second customer opened in the same browser is not drawn into this
|
|
132
|
+
* run's tab group.
|
|
133
|
+
*/
|
|
134
|
+
origins: string[];
|
|
135
|
+
/** The customer config's `swPath`: where the Speed Kit service worker is served. */
|
|
136
|
+
swPath: string;
|
|
137
|
+
/** The customer config's `scope`: the URL prefix that service worker controls. */
|
|
138
|
+
scope: string;
|
|
139
|
+
/** `--local`: the documentHandler is built and served from this machine. */
|
|
140
|
+
local: boolean;
|
|
141
|
+
/** The customer config's `forceInstall`: Speed Kit is installed on every page. */
|
|
142
|
+
forceInstall: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* The SOCKS proxy every origin request goes through, or null for a direct
|
|
145
|
+
* connection. `source` says whether `SK_PROXY_SERVER` set it or the
|
|
146
|
+
* customer config's `chromeFlags` did — the environment overrides the exit
|
|
147
|
+
* region the customer pinned, and that is worth seeing.
|
|
148
|
+
*/
|
|
149
|
+
proxy: {
|
|
150
|
+
url: string;
|
|
151
|
+
source: "environment" | "chromeFlags";
|
|
152
|
+
} | null;
|
|
125
153
|
}
|
|
126
154
|
export interface AthenaInfo {
|
|
127
155
|
client: boolean;
|
|
@@ -124,9 +124,6 @@ export class BrowserContext {
|
|
|
124
124
|
...(this.userAgent ? [`--user-agent=${this.userAgent}`] : []),
|
|
125
125
|
];
|
|
126
126
|
}
|
|
127
|
-
isChromeBrowser() {
|
|
128
|
-
return !!/chrome/i.test(this.browserVersionString);
|
|
129
|
-
}
|
|
130
127
|
getBrowserExtensionPath() {
|
|
131
128
|
if (this.environment?.settings.chromeExtensionPaths) {
|
|
132
129
|
return this.environment.settings.chromeExtensionPaths.split(",");
|
|
@@ -164,14 +161,6 @@ export class BrowserContext {
|
|
|
164
161
|
/** Args that depend on how Chrome is launched, added after the customer's chromeFlags. */
|
|
165
162
|
getLaunchOnlyArgs() {
|
|
166
163
|
const args = [];
|
|
167
|
-
if (this.environment?.settings.chromeExtensionPaths) {
|
|
168
|
-
if (this.isChromeBrowser()) {
|
|
169
|
-
args.push("--remote-debugging-pipe");
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
args.push(`--load-extension=${this.environment?.settings.chromeExtensionPaths}`, `--disable-extensions-except=${this.environment?.settings.chromeExtensionPaths}`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
164
|
if (this.debuggingPort || this.headless) {
|
|
176
165
|
args.push(`--remote-debugging-port=${this.debugPort}`);
|
|
177
166
|
}
|
|
@@ -196,8 +185,13 @@ export class BrowserContext {
|
|
|
196
185
|
...(this.headless ? HEADLESS_DEFAULT_ARGS_TO_DROP : []),
|
|
197
186
|
],
|
|
198
187
|
};
|
|
199
|
-
|
|
200
|
-
|
|
188
|
+
// One way for every Chromium build. Branded Chrome ignores
|
|
189
|
+
// `--load-extension` since 137, so extensions are installed over the pipe
|
|
190
|
+
// with `Extensions.loadUnpacked`, which also makes Puppeteer pass
|
|
191
|
+
// `--enable-unsafe-extension-debugging`. Those two are the documented
|
|
192
|
+
// preconditions of the `Extensions` domain, which ExtensionBridge writes
|
|
193
|
+
// the devtools panel's storage through.
|
|
194
|
+
if (this.environment?.settings.chromeExtensionPaths) {
|
|
201
195
|
options["enableExtensions"] = this.getBrowserExtensionPath();
|
|
202
196
|
options["pipe"] = true;
|
|
203
197
|
}
|
|
@@ -43,7 +43,7 @@ import { StaticRecipe } from "../integration-api/virtual/static-recipe.js";
|
|
|
43
43
|
import { DiffAgainstCurrentPage } from "./dashboard/diff-against-current-page.js";
|
|
44
44
|
import { ExtensionDownloader } from "./browser/extension/extension-downloader.js";
|
|
45
45
|
import { ExecutableValidator } from "./browser/executable/executable-validator.js";
|
|
46
|
-
import { applyOriginProxy, withOriginProxyFlag, } from "../../helpers/origin-proxy.js";
|
|
46
|
+
import { PROXY_ENVIRONMENT_VARIABLE, applyOriginProxy, currentOriginProxy, formatProxy, withOriginProxyFlag, } from "../../helpers/origin-proxy.js";
|
|
47
47
|
import { QueryBuilderFactory } from "../query-builder/query-builder-factory.js";
|
|
48
48
|
import { ParameterQueryServiceBuildContext } from "../query-builder/query-builder-service-build-context.js";
|
|
49
49
|
import { formatChromeFeatureFinding, formatChromeFlagDuplicate, } from "../../helpers/chrome-flags.js";
|
|
@@ -169,8 +169,7 @@ export class OnboardingServiceFactory {
|
|
|
169
169
|
id: "skCli",
|
|
170
170
|
data: {
|
|
171
171
|
version: this.context.environment.oclif.version,
|
|
172
|
-
|
|
173
|
-
customerConfigPath: path.resolve(this.context.customerPath, this.context.configName),
|
|
172
|
+
session: this.sessionInfo(customerConfig),
|
|
174
173
|
},
|
|
175
174
|
});
|
|
176
175
|
messageHandler.addMessage({
|
|
@@ -330,6 +329,28 @@ export class OnboardingServiceFactory {
|
|
|
330
329
|
}
|
|
331
330
|
return integrationApi.run(integrationApiArray);
|
|
332
331
|
}
|
|
332
|
+
sessionInfo(customerConfig) {
|
|
333
|
+
// Read back rather than recomputed: `applyOriginProxy` has already decided
|
|
334
|
+
// which proxy wins, and the panel should see that decision, not a second one.
|
|
335
|
+
const proxy = currentOriginProxy();
|
|
336
|
+
return {
|
|
337
|
+
app: customerConfig.app,
|
|
338
|
+
customerConfigPath: path.resolve(this.context.customerPath, this.context.configName),
|
|
339
|
+
origins: customerConfig.origins ?? [],
|
|
340
|
+
swPath: customerConfig.swPath,
|
|
341
|
+
scope: customerConfig.scope,
|
|
342
|
+
local: Boolean(this.context.local),
|
|
343
|
+
forceInstall: Boolean(customerConfig.forceInstall),
|
|
344
|
+
proxy: proxy
|
|
345
|
+
? {
|
|
346
|
+
url: formatProxy(proxy),
|
|
347
|
+
source: process.env[PROXY_ENVIRONMENT_VARIABLE]?.trim()
|
|
348
|
+
? "environment"
|
|
349
|
+
: "chromeFlags",
|
|
350
|
+
}
|
|
351
|
+
: null,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
333
354
|
async getUrlForTest(customerConfig, cli) {
|
|
334
355
|
// Consider startup domain based on the following priority:
|
|
335
356
|
// 1. domain flag (-d)
|
|
@@ -41,6 +41,14 @@ export declare class OnboardingService {
|
|
|
41
41
|
* sk-cli. Without a loaded devtools extension there is nothing to attach
|
|
42
42
|
* to — ExtensionValidator already reported why — so it is skipped.
|
|
43
43
|
*/
|
|
44
|
+
/**
|
|
45
|
+
* Open the run's DevTools on the Speed Kit panel rather than on Elements.
|
|
46
|
+
*
|
|
47
|
+
* Headed only: that is where `devtools: true` opens a DevTools window for the
|
|
48
|
+
* tab, and where someone is looking at it. The selection reaches into
|
|
49
|
+
* DevTools' internals, so a failure is a warning and nothing more.
|
|
50
|
+
*/
|
|
51
|
+
private showDevtoolsPanelOnStart;
|
|
44
52
|
private attachExtensionBridge;
|
|
45
53
|
private findPage;
|
|
46
54
|
private prepareCleanState;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BROWSER_EVENTS, CDP_SESSION, } from "./onboarding-model.js";
|
|
2
|
+
import { PanelNotFoundError, showDevtoolsPanel, } from "./browser/extension/devtools-panel.js";
|
|
2
3
|
import { safe } from "../../helpers/safe.js";
|
|
3
4
|
import { isEmptyServiceWorkerUrl } from "./empty-service-worker.js";
|
|
4
5
|
import { launchBrowser, resetBrowserState } from "./browser/launch-browser.js";
|
|
@@ -51,6 +52,9 @@ export class OnboardingService {
|
|
|
51
52
|
await this.attachExtensionBridge(browser);
|
|
52
53
|
const page = await this.preparePage(browser, shutdownSignal);
|
|
53
54
|
this.cli.successAction("ONBOARDING:PREPARE:BROWSER");
|
|
55
|
+
// Not awaited: the panel registers a moment after DevTools opens, and the
|
|
56
|
+
// run has no reason to wait for a convenience.
|
|
57
|
+
void this.showDevtoolsPanelOnStart(page);
|
|
54
58
|
await this.navigate(page, `${this.customerConfig.scope}speed-kit-install.html?url=${this.customerConfig.scope}`);
|
|
55
59
|
await waitForAbort(shutdownSignal);
|
|
56
60
|
await safe(browser.close());
|
|
@@ -87,6 +91,30 @@ export class OnboardingService {
|
|
|
87
91
|
* sk-cli. Without a loaded devtools extension there is nothing to attach
|
|
88
92
|
* to — ExtensionValidator already reported why — so it is skipped.
|
|
89
93
|
*/
|
|
94
|
+
/**
|
|
95
|
+
* Open the run's DevTools on the Speed Kit panel rather than on Elements.
|
|
96
|
+
*
|
|
97
|
+
* Headed only: that is where `devtools: true` opens a DevTools window for the
|
|
98
|
+
* tab, and where someone is looking at it. The selection reaches into
|
|
99
|
+
* DevTools' internals, so a failure is a warning and nothing more.
|
|
100
|
+
*/
|
|
101
|
+
async showDevtoolsPanelOnStart(page) {
|
|
102
|
+
const extensionId = this.extensionBridge.devtoolsExtensionId;
|
|
103
|
+
if (this.browserContext.headless || !extensionId) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const result = await safe(showDevtoolsPanel(page, extensionId).catch((error) => {
|
|
107
|
+
// Name the tabs DevTools did show, so a missing panel can be told
|
|
108
|
+
// from a renamed one.
|
|
109
|
+
if (!(error instanceof PanelNotFoundError))
|
|
110
|
+
throw error;
|
|
111
|
+
throw new Error(`${error.message} — DevTools shows ${error.tabs.join(", ") || "no tabs at all"}`);
|
|
112
|
+
}));
|
|
113
|
+
if (result.success === true) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.cli.writeWarning(`DevTools did not open on the Speed Kit panel: ${result.error}`);
|
|
117
|
+
}
|
|
90
118
|
async attachExtensionBridge(browser) {
|
|
91
119
|
if (!this.extensionBridge.isAvailable) {
|
|
92
120
|
return;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { PanelNotFoundError, showDevtoolsPanel, } from "../../../browser/extension/devtools-panel.js";
|
|
4
|
+
const ID = "gbiigacjibjkoldfdgjkomkddifgkeja";
|
|
5
|
+
const PANEL = `chrome-extension://${ID}Speed-Kit`;
|
|
6
|
+
const BUILT_IN = ["elements", "console", "network"];
|
|
7
|
+
/**
|
|
8
|
+
* A page whose DevTools frontend answers the selection script.
|
|
9
|
+
*
|
|
10
|
+
* `answers` is what DevTools shows on each successive poll: the extension's
|
|
11
|
+
* panel registers a moment after DevTools opens, so the first few polls can
|
|
12
|
+
* find nothing.
|
|
13
|
+
*/
|
|
14
|
+
function pageWith({ devtoolsOpen = true, answers, }) {
|
|
15
|
+
const expressions = [];
|
|
16
|
+
let poll = 0;
|
|
17
|
+
const devtools = {
|
|
18
|
+
evaluate: async (expression) => {
|
|
19
|
+
expressions.push(expression);
|
|
20
|
+
const tabs = answers[Math.min(poll++, answers.length - 1)];
|
|
21
|
+
const prefix = JSON.parse(expression.slice(expression.lastIndexOf("(") + 1, -1));
|
|
22
|
+
const selected = tabs.find((id) => id.startsWith(prefix)) ?? null;
|
|
23
|
+
return { tabs, selected };
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const page = {
|
|
27
|
+
hasDevTools: async () => devtoolsOpen,
|
|
28
|
+
openDevTools: async () => devtools,
|
|
29
|
+
};
|
|
30
|
+
return { page: page, expressions };
|
|
31
|
+
}
|
|
32
|
+
describe("showDevtoolsPanel", () => {
|
|
33
|
+
it("switches an open DevTools to the panel", async () => {
|
|
34
|
+
const { page } = pageWith({ answers: [[...BUILT_IN, PANEL]] });
|
|
35
|
+
const shown = await showDevtoolsPanel(page, ID);
|
|
36
|
+
expect(shown).to.deep.equal({ panel: PANEL, openedDevTools: false });
|
|
37
|
+
});
|
|
38
|
+
it("says when it opened DevTools rather than switching tabs", async () => {
|
|
39
|
+
const { page } = pageWith({
|
|
40
|
+
devtoolsOpen: false,
|
|
41
|
+
answers: [[...BUILT_IN, PANEL]],
|
|
42
|
+
});
|
|
43
|
+
const shown = await showDevtoolsPanel(page, ID);
|
|
44
|
+
expect(shown.openedDevTools).to.equal(true);
|
|
45
|
+
});
|
|
46
|
+
it("waits for the extension to register its panel", async () => {
|
|
47
|
+
const { page, expressions } = pageWith({
|
|
48
|
+
answers: [BUILT_IN, BUILT_IN, [...BUILT_IN, PANEL]],
|
|
49
|
+
});
|
|
50
|
+
const shown = await showDevtoolsPanel(page, ID);
|
|
51
|
+
expect(shown.panel).to.equal(PANEL);
|
|
52
|
+
expect(expressions).to.have.length(3);
|
|
53
|
+
});
|
|
54
|
+
it("waits for a DevTools window it just opened to initialise", async () => {
|
|
55
|
+
// Asked too early, the frontend has no settings yet and InspectorView
|
|
56
|
+
// throws — which is what a freshly opened window answers at first.
|
|
57
|
+
let polls = 0;
|
|
58
|
+
const starting = {
|
|
59
|
+
hasDevTools: async () => false,
|
|
60
|
+
openDevTools: async () => ({
|
|
61
|
+
evaluate: async () => {
|
|
62
|
+
if (polls++ < 2) {
|
|
63
|
+
throw new Error("Unable to create settings");
|
|
64
|
+
}
|
|
65
|
+
return { tabs: [PANEL], selected: PANEL };
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
const shown = await showDevtoolsPanel(starting, ID);
|
|
70
|
+
expect(shown).to.deep.equal({ panel: PANEL, openedDevTools: true });
|
|
71
|
+
});
|
|
72
|
+
it("reports internals it cannot use once the time is up", async () => {
|
|
73
|
+
const broken = {
|
|
74
|
+
hasDevTools: async () => true,
|
|
75
|
+
openDevTools: async () => ({
|
|
76
|
+
evaluate: async () => {
|
|
77
|
+
throw new Error("InspectorView is not defined");
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
};
|
|
81
|
+
let error;
|
|
82
|
+
await showDevtoolsPanel(broken, ID, 50).catch((e) => (error = e));
|
|
83
|
+
expect(error?.message).to.equal("InspectorView is not defined");
|
|
84
|
+
});
|
|
85
|
+
it("looks for this run's extension, not any extension's panel", async () => {
|
|
86
|
+
const other = "chrome-extension://abcdefghijklmnopabcdefghijklmnopReact";
|
|
87
|
+
const { page } = pageWith({ answers: [[...BUILT_IN, other, PANEL]] });
|
|
88
|
+
const shown = await showDevtoolsPanel(page, ID);
|
|
89
|
+
expect(shown.panel).to.equal(PANEL);
|
|
90
|
+
});
|
|
91
|
+
it("gives up with the tabs DevTools did show", async () => {
|
|
92
|
+
const { page } = pageWith({ answers: [BUILT_IN] });
|
|
93
|
+
let error;
|
|
94
|
+
await showDevtoolsPanel(page, ID, 50).catch((e) => (error = e));
|
|
95
|
+
expect(error).to.be.instanceOf(PanelNotFoundError);
|
|
96
|
+
expect(error.message).to.contain("did not appear");
|
|
97
|
+
expect(error.tabs).to.deep.equal(BUILT_IN);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|