HtmlScreenshot: honour OFFICECLI_BROWSER as an explicit chrome-family executable - #318
HtmlScreenshot: honour OFFICECLI_BROWSER as an explicit chrome-family executable#318hesong12 wants to merge 1 commit into
Conversation
Hosts that ship their own Chromium build outside the standard PATH names / platform install locations (for example a Chrome for Testing binary staged under an app-support directory) have no way to point FindChrome() at it. Read OFFICECLI_BROWSER first, before the PATH and absolute-path fallbacks, when it names an existing file.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bfb9829152
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| var explicitBrowser = Environment.GetEnvironmentVariable("OFFICECLI_BROWSER"); | ||
| if (!string.IsNullOrWhiteSpace(explicitBrowser) && File.Exists(explicitBrowser)) | ||
| return explicitBrowser; |
There was a problem hiding this comment.
Prefer the explicit browser before Playwright
For view ... screenshot on a host with a working playwright CLI, this override is never honored: Capture() iterates Backends(), which tries Playwright before TryChrome, and returns immediately when Playwright succeeds. Consequently, operators cannot force the pinned Chrome-for-Testing executable described in the README whenever Playwright is installed; a valid OFFICECLI_BROWSER should make the Chrome backend run before automatic backend discovery while preserving the existing order when the variable is unset.
Useful? React with 👍 / 👎.
Files:
src/officecli/Core/HtmlScreenshot.cs(FindChrome()),README.mdSummary
FindChrome()only ever looks for a chrome-family binary by PATH name(
google-chrome,chrome,msedge, …) or a fixed set of platform-standardinstall paths (
/Applications/Google Chrome.app, …). A host that ships itsown Chromium build outside those locations — for example a pinned
"Chrome for Testing" binary staged under an application-support directory —
has no way to point OfficeCLI at it, and screenshot/mermaid rendering fails
with
no_screenshot_backendeven though a perfectly good browser is sittingright there.
This PR adds one explicit override, checked first:
OFFICECLI_BROWSER. Whenset to a path that exists,
FindChrome()returns it immediately, before thePATH and absolute-path fallbacks. When unset (or pointing at a nonexistent
file), behaviour is byte-for-byte unchanged.
One README line documents it next to the existing description of the
headless-screenshot rendering path.
Why
Product-side rationale for the host that needed this: a desktop app ships
its own pinned Chrome for Testing binary for its browser-automation feature
and wants OfficeCLI's screenshot/mermaid rendering to reuse that exact
binary instead of requiring a second, separately-installed system Chrome.
OFFICECLI_BROWSERis the minimal, additive way to do that — no newdependency, no behavior change for anyone who doesn't set it.
Validation
Toolchain: .NET 10 SDK installed to a scratch directory (
dotnet-install.sh --channel 10.0), never touching the system SDK.dotnet build src/officecli -c Debugsucceeds on the pristine clone and on this branch.Command sequence, run on macOS with a real Chrome for Testing binary at a
non-standard path and the platform-standard Chrome/Chromium/Edge locations
made unreadable for the duration of the test (
sandbox-execdenyingfile-read*on/Applications/Google Chrome.app,Chromium.app,Microsoft Edge.app— i.e. "no browser at a standard location", the exactcondition
OFFICECLI_BROWSERexists to solve):$CFT_PATH=.../chrome-149.0.7827.22/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing.Result PNG: 1600×1200, 8-bit RGB, 9296 bytes — see attached
U1-screenshot.png.Confirmed the override truly changed behavior (not just "a browser happened
to be found"): the identical command against the unmodified
mainbranch, with the exact same env var set and the exact same browsers hidden,
still fails with
no_screenshot_backend— provingFindChrome()does notread
OFFICECLI_BROWSERbefore this change, and does after.Compatibility
Additive only.
FindChrome()'s existing PATH-name and absolute-path searchis untouched and still runs whenever
OFFICECLI_BROWSERis unset.