@speedkit/cli 4.51.0-run-control.2 → 4.51.0-run-control.3
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/dist/build-info.json +3 -3
- package/dist/services/onboarding/browser/launch-browser.js +3 -0
- package/dist/services/onboarding/browser/resume-restarted-workers.d.ts +14 -0
- package/dist/services/onboarding/browser/resume-restarted-workers.js +26 -0
- package/dist/services/onboarding/spec/browser/resume-restarted-workers.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/browser/resume-restarted-workers.spec.js +45 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/dist/build-info.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import puppeteerExtra from "puppeteer-extra";
|
|
2
2
|
import { emulateDevice } from "./emulate-device.js";
|
|
3
3
|
import { answerDialogs } from "./answer-dialogs.js";
|
|
4
|
+
import { resumeRestartedWorkers } from "./resume-restarted-workers.js";
|
|
4
5
|
/** Launches the onboarding Chrome. Onboarding and browse mode share it, so their hardening cannot drift. */
|
|
5
6
|
export async function launchBrowser(browserContext, cli) {
|
|
6
7
|
const browser = await puppeteerExtra.default.launch(browserContext.getPuppeteerLaunchOptions());
|
|
8
|
+
// First, so that it covers the sessions the emulation opens.
|
|
9
|
+
await resumeRestartedWorkers(browser);
|
|
7
10
|
if (browserContext.emulation) {
|
|
8
11
|
await emulateDevice(browser, browserContext);
|
|
9
12
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Browser } from "puppeteer";
|
|
2
|
+
/**
|
|
3
|
+
* Lets a target run again when Chrome restarts it, on every CDP session the run opens on `browser`.
|
|
4
|
+
*
|
|
5
|
+
* Chrome stops a service worker and starts it again under the same target. While a session is
|
|
6
|
+
* attached, Chrome holds the restarted worker at its first line and tells only the attached
|
|
7
|
+
* sessions, with `Inspector.targetReloadedAfterCrash`. The run keeps sessions on its workers for
|
|
8
|
+
* the device emulation, so nobody resumed it. An activating worker then stayed `starting`, every
|
|
9
|
+
* navigation in its scope waited for it, and every tool answered CDP_TIMEOUT until an outside
|
|
10
|
+
* client attached and resumed the worker.
|
|
11
|
+
*
|
|
12
|
+
* `Runtime.runIfWaitingForDebugger` does nothing on a target that does not wait.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resumeRestartedWorkers(browser: Pick<Browser, "target">): Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CDPSessionEvent } from "puppeteer";
|
|
2
|
+
/**
|
|
3
|
+
* Lets a target run again when Chrome restarts it, on every CDP session the run opens on `browser`.
|
|
4
|
+
*
|
|
5
|
+
* Chrome stops a service worker and starts it again under the same target. While a session is
|
|
6
|
+
* attached, Chrome holds the restarted worker at its first line and tells only the attached
|
|
7
|
+
* sessions, with `Inspector.targetReloadedAfterCrash`. The run keeps sessions on its workers for
|
|
8
|
+
* the device emulation, so nobody resumed it. An activating worker then stayed `starting`, every
|
|
9
|
+
* navigation in its scope waited for it, and every tool answered CDP_TIMEOUT until an outside
|
|
10
|
+
* client attached and resumed the worker.
|
|
11
|
+
*
|
|
12
|
+
* `Runtime.runIfWaitingForDebugger` does nothing on a target that does not wait.
|
|
13
|
+
*/
|
|
14
|
+
export async function resumeRestartedWorkers(browser) {
|
|
15
|
+
const root = await browser.target().createCDPSession();
|
|
16
|
+
root
|
|
17
|
+
.connection()
|
|
18
|
+
?.on(CDPSessionEvent.SessionAttached, (session) => {
|
|
19
|
+
session.on("Inspector.targetReloadedAfterCrash", () => {
|
|
20
|
+
void session
|
|
21
|
+
.send("Runtime.runIfWaitingForDebugger")
|
|
22
|
+
.catch(() => undefined);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
await root.detach();
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { describe, it } from "mocha";
|
|
4
|
+
import { CDPSessionEvent } from "puppeteer";
|
|
5
|
+
import { resumeRestartedWorkers } from "../../browser/resume-restarted-workers.js";
|
|
6
|
+
/** A CDP session that records what it sends. */
|
|
7
|
+
function session(sent, answer) {
|
|
8
|
+
return Object.assign(new EventEmitter(), {
|
|
9
|
+
send: (method) => {
|
|
10
|
+
sent.push(method);
|
|
11
|
+
return answer();
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const tick = () => new Promise((resolve) => setImmediate(resolve));
|
|
16
|
+
describe("resumeRestartedWorkers", () => {
|
|
17
|
+
it("resumes a target that Chrome restarted, on every later session", async () => {
|
|
18
|
+
const connection = new EventEmitter();
|
|
19
|
+
let detached = false;
|
|
20
|
+
const browser = {
|
|
21
|
+
target: () => ({
|
|
22
|
+
createCDPSession: async () => ({
|
|
23
|
+
connection: () => connection,
|
|
24
|
+
detach: async () => void (detached = true),
|
|
25
|
+
}),
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
await resumeRestartedWorkers(browser);
|
|
29
|
+
expect(detached).to.equal(true);
|
|
30
|
+
const sent = [];
|
|
31
|
+
const worker = session(sent, async () => ({}));
|
|
32
|
+
const gone = session(sent, () => Promise.reject(new Error("detached")));
|
|
33
|
+
connection.emit(CDPSessionEvent.SessionAttached, worker);
|
|
34
|
+
connection.emit(CDPSessionEvent.SessionAttached, gone);
|
|
35
|
+
worker.emit("Inspector.workerScriptLoaded");
|
|
36
|
+
expect(sent).to.deep.equal([]);
|
|
37
|
+
worker.emit("Inspector.targetReloadedAfterCrash");
|
|
38
|
+
gone.emit("Inspector.targetReloadedAfterCrash");
|
|
39
|
+
await tick();
|
|
40
|
+
expect(sent).to.deep.equal([
|
|
41
|
+
"Runtime.runIfWaitingForDebugger",
|
|
42
|
+
"Runtime.runIfWaitingForDebugger",
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
});
|
package/oclif.manifest.json
CHANGED