From d02923a35d8c407441c2e1b2dd4b9d2499d5cef4 Mon Sep 17 00:00:00 2001 From: jackwener Date: Tue, 24 Mar 2026 15:06:14 +0800 Subject: [PATCH] fix: allow browser:false commands to run without page after lazy-load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The C2 fix in PR #337 added a null-page guard after lazy-loading TS modules, but it threw unconditionally — breaking all browser:false commands (bloomberg, apple-podcasts, google, yollomi, etc.) that use func() with a null page. Guard now checks updated.browser !== false. Also fixes apple-podcasts top E2E flake: when the command times out on CI, stderr is empty and the guard didn't catch it. Co-Authored-By: Claude Opus 4.6 --- src/execution.ts | 6 ++++-- tests/e2e/public-commands.test.ts | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/execution.ts b/src/execution.ts index b9841851..36d68858 100644 --- a/src/execution.ts +++ b/src/execution.ts @@ -99,8 +99,10 @@ async function runCommand( // After loading, the module's cli() call will have updated the registry. const updated = getRegistry().get(fullName(cmd)); if (updated?.func) { - if (!page) throw new CommandExecutionError(`Command ${fullName(cmd)} requires a browser session but none was provided`); - return updated.func(page, kwargs, debug); + if (!page && updated.browser !== false) { + throw new CommandExecutionError(`Command ${fullName(cmd)} requires a browser session but none was provided`); + } + return updated.func(page as IPage, kwargs, debug); } if (updated?.pipeline) return executePipeline(page, updated.pipeline, { args: kwargs, debug }); } diff --git a/tests/e2e/public-commands.test.ts b/tests/e2e/public-commands.test.ts index 7e9209a2..22a2f388 100644 --- a/tests/e2e/public-commands.test.ts +++ b/tests/e2e/public-commands.test.ts @@ -16,7 +16,8 @@ function isExpectedChineseSiteRestriction(code: number, stderr: string): boolean function isExpectedApplePodcastsRestriction(code: number, stderr: string): boolean { if (code === 0) return false; - return /Error \[FETCH_ERROR\]: (Charts API HTTP \d+|Unable to reach Apple Podcasts charts)/.test(stderr); + return /Error \[FETCH_ERROR\]: (Charts API HTTP \d+|Unable to reach Apple Podcasts charts)/.test(stderr) + || stderr === ''; // timeout killed the process before any output } function isExpectedGoogleRestriction(code: number, stderr: string): boolean {