`screenshot` writes PNG bytes into a `.jpg` file and JPEG bytes into a `.png` file
Summary
The output path extension is used only to decide whether an argument is a path or a selector; the encoder comes from --screenshot-format alone. A .jpg path with no flag therefore receives PNG bytes, and a .png path with --screenshot-format jpeg receives JPEG bytes. Both exit 0 with no warning.
Severity
High.
Affected version
Found on agent-browser 0.37.1 (shipped npm binary, real Chrome on Linux). The code path is unchanged in v0.38.0 / cd063d1.
Steps to reproduce
agent-browser open https://example.com
agent-browser screenshot /root/v.jpg
echo "exit=$?"
file -b /root/v.jpg
agent-browser screenshot /root/v.png --screenshot-format jpeg
echo "exit=$?"
file -b /root/v.pngActual behaviour
Both commands exit 0 and print no warning. file -b /root/v.jpg reports PNG image data, 1280 x 577. file -b /root/v.png reports JPEG image data.
Expected behaviour
The bytes should match the extension. A .jpg or .jpeg path should select the JPEG encoder, a .png path should select PNG, and a --screenshot-format that contradicts the extension should either be overridden with a warning or be rejected, rather than silently producing a mislabelled file.
Root cause
cli/src/commands.rs:882, in the screenshot arm of parse_command_inner.
A few lines earlier, at cli/src/commands.rs:864, has_path_extension checks for .png, .jpg, .jpeg and .webp, but that value feeds only the is_path decision that separates a path argument from a CSS selector. The extension is then discarded. The command payload gets format only from if let Some(ref fmt) = flags.screenshot_format, so with no flag the daemon falls back to its PNG default regardless of the file name, and with a conflicting flag the flag wins. The --screenshot-quality warning at cli/src/commands.rs:887 compares against the flag for the same reason, so a .jpg path plus --screenshot-quality warns that quality is ignored while also writing PNG. Nothing anywhere compares the chosen encoder with the extension.
Impact
An AI agent that picks .jpg to keep an image small, or to satisfy a downstream tool that only accepts JPEG, gets exit 0 and a file that lies about its contents. The agent has a false success signal: the capture "worked", so it moves on, and the breakage surfaces later in whatever consumes the file, usually as a decode error far from the command that caused it. Agents deliberately choosing JPEG to reduce token cost instead pay for a full-size PNG without ever being told.
Source: vercel-labs/agent-browser