Skip to content

Chrome DevTools for coding agents

fix: reject non-positive --viewport dimensions (#2781)

kevin0ef528a52f2e
diff --git a/src/config/puppeteer-options.ts b/src/config/puppeteer-options.ts
index cf6891de..4edddcff 100644
--- a/src/config/puppeteer-options.ts
+++ b/src/config/puppeteer-options.ts
@@ -21,8 +21,15 @@ export const puppeteerOptions = {
return;
}
const [width, height] = arg.split('x').map(Number);
- if (!width || !height || Number.isNaN(width) || Number.isNaN(height)) {
- throw new Error('Invalid viewport. Expected format is `1280x720`.');
+ if (
+ !Number.isInteger(width) ||
+ !Number.isInteger(height) ||
+ width <= 0 ||
+ height <= 0
+ ) {
+ throw new Error(
+ 'Invalid viewport. Expected format is `1280x720` with positive integer width and height.',
+ );
}
return {
width,
diff --git a/tests/cli.test.ts b/tests/cli.test.ts
index 656bc113..1e112142 100644
--- a/tests/cli.test.ts
+++ b/tests/cli.test.ts
@@ -17,6 +17,7 @@ import {
import {buildCommand} from '../src/config/cli-commands.js';
import {commands} from '../src/config/cli-options.js';
import {computeFlagUsage} from '../src/telemetry/flagUtils.js';
+import {puppeteerOptions} from '../src/config/puppeteer-options.js';
import {createTempFile} from './utils.js';
@@ -151,6 +152,29 @@ describe('cli args parsing', () => {
});
});
+ it('rejects non-positive viewport dimensions', async () => {
+ const coerce = puppeteerOptions.viewport.coerce;
+ assert.ok(coerce);
+
+ assert.strictEqual(coerce(undefined), undefined);
+
+ for (const value of [
+ '800x-1',
+ '-100x800',
+ '800x0',
+ '0x800',
+ 'Infinityx600',
+ '800xInfinity',
+ '1280.5x720',
+ '1280x720.5',
+ ]) {
+ assert.throws(
+ () => coerce(value),
+ /Invalid viewport\. Expected format is `1280x720` with positive integer width and height\./,
+ );
+ }
+ });
+
it('parses chrome args', async () => {
const args = parseConfig([
`--chrome-arg='--no-sandbox'`,