From c7c98ba034cda0067118e6c78e3ea7368ce4549b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Liu=20=E5=AE=9D=E7=8E=89?= Date: Wed, 1 Apr 2026 02:11:56 -0500 Subject: [PATCH] chore: sync vendor baoyu-chrome-cdp across CDP skills --- .../vendor/baoyu-chrome-cdp/src/index.ts | 33 ++++++++++++++++++- .../vendor/baoyu-chrome-cdp/src/index.ts | 33 ++++++++++++++++++- .../vendor/baoyu-chrome-cdp/src/index.ts | 33 ++++++++++++++++++- .../vendor/baoyu-chrome-cdp/src/index.ts | 33 ++++++++++++++++++- .../vendor/baoyu-chrome-cdp/src/index.ts | 33 ++++++++++++++++++- 5 files changed, 160 insertions(+), 5 deletions(-) diff --git a/skills/baoyu-danger-gemini-web/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-danger-gemini-web/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 0be48c3..3d189b1 100644 --- a/skills/baoyu-danger-gemini-web/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-danger-gemini-web/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -478,7 +478,7 @@ export function killChrome(chrome: ChildProcess): void { chrome.kill("SIGTERM"); } catch {} setTimeout(() => { - if (!chrome.killed) { + if (chrome.exitCode === null && chrome.signalCode === null) { try { chrome.kill("SIGKILL"); } catch {} @@ -486,6 +486,37 @@ export function killChrome(chrome: ChildProcess): void { }, 2_000).unref?.(); } +export async function gracefulKillChrome( + chrome: ChildProcess, + port?: number, + timeoutMs = 6_000, +): Promise { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + + const exitPromise = new Promise((resolve) => { + chrome.once("exit", () => resolve()); + }); + + killChrome(chrome); + + const start = Date.now(); + while (Date.now() - start < timeoutMs) { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + if (port !== undefined && !await isPortListening(port, 250)) return; + + const exited = await Promise.race([ + exitPromise.then(() => true), + sleep(100).then(() => false), + ]); + if (exited) return; + } + + await Promise.race([ + exitPromise, + sleep(250), + ]); +} + export async function openPageSession(options: OpenPageSessionOptions): Promise { let targetId: string; let createdTarget = false; diff --git a/skills/baoyu-danger-x-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-danger-x-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 0be48c3..3d189b1 100644 --- a/skills/baoyu-danger-x-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-danger-x-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -478,7 +478,7 @@ export function killChrome(chrome: ChildProcess): void { chrome.kill("SIGTERM"); } catch {} setTimeout(() => { - if (!chrome.killed) { + if (chrome.exitCode === null && chrome.signalCode === null) { try { chrome.kill("SIGKILL"); } catch {} @@ -486,6 +486,37 @@ export function killChrome(chrome: ChildProcess): void { }, 2_000).unref?.(); } +export async function gracefulKillChrome( + chrome: ChildProcess, + port?: number, + timeoutMs = 6_000, +): Promise { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + + const exitPromise = new Promise((resolve) => { + chrome.once("exit", () => resolve()); + }); + + killChrome(chrome); + + const start = Date.now(); + while (Date.now() - start < timeoutMs) { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + if (port !== undefined && !await isPortListening(port, 250)) return; + + const exited = await Promise.race([ + exitPromise.then(() => true), + sleep(100).then(() => false), + ]); + if (exited) return; + } + + await Promise.race([ + exitPromise, + sleep(250), + ]); +} + export async function openPageSession(options: OpenPageSessionOptions): Promise { let targetId: string; let createdTarget = false; diff --git a/skills/baoyu-post-to-wechat/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-post-to-wechat/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 0be48c3..3d189b1 100644 --- a/skills/baoyu-post-to-wechat/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-post-to-wechat/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -478,7 +478,7 @@ export function killChrome(chrome: ChildProcess): void { chrome.kill("SIGTERM"); } catch {} setTimeout(() => { - if (!chrome.killed) { + if (chrome.exitCode === null && chrome.signalCode === null) { try { chrome.kill("SIGKILL"); } catch {} @@ -486,6 +486,37 @@ export function killChrome(chrome: ChildProcess): void { }, 2_000).unref?.(); } +export async function gracefulKillChrome( + chrome: ChildProcess, + port?: number, + timeoutMs = 6_000, +): Promise { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + + const exitPromise = new Promise((resolve) => { + chrome.once("exit", () => resolve()); + }); + + killChrome(chrome); + + const start = Date.now(); + while (Date.now() - start < timeoutMs) { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + if (port !== undefined && !await isPortListening(port, 250)) return; + + const exited = await Promise.race([ + exitPromise.then(() => true), + sleep(100).then(() => false), + ]); + if (exited) return; + } + + await Promise.race([ + exitPromise, + sleep(250), + ]); +} + export async function openPageSession(options: OpenPageSessionOptions): Promise { let targetId: string; let createdTarget = false; diff --git a/skills/baoyu-post-to-weibo/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-post-to-weibo/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 0be48c3..3d189b1 100644 --- a/skills/baoyu-post-to-weibo/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-post-to-weibo/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -478,7 +478,7 @@ export function killChrome(chrome: ChildProcess): void { chrome.kill("SIGTERM"); } catch {} setTimeout(() => { - if (!chrome.killed) { + if (chrome.exitCode === null && chrome.signalCode === null) { try { chrome.kill("SIGKILL"); } catch {} @@ -486,6 +486,37 @@ export function killChrome(chrome: ChildProcess): void { }, 2_000).unref?.(); } +export async function gracefulKillChrome( + chrome: ChildProcess, + port?: number, + timeoutMs = 6_000, +): Promise { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + + const exitPromise = new Promise((resolve) => { + chrome.once("exit", () => resolve()); + }); + + killChrome(chrome); + + const start = Date.now(); + while (Date.now() - start < timeoutMs) { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + if (port !== undefined && !await isPortListening(port, 250)) return; + + const exited = await Promise.race([ + exitPromise.then(() => true), + sleep(100).then(() => false), + ]); + if (exited) return; + } + + await Promise.race([ + exitPromise, + sleep(250), + ]); +} + export async function openPageSession(options: OpenPageSessionOptions): Promise { let targetId: string; let createdTarget = false; diff --git a/skills/baoyu-post-to-x/scripts/vendor/baoyu-chrome-cdp/src/index.ts b/skills/baoyu-post-to-x/scripts/vendor/baoyu-chrome-cdp/src/index.ts index 0be48c3..3d189b1 100644 --- a/skills/baoyu-post-to-x/scripts/vendor/baoyu-chrome-cdp/src/index.ts +++ b/skills/baoyu-post-to-x/scripts/vendor/baoyu-chrome-cdp/src/index.ts @@ -478,7 +478,7 @@ export function killChrome(chrome: ChildProcess): void { chrome.kill("SIGTERM"); } catch {} setTimeout(() => { - if (!chrome.killed) { + if (chrome.exitCode === null && chrome.signalCode === null) { try { chrome.kill("SIGKILL"); } catch {} @@ -486,6 +486,37 @@ export function killChrome(chrome: ChildProcess): void { }, 2_000).unref?.(); } +export async function gracefulKillChrome( + chrome: ChildProcess, + port?: number, + timeoutMs = 6_000, +): Promise { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + + const exitPromise = new Promise((resolve) => { + chrome.once("exit", () => resolve()); + }); + + killChrome(chrome); + + const start = Date.now(); + while (Date.now() - start < timeoutMs) { + if (chrome.exitCode !== null || chrome.signalCode !== null) return; + if (port !== undefined && !await isPortListening(port, 250)) return; + + const exited = await Promise.race([ + exitPromise.then(() => true), + sleep(100).then(() => false), + ]); + if (exited) return; + } + + await Promise.race([ + exitPromise, + sleep(250), + ]); +} + export async function openPageSession(options: OpenPageSessionOptions): Promise { let targetId: string; let createdTarget = false;