Skip to content

Commit 357db65

Browse files
authored
fix: change default screen size in headless (#299)
Sets the screen size in headless to be 3840x2160px to allow resize tool to work correctly for most use cases. Closes #294
1 parent 098a904 commit 357db65

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ The Chrome DevTools MCP server supports the following configuration option:
280280
- **Type:** string
281281

282282
- **`--viewport`**
283-
Initial viewport size for the Chrome instances started by the server. For example, `1280x720`
283+
Initial viewport size for the Chrome instances started by the server. For example, `1280x720`. In headless mode, max size is 3840x2160px.
284284
- **Type:** string
285285

286286
- **`--proxyServer`**

src/browser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
9999
if (customDevTools) {
100100
args.push(`--custom-devtools-frontend=file://${customDevTools}`);
101101
}
102+
if (headless) {
103+
args.push('--screen-info={3840x2160}');
104+
}
102105
let puppeteerChannel: ChromeReleaseChannel | undefined;
103106
if (!executablePath) {
104107
puppeteerChannel =

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const cliOptions = {
6565
viewport: {
6666
type: 'string',
6767
describe:
68-
'Initial viewport size for the Chrome instances started by the server. For example, `1280x720`',
68+
'Initial viewport size for the Chrome instances started by the server. For example, `1280x720`. In headless mode, max size is 3840x2160px.',
6969
coerce: (arg: string | undefined) => {
7070
if (arg === undefined) {
7171
return;

tests/browser.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ describe('browser', () => {
5252
userDataDir: folderPath,
5353
executablePath: executablePath(),
5454
viewport: {
55-
width: 700,
56-
height: 500,
55+
width: 1501,
56+
height: 801,
5757
},
5858
});
5959
try {
@@ -62,8 +62,8 @@ describe('browser', () => {
6262
return {width: window.innerWidth, height: window.innerHeight};
6363
});
6464
assert.deepStrictEqual(result, {
65-
width: 700,
66-
height: 500,
65+
width: 1501,
66+
height: 801,
6767
});
6868
} finally {
6969
await browser.close();

0 commit comments

Comments
 (0)