@speedkit/cli 4.51.0-run-control.1 → 4.51.0-run-control.2
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/README.md +81 -29
- package/dist/build-info.json +3 -3
- package/dist/commands/diff.d.ts +1 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.js +14 -3
- package/dist/commands/onboarding/browser/emulate.d.ts +12 -0
- package/dist/commands/onboarding/browser/emulate.js +3 -0
- package/dist/commands/onboarding/browser/navigate.d.ts +8 -0
- package/dist/commands/onboarding/browser/navigate.js +2 -1
- package/dist/commands/onboarding/cache/prewarm.js +1 -1
- package/dist/commands/onboarding/debug/arm.d.ts +6 -0
- package/dist/commands/onboarding/debug/arm.js +2 -1
- package/dist/commands/onboarding/files/rebuild.d.ts +6 -6
- package/dist/commands/onboarding/logs.js +3 -2
- package/dist/commands/onboarding/status.js +2 -2
- package/dist/commands/onboarding/stop.d.ts +13 -0
- package/dist/commands/onboarding/stop.js +17 -0
- package/dist/commands/onboarding.d.ts +1 -1
- package/dist/commands/onboarding.js +1 -1
- package/dist/services/diff/diff-service-build-context.d.ts +4 -0
- package/dist/services/diff/diff-service-build-context.js +5 -0
- package/dist/services/diff/diff-service-factory.js +17 -5
- package/dist/services/diff/run-runtime-config.d.ts +33 -0
- package/dist/services/diff/run-runtime-config.js +74 -0
- package/dist/services/diff/spec/run-runtime-config.spec.d.ts +1 -0
- package/dist/services/diff/spec/run-runtime-config.spec.js +87 -0
- package/dist/services/onboarding/browse/browse-service.d.ts +13 -1
- package/dist/services/onboarding/browse/browse-service.js +40 -7
- package/dist/services/onboarding/browser/answer-dialogs.d.ts +12 -0
- package/dist/services/onboarding/browser/answer-dialogs.js +25 -0
- package/dist/services/onboarding/browser/emulate-device.d.ts +12 -1
- package/dist/services/onboarding/browser/emulate-device.js +33 -6
- package/dist/services/onboarding/browser/launch-browser.d.ts +2 -1
- package/dist/services/onboarding/browser/launch-browser.js +3 -1
- package/dist/services/onboarding/control/browser-session.d.ts +26 -12
- package/dist/services/onboarding/control/browser-session.js +118 -91
- package/dist/services/onboarding/control/control-protocol.d.ts +39 -1
- package/dist/services/onboarding/control/control-protocol.js +0 -11
- package/dist/services/onboarding/control/control-server.d.ts +8 -0
- package/dist/services/onboarding/control/control-server.js +22 -2
- package/dist/services/onboarding/control/debug-session.d.ts +30 -1
- package/dist/services/onboarding/control/debug-session.js +106 -10
- package/dist/services/onboarding/control/navigate-wait.d.ts +33 -0
- package/dist/services/onboarding/control/navigate-wait.js +56 -0
- package/dist/services/onboarding/control/service-worker-tracker.js +1 -0
- package/dist/services/onboarding/control/watch.js +9 -1
- package/dist/services/onboarding/fetch-event-handler.js +9 -0
- package/dist/services/onboarding/inject/inject-service.js +1 -1
- package/dist/services/onboarding/onboarding-model.js +2 -1
- package/dist/services/onboarding/onboarding-service-build-context.js +1 -1
- package/dist/services/onboarding/onboarding-service-factory.js +20 -7
- package/dist/services/onboarding/onboarding-service.js +1 -1
- package/dist/services/onboarding/spec/browser/answer-dialogs.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/browser/answer-dialogs.spec.js +66 -0
- package/dist/services/onboarding/spec/control/browser-session.spec.js +127 -2
- package/dist/services/onboarding/spec/control/control-server.spec.js +33 -0
- package/dist/services/onboarding/spec/control/debug-session.spec.js +58 -0
- package/dist/services/onboarding/spec/control/navigate-wait.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/control/navigate-wait.spec.js +47 -0
- package/dist/services/onboarding/spec/control/watch.spec.js +15 -0
- package/dist/services/onboarding/spec/fetch-event-handler.spec.js +17 -0
- package/dist/services/onboarding/spec/onboarding-model.spec.js +2 -3
- package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +24 -1
- package/dist/services/onboarding/spec/virtual-orestes-app/virtual-orestes-app.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/virtual-orestes-app/virtual-orestes-app.spec.js +65 -0
- package/dist/services/onboarding/virtual-orestes-app/index.d.ts +4 -0
- package/dist/services/onboarding/virtual-orestes-app/index.js +31 -0
- package/dist/services/origin-request/runtime-config-source.d.ts +6 -0
- package/dist/services/origin-request/runtime-config-source.js +6 -0
- package/dist/services/run-control/browser/run-browser-contexts.d.ts +16 -0
- package/dist/services/run-control/browser/run-browser-contexts.js +14 -1
- package/dist/services/run-control/browser/run-browser-service.d.ts +5 -1
- package/dist/services/run-control/browser/run-browser-service.js +16 -9
- package/dist/services/run-control/debug/run-debug-contexts.d.ts +5 -0
- package/dist/services/run-control/debug/run-debug-contexts.js +3 -0
- package/dist/services/run-control/debug/run-debug-service.d.ts +1 -0
- package/dist/services/run-control/debug/run-debug-service.js +3 -0
- package/dist/services/run-control/files/run-files-contexts.d.ts +5 -5
- package/dist/services/run-control/inject/run-inject-contexts.js +7 -1
- package/dist/services/run-control/inject/run-inject-service.d.ts +2 -2
- package/dist/services/run-control/inject/run-inject-service.js +32 -8
- package/dist/services/run-control/probe/run-probe-service.js +1 -0
- package/dist/services/run-control/session/run-session-service.d.ts +8 -1
- package/dist/services/run-control/session/run-session-service.js +58 -2
- package/dist/services/run-control/spec/cache/run-cache-service.spec.js +1 -1
- package/dist/services/run-control/spec/inject/run-inject-service.spec.js +27 -0
- package/dist/services/run-control/spec/session/run-session-service.spec.js +49 -0
- package/dist/services/run-log/request-log.d.ts +3 -1
- package/dist/services/run-registry/run-registry.d.ts +7 -2
- package/dist/services/run-registry/run-registry.js +26 -5
- package/dist/services/run-registry/spec/run-registry.spec.js +17 -0
- package/oclif.manifest.json +281 -181
- package/package.json +1 -1
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { DebugActionData, DebugAwaitData, DebugEvalData, DebugReleaseData, DebugStatusData, DebugStepKind, DebugThen, PageThreadState } from "./control-protocol.js";
|
|
2
2
|
import { PreloadRegistry } from "./preload-registry.js";
|
|
3
|
+
/**
|
|
4
|
+
* The four anchors, and what each one is for.
|
|
5
|
+
*
|
|
6
|
+
* Every one is a `performance.mark` Speed Kit emits, so a single wrapper covers
|
|
7
|
+
* the whole lifecycle — which is why this works with no source maps, no script
|
|
8
|
+
* ids and nothing to re-resolve when a build changes.
|
|
9
|
+
*/
|
|
10
|
+
export declare const BREAKPOINTS: {
|
|
11
|
+
bp: number;
|
|
12
|
+
mark: string;
|
|
13
|
+
description: string;
|
|
14
|
+
/**
|
|
15
|
+
* The devtools extension's sessionStorage key for this breakpoint.
|
|
16
|
+
*
|
|
17
|
+
* Mirrors `lib/breakpoint-flags.ts` in team-pi/devtools, which derives them
|
|
18
|
+
* from its own breakpoint table so a rename there cannot leave a stale copy
|
|
19
|
+
* here. A key this side gets wrong arms nothing, which is the safe direction.
|
|
20
|
+
*/
|
|
21
|
+
flagKey: string;
|
|
22
|
+
/** Anchors on the SSR pass; a document that was not pre-rendered has none. */
|
|
23
|
+
ssrOnly?: boolean;
|
|
24
|
+
}[];
|
|
3
25
|
/**
|
|
4
26
|
* What the debugger needs from the browser.
|
|
5
27
|
*
|
|
@@ -79,6 +101,8 @@ export declare class DebugSession {
|
|
|
79
101
|
private paused;
|
|
80
102
|
private lastPause;
|
|
81
103
|
private skipReason;
|
|
104
|
+
/** Armed with `--compared`: BP1 and BP3 sit on {@link COMPARED_MARKS}. */
|
|
105
|
+
private compared;
|
|
82
106
|
/**
|
|
83
107
|
* Breakpoints that have paused on the document loaded now.
|
|
84
108
|
*
|
|
@@ -111,7 +135,7 @@ export declare class DebugSession {
|
|
|
111
135
|
get isArmed(): boolean;
|
|
112
136
|
/** What is armed, for the report the devtools panel mirrors. */
|
|
113
137
|
get armedBreakpoints(): number[];
|
|
114
|
-
arm(bps: number[] | undefined, then?: DebugThen): Promise<DebugStatusData>;
|
|
138
|
+
arm(bps: number[] | undefined, then?: DebugThen, compared?: boolean): Promise<DebugStatusData>;
|
|
115
139
|
disarm(): Promise<DebugActionData>;
|
|
116
140
|
/**
|
|
117
141
|
* Get the page running, whoever stopped it, and keep it running.
|
|
@@ -185,6 +209,11 @@ export declare class DebugSession {
|
|
|
185
209
|
private probeDocument;
|
|
186
210
|
private subscribe;
|
|
187
211
|
private onPaused;
|
|
212
|
+
/**
|
|
213
|
+
* Fills `window.__skCD` at a `--compared` pause and says what it holds. BP1
|
|
214
|
+
* copies the sides from the calling frame; at BP3 the preload built them.
|
|
215
|
+
*/
|
|
216
|
+
private captureSides;
|
|
188
217
|
/** Read on the paused frame, because that is the only place the locals are. */
|
|
189
218
|
private readPausedState;
|
|
190
219
|
}
|
|
@@ -25,7 +25,7 @@ const SKIP_PREFIX = "__SK_DEBUG_CD_SKIPPED__";
|
|
|
25
25
|
* the whole lifecycle — which is why this works with no source maps, no script
|
|
26
26
|
* ids and nothing to re-resolve when a build changes.
|
|
27
27
|
*/
|
|
28
|
-
const BREAKPOINTS = [
|
|
28
|
+
export const BREAKPOINTS = [
|
|
29
29
|
{
|
|
30
30
|
bp: 1,
|
|
31
31
|
mark: "baqend-blocking-script-start",
|
|
@@ -53,6 +53,32 @@ const BREAKPOINTS = [
|
|
|
53
53
|
flagKey: "sk-devtools-bp4",
|
|
54
54
|
},
|
|
55
55
|
];
|
|
56
|
+
/**
|
|
57
|
+
* Where `arm --compared` pauses BP1 and BP3 instead: where each change-detection
|
|
58
|
+
* pass is about to compare, so both sides still exist. The regular pass marks
|
|
59
|
+
* `skChangeDetectionStart` from `contentChangeDetection(local, remote, rules)`.
|
|
60
|
+
*/
|
|
61
|
+
const COMPARED_MARKS = {
|
|
62
|
+
1: "skChangeDetectionStart",
|
|
63
|
+
3: "sk-prerender-change-detection-start",
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Run on BP1's calling frame, `contentChangeDetection(local, remote, rules)`.
|
|
67
|
+
* `arguments` survives minification. The per-block engine passes elements, not
|
|
68
|
+
* documents, and counts as legacy.
|
|
69
|
+
*/
|
|
70
|
+
const CAPTURE_REGULAR_SIDES = `(function () {
|
|
71
|
+
var a = arguments;
|
|
72
|
+
var isNode = function (x) { return x && (x.nodeType === 9 || x.nodeType === 1); };
|
|
73
|
+
window.__skCD = isNode(a[0]) && isNode(a[1])
|
|
74
|
+
? { local: a[0], remote: a[1], rules: a[2], pass: "regular", legacy: false }
|
|
75
|
+
: { local: null, remote: null, rules: null, pass: "regular", legacy: true };
|
|
76
|
+
}).apply(this, typeof arguments === "undefined" ? [] : arguments)`;
|
|
77
|
+
const SUMMARISE_SIDES = `window.__skCD
|
|
78
|
+
? { pass: window.__skCD.pass, legacy: window.__skCD.legacy,
|
|
79
|
+
rules: window.__skCD.rules ? window.__skCD.rules.length : 0,
|
|
80
|
+
containers: window.__skCD.containers ? window.__skCD.containers.length : undefined }
|
|
81
|
+
: { error: "no __skCD: the pass did not reach its comparison" }`;
|
|
56
82
|
export class NotPausedError extends Error {
|
|
57
83
|
code = "NOT_PAUSED";
|
|
58
84
|
}
|
|
@@ -93,6 +119,8 @@ export class DebugSession {
|
|
|
93
119
|
paused = false;
|
|
94
120
|
lastPause = null;
|
|
95
121
|
skipReason = null;
|
|
122
|
+
/** Armed with `--compared`: BP1 and BP3 sit on {@link COMPARED_MARKS}. */
|
|
123
|
+
compared = false;
|
|
96
124
|
/**
|
|
97
125
|
* Breakpoints that have paused on the document loaded now.
|
|
98
126
|
*
|
|
@@ -134,7 +162,7 @@ export class DebugSession {
|
|
|
134
162
|
get armedBreakpoints() {
|
|
135
163
|
return [...this.armed];
|
|
136
164
|
}
|
|
137
|
-
async arm(bps, then = "none") {
|
|
165
|
+
async arm(bps, then = "none", compared = false) {
|
|
138
166
|
const wanted = bps?.length ? bps : BREAKPOINTS.map(({ bp }) => bp);
|
|
139
167
|
const unknown = wanted.filter((bp) => !BREAKPOINTS.some((breakpoint) => breakpoint.bp === bp));
|
|
140
168
|
if (unknown.length > 0) {
|
|
@@ -155,7 +183,9 @@ export class DebugSession {
|
|
|
155
183
|
this.attached = true;
|
|
156
184
|
this.armed = [...new Set(wanted)].sort();
|
|
157
185
|
this.skipReason = null;
|
|
158
|
-
|
|
186
|
+
this.compared = compared;
|
|
187
|
+
// The extension pauses on its own marks only, so `--compared` takes the wrapper.
|
|
188
|
+
await this.preloads.reserve("debug", armingScript(this.armed, this.extensionArms() && !compared, release, compared));
|
|
159
189
|
if (then === "reload") {
|
|
160
190
|
// A navigation to the same url, not a reload. Speed Kit's worker treats a
|
|
161
191
|
// reload as the user asking for fresh content: it revalidates its Bloom
|
|
@@ -206,6 +236,7 @@ export class DebugSession {
|
|
|
206
236
|
// that says nothing is armed. Nothing reports after this one.
|
|
207
237
|
const had = this.armed;
|
|
208
238
|
this.armed = [];
|
|
239
|
+
this.compared = false;
|
|
209
240
|
await this.clearLiveDocument(had);
|
|
210
241
|
await this.preloads.release("debug");
|
|
211
242
|
if (this.attached) {
|
|
@@ -277,8 +308,10 @@ export class DebugSession {
|
|
|
277
308
|
};
|
|
278
309
|
}
|
|
279
310
|
async status() {
|
|
280
|
-
|
|
281
|
-
|
|
311
|
+
// In parallel: each read waits up to its CDP budget on a stuck page, and
|
|
312
|
+
// in sequence they outlasted the client's, which saw only CONTROL_TIMEOUT.
|
|
313
|
+
const [{ marks, prerendered, navigationType }, thread, pageArmed] = await Promise.all([
|
|
314
|
+
this.probeDocument(),
|
|
282
315
|
this.threadState(),
|
|
283
316
|
this.readPanelFlags(),
|
|
284
317
|
]);
|
|
@@ -328,8 +361,11 @@ export class DebugSession {
|
|
|
328
361
|
}
|
|
329
362
|
const startedAt = Date.now();
|
|
330
363
|
if (this.paused && this.lastPause) {
|
|
364
|
+
const status = await this.status();
|
|
331
365
|
return {
|
|
332
|
-
...
|
|
366
|
+
...status,
|
|
367
|
+
paused: status.paused === true,
|
|
368
|
+
pause: status.pause ?? null,
|
|
333
369
|
fired: true,
|
|
334
370
|
timedOut: false,
|
|
335
371
|
waitedMs: 0,
|
|
@@ -350,6 +386,9 @@ export class DebugSession {
|
|
|
350
386
|
const status = await this.status();
|
|
351
387
|
return {
|
|
352
388
|
...status,
|
|
389
|
+
// Always a boolean: a breakpoint list without one was read as paused.
|
|
390
|
+
paused: status.paused === true,
|
|
391
|
+
pause: status.pause ?? null,
|
|
353
392
|
fired: Boolean(pause),
|
|
354
393
|
timedOut: !pause,
|
|
355
394
|
waitedMs: Date.now() - startedAt,
|
|
@@ -582,6 +621,11 @@ export class DebugSession {
|
|
|
582
621
|
at: new Date().toISOString(),
|
|
583
622
|
};
|
|
584
623
|
pause.bp = pause.state.lastBp ?? "unknown";
|
|
624
|
+
if (this.compared && (pause.bp === "BP1" || pause.bp === "BP3")) {
|
|
625
|
+
pause.compared = await this.captureSides(pause.bp === "BP1"
|
|
626
|
+
? payload.callFrames?.[1]?.callFrameId
|
|
627
|
+
: top?.callFrameId, pause.bp === "BP1");
|
|
628
|
+
}
|
|
585
629
|
const number = Number(pause.bp.replace("BP", ""));
|
|
586
630
|
if (Number.isInteger(number)) {
|
|
587
631
|
this.firedThisDocument.add(number);
|
|
@@ -593,6 +637,27 @@ export class DebugSession {
|
|
|
593
637
|
settle(pause);
|
|
594
638
|
}
|
|
595
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Fills `window.__skCD` at a `--compared` pause and says what it holds. BP1
|
|
642
|
+
* copies the sides from the calling frame; at BP3 the preload built them.
|
|
643
|
+
*/
|
|
644
|
+
async captureSides(callFrameId, fromArguments) {
|
|
645
|
+
if (!callFrameId) {
|
|
646
|
+
return { error: "no calling frame to read the compared sides from" };
|
|
647
|
+
}
|
|
648
|
+
try {
|
|
649
|
+
const expression = fromArguments
|
|
650
|
+
? `${CAPTURE_REGULAR_SIDES}, (${SUMMARISE_SIDES})`
|
|
651
|
+
: `(${SUMMARISE_SIDES})`;
|
|
652
|
+
const result = await this.transport.send("Debugger.evaluateOnCallFrame", { callFrameId, expression, returnByValue: true });
|
|
653
|
+
return (result.result?.value ?? {
|
|
654
|
+
error: result.exceptionDetails?.text ?? "no value",
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
catch (error) {
|
|
658
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
659
|
+
}
|
|
660
|
+
}
|
|
596
661
|
/** Read on the paused frame, because that is the only place the locals are. */
|
|
597
662
|
async readPausedState(callFrameId) {
|
|
598
663
|
const expression = `JSON.stringify({
|
|
@@ -714,9 +779,9 @@ function names(breakpoints) {
|
|
|
714
779
|
* keeps an install guard of its own on top of the envelope's so the wrapper
|
|
715
780
|
* goes in exactly once per document however often the set is re-armed.
|
|
716
781
|
*/
|
|
717
|
-
function armingScript(armed, extensionArms, release) {
|
|
782
|
+
function armingScript(armed, extensionArms, release, compared = false) {
|
|
718
783
|
const marks = Object.fromEntries(BREAKPOINTS.filter(({ bp }) => armed.includes(bp)).map(({ bp, mark }) => [
|
|
719
|
-
mark,
|
|
784
|
+
(compared && COMPARED_MARKS[bp]) || mark,
|
|
720
785
|
bp,
|
|
721
786
|
]));
|
|
722
787
|
// Only the ones this run owns: those it is arming now, and those it armed
|
|
@@ -725,7 +790,8 @@ function armingScript(armed, extensionArms, release) {
|
|
|
725
790
|
// state change every guardrail here exists to prevent.
|
|
726
791
|
const flags = BREAKPOINTS.filter(({ bp }) => armed.includes(bp) || release.includes(bp))
|
|
727
792
|
.map(({ bp, flagKey }) => {
|
|
728
|
-
|
|
793
|
+
// Off under `--compared`, or the extension pauses a second time.
|
|
794
|
+
const on = !compared && armed.includes(bp);
|
|
729
795
|
return ` try { sessionStorage.${on ? `setItem(${JSON.stringify(flagKey)}, "on")` : `removeItem(${JSON.stringify(flagKey)})`}; } catch (ignored) {}`;
|
|
730
796
|
})
|
|
731
797
|
.join("\n");
|
|
@@ -766,12 +832,42 @@ ${flags}
|
|
|
766
832
|
window.__SK_DEBUG_INSTALLED = true;
|
|
767
833
|
window.__SK_DEBUG_LAST = null;
|
|
768
834
|
|
|
835
|
+
// Mirrors getPreRenderedPlaceholders() and getFilteredCd() in ssrClient.ts: the
|
|
836
|
+
// SSR pass compares each container's shadow root against the live document,
|
|
837
|
+
// with the rules that have no mode or mode "ssr".
|
|
838
|
+
function captureSsrSides() {
|
|
839
|
+
try {
|
|
840
|
+
var hosts = document.querySelectorAll(".speed-kit-shadow-app-root, sk-shadow-app-root");
|
|
841
|
+
var containers = [];
|
|
842
|
+
for (var i = 0; i < hosts.length; i++) {
|
|
843
|
+
containers.push({ host: hosts[i], local: hosts[i].shadowRoot || hosts[i].customShadowRoot || null });
|
|
844
|
+
}
|
|
845
|
+
var all = window.dynamicBlockConfig && window.dynamicBlockConfig.changeDetection;
|
|
846
|
+
var rules = Array.isArray(all)
|
|
847
|
+
? all.filter(function (rule) { return typeof rule.mode === "undefined" || rule.mode === "ssr"; })
|
|
848
|
+
: [];
|
|
849
|
+
window.__skCD = {
|
|
850
|
+
local: containers.length ? containers[0].local : null,
|
|
851
|
+
remote: document,
|
|
852
|
+
rules: rules,
|
|
853
|
+
pass: "ssr",
|
|
854
|
+
// Without rules the pass runs on the legacy preRenderedRootConfig.
|
|
855
|
+
legacy: rules.length === 0,
|
|
856
|
+
containers: containers
|
|
857
|
+
};
|
|
858
|
+
} catch (ignored) {}
|
|
859
|
+
}
|
|
860
|
+
|
|
769
861
|
if (typeof performance !== "undefined" && performance.mark) {
|
|
770
862
|
var original = performance.mark;
|
|
771
863
|
performance.mark = function (name) {
|
|
772
864
|
try {
|
|
773
865
|
var armed = window.__SK_DEBUG_ARMED || {};
|
|
774
|
-
|
|
866
|
+
// The SSR pass marks skChangeDetectionStart too; BP1 is the regular pass only.
|
|
867
|
+
var again = name === "${COMPARED_MARKS[1]}" && window.__SK_DEBUG_CD_SEEN;
|
|
868
|
+
if (name === "${COMPARED_MARKS[1]}") window.__SK_DEBUG_CD_SEEN = true;
|
|
869
|
+
if (name === "${COMPARED_MARKS[3]}" && armed[name]) captureSsrSides();
|
|
870
|
+
if (!again && Object.prototype.hasOwnProperty.call(armed, name)) {
|
|
775
871
|
window.__SK_DEBUG_LAST = "BP" + armed[name];
|
|
776
872
|
debugger;
|
|
777
873
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Where `browser navigate --wait` returns: the load event, or a Speed Kit lifecycle mark. */
|
|
2
|
+
export type NavigateWaitPoint = "load" | "bp1" | "bp2" | "bp3" | "bp4";
|
|
3
|
+
/** The marks of `/debug-lifecycle`, by the breakpoint that pauses before each. */
|
|
4
|
+
export declare const WAIT_MARKS: Record<Exclude<NavigateWaitPoint, "load">, string>;
|
|
5
|
+
/** The answer's `wait`: which point, and when it was reached or why not. */
|
|
6
|
+
export interface NavigateWaitData {
|
|
7
|
+
point: NavigateWaitPoint;
|
|
8
|
+
mark?: string;
|
|
9
|
+
reached: boolean;
|
|
10
|
+
/** The mark's time since the navigation started, as `performance.mark` has it. */
|
|
11
|
+
atMs?: number;
|
|
12
|
+
reason?: string;
|
|
13
|
+
}
|
|
14
|
+
/** What one look at the page saw. */
|
|
15
|
+
export interface WaitProbe {
|
|
16
|
+
/** The `startTime` of each wait mark present, by mark name. */
|
|
17
|
+
marks: Record<string, number>;
|
|
18
|
+
ssr: boolean;
|
|
19
|
+
readyState: string;
|
|
20
|
+
responseSource: string | null;
|
|
21
|
+
responseCause: string | null;
|
|
22
|
+
}
|
|
23
|
+
/** Reads a {@link WaitProbe}; plain `Runtime.evaluate`, never awaited by the page. */
|
|
24
|
+
export declare const WAIT_PROBE: string;
|
|
25
|
+
/** How long after the load event a mark of the merge may still land. */
|
|
26
|
+
export declare const AFTER_LOAD_GRACE_MS = 2000;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the wait is over: reached, or never going to be. Undefined means look again.
|
|
29
|
+
*
|
|
30
|
+
* Never waits for what cannot come: an SSR mark on a page without SSR, a merge mark after a
|
|
31
|
+
* load that had none. `sinceLoadMs` is how long the page has been complete, or undefined.
|
|
32
|
+
*/
|
|
33
|
+
export declare function decideWait(point: Exclude<NavigateWaitPoint, "load">, probe: WaitProbe, sinceLoadMs?: number): NavigateWaitData | undefined;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { BREAKPOINTS } from "./debug-session.js";
|
|
2
|
+
/** The marks of `/debug-lifecycle`, by the breakpoint that pauses before each. */
|
|
3
|
+
export const WAIT_MARKS = Object.fromEntries(BREAKPOINTS.map(({ bp, mark }) => [`bp${bp}`, mark]));
|
|
4
|
+
/** Reads a {@link WaitProbe}; plain `Runtime.evaluate`, never awaited by the page. */
|
|
5
|
+
export const WAIT_PROBE = `JSON.stringify((function () {
|
|
6
|
+
var marks = {};
|
|
7
|
+
${JSON.stringify(Object.values(WAIT_MARKS))}.forEach(function (name) {
|
|
8
|
+
var entry = performance.getEntriesByName(name, 'mark')[0];
|
|
9
|
+
if (entry) marks[name] = Math.round(entry.startTime);
|
|
10
|
+
});
|
|
11
|
+
var root = document.documentElement;
|
|
12
|
+
var last = window.SpeedKit && window.SpeedKit.lastNavigate;
|
|
13
|
+
return {
|
|
14
|
+
marks: marks,
|
|
15
|
+
ssr: Boolean(root && root.classList.contains('speed-kit-pre-rendered')),
|
|
16
|
+
readyState: document.readyState,
|
|
17
|
+
responseSource: last ? String(last.responseSource) : null,
|
|
18
|
+
responseCause: last ? String(last.responseCause) : null
|
|
19
|
+
};
|
|
20
|
+
})())`;
|
|
21
|
+
/** How long after the load event a mark of the merge may still land. */
|
|
22
|
+
export const AFTER_LOAD_GRACE_MS = 2000;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the wait is over: reached, or never going to be. Undefined means look again.
|
|
25
|
+
*
|
|
26
|
+
* Never waits for what cannot come: an SSR mark on a page without SSR, a merge mark after a
|
|
27
|
+
* load that had none. `sinceLoadMs` is how long the page has been complete, or undefined.
|
|
28
|
+
*/
|
|
29
|
+
export function decideWait(point, probe, sinceLoadMs) {
|
|
30
|
+
const mark = WAIT_MARKS[point];
|
|
31
|
+
if (probe.marks[mark] !== undefined) {
|
|
32
|
+
return { point, mark, reached: true, atMs: probe.marks[mark] };
|
|
33
|
+
}
|
|
34
|
+
const notReached = (reason) => ({
|
|
35
|
+
point,
|
|
36
|
+
mark,
|
|
37
|
+
reached: false,
|
|
38
|
+
reason: `not reached: ${reason}`,
|
|
39
|
+
});
|
|
40
|
+
const served = `responseSource ${probe.responseSource ?? "none"}, responseCause ${probe.responseCause ?? "none"}`;
|
|
41
|
+
if ((point === "bp3" || point === "bp4") && !probe.ssr) {
|
|
42
|
+
return notReached("no SSR on this page (speed-kit-pre-rendered is missing on <html>)");
|
|
43
|
+
}
|
|
44
|
+
if (point === "bp3" && probe.marks[WAIT_MARKS.bp4] !== undefined) {
|
|
45
|
+
return notReached("this load skipped the SSR comparison (`debug status` names the skip reason)");
|
|
46
|
+
}
|
|
47
|
+
// The SSR marks may land well after the load event; they wait for the timeout.
|
|
48
|
+
if ((point === "bp1" || point === "bp2") &&
|
|
49
|
+
sinceLoadMs !== undefined &&
|
|
50
|
+
sinceLoadMs >= AFTER_LOAD_GRACE_MS) {
|
|
51
|
+
return notReached(probe.marks[WAIT_MARKS.bp1] === undefined
|
|
52
|
+
? `Speed Kit did not run its merge on this load (${served})`
|
|
53
|
+
: `the page loaded without it (${served})`);
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const DEFAULT_INTERVAL_MS = 200;
|
|
2
|
+
/** The shortest tick the sampler takes; a shorter one is raised to it. */
|
|
3
|
+
const MIN_INTERVAL_MS = 20;
|
|
2
4
|
const DEFAULT_DURATION_MS = 15_000;
|
|
3
5
|
/** Long enough for a slow load to finish, short enough to be a tool call. */
|
|
4
6
|
const MAX_DURATION_MS = 120_000;
|
|
@@ -21,7 +23,12 @@ const MAX_RETURNED = 200;
|
|
|
21
23
|
* here.
|
|
22
24
|
*/
|
|
23
25
|
export async function runWatch(preloads, reload, options) {
|
|
24
|
-
const intervalMs = Math.max(
|
|
26
|
+
const intervalMs = Math.max(MIN_INTERVAL_MS, options.intervalMs ?? DEFAULT_INTERVAL_MS);
|
|
27
|
+
const notes = options.intervalMs !== undefined && options.intervalMs < intervalMs
|
|
28
|
+
? [
|
|
29
|
+
`interval ${options.intervalMs}ms raised to ${intervalMs}ms, the shortest the sampler takes`,
|
|
30
|
+
]
|
|
31
|
+
: [];
|
|
25
32
|
const durationMs = Math.min(MAX_DURATION_MS, Math.max(intervalMs, options.durationMs ?? DEFAULT_DURATION_MS));
|
|
26
33
|
await preloads.reserve("watch", watchScript(options.expression, intervalMs));
|
|
27
34
|
try {
|
|
@@ -58,6 +65,7 @@ export async function runWatch(preloads, reload, options) {
|
|
|
58
65
|
console: console.slice(0, MAX_RETURNED),
|
|
59
66
|
exceptions: exceptions.slice(0, MAX_RETURNED),
|
|
60
67
|
truncated: shown.length > MAX_RETURNED,
|
|
68
|
+
notes,
|
|
61
69
|
};
|
|
62
70
|
}
|
|
63
71
|
finally {
|
|
@@ -35,6 +35,15 @@ export class FetchEventHandler {
|
|
|
35
35
|
const failure = response.errorObj
|
|
36
36
|
? response.errorObj.message
|
|
37
37
|
: JSON.stringify(response.errorObj);
|
|
38
|
+
// The page dropped the request while a handler worked on it, e.g. a
|
|
39
|
+
// navigation away. Logged as an error, it read as a proxy failure.
|
|
40
|
+
if (/Invalid InterceptionId/.test(failure)) {
|
|
41
|
+
this.deps.requestLog?.record({
|
|
42
|
+
...this.describe(event),
|
|
43
|
+
outcome: "cancelled",
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
38
47
|
this.deps.requestLog?.record({
|
|
39
48
|
...this.describe(event),
|
|
40
49
|
outcome: "error",
|
|
@@ -31,7 +31,7 @@ export class InjectService {
|
|
|
31
31
|
externalSignal,
|
|
32
32
|
disconnected.signal,
|
|
33
33
|
]);
|
|
34
|
-
const browser = await launchBrowser(this.browserContext);
|
|
34
|
+
const browser = await launchBrowser(this.browserContext, this.cli);
|
|
35
35
|
for (const target of browser.targets()) {
|
|
36
36
|
if (target.type() === "browser") {
|
|
37
37
|
await this.fetchEventHandler.handleRequestFetchEvents(target);
|
|
@@ -230,7 +230,8 @@ export class BrowserContext {
|
|
|
230
230
|
/** Args that depend on how Chrome is launched, added after the customer's chromeFlags. */
|
|
231
231
|
getLaunchOnlyArgs() {
|
|
232
232
|
const args = [];
|
|
233
|
-
|
|
233
|
+
// Headless needs no port: run control goes through the CLI's own connection.
|
|
234
|
+
if (this.debuggingPort) {
|
|
234
235
|
args.push(`--remote-debugging-port=${this.debugPort}`);
|
|
235
236
|
// Puppeteer adds the pipe switch for `pipe: true` only when no other
|
|
236
237
|
// `--remote-debugging-*` switch is present, and it refuses
|
|
@@ -49,7 +49,7 @@ const flags = {
|
|
|
49
49
|
}),
|
|
50
50
|
debugPort: Flags.integer({
|
|
51
51
|
default: 9222,
|
|
52
|
-
description: "Chrome remote debugging port (only used with -p
|
|
52
|
+
description: "Chrome remote debugging port (only used with -p). Use distinct ports to run multiple onboarding processes with -p at once.",
|
|
53
53
|
}),
|
|
54
54
|
verboseLevel: Flags.boolean({
|
|
55
55
|
char: "v",
|
|
@@ -44,7 +44,7 @@ import { DevtoolsExtensionApi } from "./browser/extension/devtools-extension-api
|
|
|
44
44
|
import { ExtensionBridge } from "./browser/extension/extension-bridge.js";
|
|
45
45
|
import { TodoCollector } from "./todo-collector.js";
|
|
46
46
|
import { installBrowserOriginFetch } from "../browser-fetch/index.js";
|
|
47
|
-
import { OriginFetcher, RuntimeConfigSource } from "../origin-request/index.js";
|
|
47
|
+
import { NO_RUNTIME_CONFIG_WARNING, OriginFetcher, RuntimeConfigSource, } from "../origin-request/index.js";
|
|
48
48
|
import { VirtualOrestesApp } from "./virtual-orestes-app/index.js";
|
|
49
49
|
import { ConfigApiContext, ConfigApiServiceFactory, } from "../config-api/index.js";
|
|
50
50
|
import * as fs from "node:fs";
|
|
@@ -53,6 +53,7 @@ import { join } from "node:path";
|
|
|
53
53
|
import { mkdtempSync } from "node:fs";
|
|
54
54
|
import { tmpdir } from "node:os";
|
|
55
55
|
import { StaticRecipe } from "../integration-api/virtual/static-recipe.js";
|
|
56
|
+
import FileList from "../integration-api/file-list.js";
|
|
56
57
|
import { DiffAgainstCurrentPage } from "./dashboard/diff-against-current-page.js";
|
|
57
58
|
import { ExtensionDownloader } from "./browser/extension/extension-downloader.js";
|
|
58
59
|
import { ExecutableValidator } from "./browser/executable/executable-validator.js";
|
|
@@ -135,7 +136,18 @@ export class OnboardingServiceFactory {
|
|
|
135
136
|
applyOriginProxy(customerConfig?.chromeFlags, cli);
|
|
136
137
|
const url = resolveBrowseUrl(this.context.domain, customerConfig);
|
|
137
138
|
const { browserContext } = await this.prepareBrowser(url, customerConfig?.chromeFlags);
|
|
138
|
-
|
|
139
|
+
// Browse mode has no cache and no files; the ops that read them answer empty.
|
|
140
|
+
const session = new BrowserSession();
|
|
141
|
+
const controlServer = this.run
|
|
142
|
+
? new ControlServer(this.run.dir, this.run.id, {
|
|
143
|
+
cache: new Cache(cli, join(this.run.dir, "dh-cache")),
|
|
144
|
+
cli,
|
|
145
|
+
files: new FileList(),
|
|
146
|
+
session,
|
|
147
|
+
origin: browserContext.domain,
|
|
148
|
+
})
|
|
149
|
+
: undefined;
|
|
150
|
+
return new BrowseService(browserContext, cli, controlServer, session);
|
|
139
151
|
}
|
|
140
152
|
/**
|
|
141
153
|
* What inject mode injects, and where. The app and the domain come from the flags, else from a
|
|
@@ -217,7 +229,7 @@ export class OnboardingServiceFactory {
|
|
|
217
229
|
for (const finding of browserContext.findFeatureFindings()) {
|
|
218
230
|
cli.writeWarning(formatChromeFeatureFinding(finding));
|
|
219
231
|
}
|
|
220
|
-
if (this.context.debuggingPort
|
|
232
|
+
if (this.context.debuggingPort) {
|
|
221
233
|
cli.writeWarning(`Chrome remote debugging enabled on port ${this.context.debugPort}.`, false,
|
|
222
234
|
// Yellow on the terminal because it changes how Chrome behaves, but it
|
|
223
235
|
// is not a problem — and `--summary` lists every warning as one.
|
|
@@ -293,7 +305,7 @@ export class OnboardingServiceFactory {
|
|
|
293
305
|
const todos = new TodoCollector(files.getInstallResources());
|
|
294
306
|
const messageHandler = await this.prepareMessagehandler(athenaClient, files, customerConfig, todos);
|
|
295
307
|
const speedKitServiceWorkerJs = new SpeedKitServiceWorkerJs(customerConfig, files.getByName(INTEGRATION_FILES.CUSTOM.SW));
|
|
296
|
-
const { fetchHandler, orestesApp, rumPi } = await this.getFetchEventHandler(files, customerConfig, documentHandler, cache, cli, browserContext, athenaClient, messageHandler, fileWatcher, speedKitServiceWorkerJs);
|
|
308
|
+
const { fetchHandler, orestesApp, rumPi, runtimeConfig } = await this.getFetchEventHandler(files, customerConfig, documentHandler, cache, cli, browserContext, athenaClient, messageHandler, fileWatcher, speedKitServiceWorkerJs);
|
|
297
309
|
const extensionBridge = new ExtensionBridge(cli, browserExtensions.hasDevtoolsExtension);
|
|
298
310
|
// Constructed here so it holds the same Cache the run does, not a second
|
|
299
311
|
// one. Its lifetime is the run's: OnboardingService starts it against the
|
|
@@ -336,6 +348,8 @@ export class OnboardingServiceFactory {
|
|
|
336
348
|
// is after the page is ready.
|
|
337
349
|
rebuild: (target) => fileWatcher.rebuild(target),
|
|
338
350
|
validate: () => validateLoadedConfig(customerConfig, files),
|
|
351
|
+
// `sk diff` follows the run with the config it loaded, and refuses without one.
|
|
352
|
+
runtimeConfig: () => runtimeConfig,
|
|
339
353
|
// Evaluated per call, not captured: the config is the thing being
|
|
340
354
|
// edited, and explaining a url against the version loaded at startup
|
|
341
355
|
// would answer about a file the user has since changed.
|
|
@@ -424,9 +438,7 @@ export class OnboardingServiceFactory {
|
|
|
424
438
|
configApi,
|
|
425
439
|
}).load();
|
|
426
440
|
if (!runtimeConfig) {
|
|
427
|
-
|
|
428
|
-
// override of a device variation. Those still resolve, from their built-in defaults only.
|
|
429
|
-
cli.writeWarning("without the runtime config, origin fetches carry no basic auth, no custom variation and no configured override of default, mobile or tablet — those fall back to the built-in defaults.");
|
|
441
|
+
cli.writeWarning(NO_RUNTIME_CONFIG_WARNING);
|
|
430
442
|
}
|
|
431
443
|
const originFetcher = new OriginFetcher({ cli, config: runtimeConfig });
|
|
432
444
|
const parameterQueryBuilder = await new QueryBuilderFactory(new ParameterQueryServiceBuildContext({
|
|
@@ -465,6 +477,7 @@ export class OnboardingServiceFactory {
|
|
|
465
477
|
requestLog: this.requestLog,
|
|
466
478
|
}),
|
|
467
479
|
orestesApp,
|
|
480
|
+
runtimeConfig,
|
|
468
481
|
};
|
|
469
482
|
}
|
|
470
483
|
async getIntegrationFiles(cli) {
|
|
@@ -121,7 +121,7 @@ export class OnboardingService {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
async prepareBrowser(localController) {
|
|
124
|
-
const browser = await launchBrowser(this.browserContext);
|
|
124
|
+
const browser = await launchBrowser(this.browserContext, this.cli);
|
|
125
125
|
for (const target of browser.targets()) {
|
|
126
126
|
if (target.type() === "browser") {
|
|
127
127
|
await this.fetchEventHandler.handleRequestFetchEvents(target);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { describe, it } from "mocha";
|
|
4
|
+
import { answerDialogs } from "../../browser/answer-dialogs.js";
|
|
5
|
+
/** A dialog that records how it was answered. */
|
|
6
|
+
function dialog(type, answers) {
|
|
7
|
+
return {
|
|
8
|
+
type: () => type,
|
|
9
|
+
message: () => `${type} text`,
|
|
10
|
+
accept: async () => void answers.push(`${type}: accepted`),
|
|
11
|
+
dismiss: async () => void answers.push(`${type}: cancelled`),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const tick = () => new Promise((resolve) => setImmediate(resolve));
|
|
15
|
+
describe("answerDialogs", () => {
|
|
16
|
+
it("answers every dialog of open and later pages, and logs each", async () => {
|
|
17
|
+
const browser = new EventEmitter();
|
|
18
|
+
const page = Object.assign(new EventEmitter(), {
|
|
19
|
+
url: () => "https://shop.test/",
|
|
20
|
+
});
|
|
21
|
+
const later = Object.assign(new EventEmitter(), {
|
|
22
|
+
url: () => "https://shop.test/2",
|
|
23
|
+
});
|
|
24
|
+
browser.targets = () => [
|
|
25
|
+
{ page: async () => page },
|
|
26
|
+
{ page: async () => null },
|
|
27
|
+
];
|
|
28
|
+
const warnings = [];
|
|
29
|
+
const answers = [];
|
|
30
|
+
answerDialogs(browser, {
|
|
31
|
+
writeWarning: (text) => void warnings.push(text),
|
|
32
|
+
});
|
|
33
|
+
browser.emit("targetcreated", { page: async () => later });
|
|
34
|
+
await tick();
|
|
35
|
+
page.emit("dialog", dialog("alert", answers));
|
|
36
|
+
page.emit("dialog", dialog("confirm", answers));
|
|
37
|
+
later.emit("dialog", dialog("beforeunload", answers));
|
|
38
|
+
later.emit("dialog", dialog("prompt", answers));
|
|
39
|
+
await tick();
|
|
40
|
+
expect(answers).to.deep.equal([
|
|
41
|
+
"alert: accepted",
|
|
42
|
+
"confirm: cancelled",
|
|
43
|
+
"beforeunload: accepted",
|
|
44
|
+
"prompt: cancelled",
|
|
45
|
+
]);
|
|
46
|
+
expect(warnings).to.have.length(4);
|
|
47
|
+
expect(warnings[0]).to.contain('a dialog (alert: "alert text")');
|
|
48
|
+
});
|
|
49
|
+
it("stays quiet when a navigation already closed the dialog", async () => {
|
|
50
|
+
const browser = Object.assign(new EventEmitter(), {
|
|
51
|
+
targets: () => [],
|
|
52
|
+
});
|
|
53
|
+
const page = Object.assign(new EventEmitter(), {
|
|
54
|
+
url: () => "https://shop.test/",
|
|
55
|
+
});
|
|
56
|
+
answerDialogs(browser, { writeWarning: () => undefined });
|
|
57
|
+
browser.emit("targetcreated", { page: async () => page });
|
|
58
|
+
await tick();
|
|
59
|
+
const closed = {
|
|
60
|
+
...dialog("alert", []),
|
|
61
|
+
accept: () => Promise.reject(new Error("No dialog is showing")),
|
|
62
|
+
};
|
|
63
|
+
page.emit("dialog", closed);
|
|
64
|
+
await tick();
|
|
65
|
+
});
|
|
66
|
+
});
|