@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.
@@ -1,6 +1,6 @@
1
1
  {
2
- "commit": "80b1d5b9",
2
+ "commit": "2279a78f",
3
3
  "dirty": true,
4
- "buildId": "7e85f8396e96",
5
- "builtAt": "2026-11-08T15:50:40.748Z"
4
+ "buildId": "50473481d0e3",
5
+ "builtAt": "2026-11-08T16:53:50.621Z"
6
6
  }
@@ -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,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
+ });
@@ -5234,5 +5234,5 @@
5234
5234
  ]
5235
5235
  }
5236
5236
  },
5237
- "version": "4.51.0-run-control.2"
5237
+ "version": "4.51.0-run-control.3"
5238
5238
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "4.51.0-run-control.2",
4
+ "version": "4.51.0-run-control.3",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"