项目文件夹

文件
Alex Rudenko ef61a08707 feat: support initial viewport in the CLI (#229)
Closes https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/165

This PR uses page_resize logic to set the initial viewport size. Not
using the emulation because it looks buggy in headful which is our
default mode.
2025-10-01 10:11:35 +02:00

73 行
1.9 KiB
TypeScript

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import os from 'node:os';
import path from 'node:path';
import {describe, it} from 'node:test';
import {executablePath} from 'puppeteer';
import {launch} from '../src/browser.js';
describe('browser', () => {
it('cannot launch multiple times with the same profile', async () => {
const tmpDir = os.tmpdir();
const folderPath = path.join(tmpDir, `temp-folder-${crypto.randomUUID()}`);
const browser1 = await launch({
headless: true,
isolated: false,
userDataDir: folderPath,
executablePath: executablePath(),
});
try {
try {
const browser2 = await launch({
headless: true,
isolated: false,
userDataDir: folderPath,
executablePath: executablePath(),
});
await browser2.close();
assert.fail('not reached');
} catch (err) {
assert.strictEqual(
err.message,
`The browser is already running for ${folderPath}. Use --isolated to run multiple browser instances.`,
);
}
} finally {
await browser1.close();
}
});
it('launches with the initial viewport', async () => {
const tmpDir = os.tmpdir();
const folderPath = path.join(tmpDir, `temp-folder-${crypto.randomUUID()}`);
const browser = await launch({
headless: true,
isolated: false,
userDataDir: folderPath,
executablePath: executablePath(),
viewport: {
width: 700,
height: 500,
},
});
try {
const [page] = await browser.pages();
const result = await page.evaluate(() => {
return {width: window.innerWidth, height: window.innerHeight};
});
assert.deepStrictEqual(result, {
width: 700,
height: 500,
});
} finally {
await browser.close();
}
});
});