chromedevtools--chrome-devtools-mcp
9a51af219f
Related Issue - https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/430 ### Description When Chrome is launched via Puppeteer, it automatically adds a set of default flags like `--enable-automation --disable-extensions --disable-component-extensions-with-background-pages.` Currently, there is no way to opt out of these defaults, which makes certain use cases difficult or impossible to support. this PR adds a way to selectively ignore specific default Chrome launch flags applied by Puppeteer using its [ignoreDefaultArgs](https://pptr.dev/api/puppeteer.launchoptions#ignoredefaultargs) property. ```json { "name": "chrome-devtools-mcp", "version": "latest", "mcpServers": { "chrome-devtools": { "command": "npx", "args": [ "chrome-devtools-mcp@latest", "--ignore-default-chrome-arg='--enable-automation'", "--ignore-default-chrome-arg='--disable-extensions'" ] } } } ``` **Feedback appreciated** @OrKoN
100 行
2.7 KiB
TypeScript
100 行
2.7 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 {ensureBrowserConnected, 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(),
|
|
devtools: false,
|
|
});
|
|
try {
|
|
try {
|
|
const browser2 = await launch({
|
|
headless: true,
|
|
isolated: false,
|
|
userDataDir: folderPath,
|
|
executablePath: executablePath(),
|
|
devtools: false,
|
|
});
|
|
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: 1501,
|
|
height: 801,
|
|
},
|
|
devtools: false,
|
|
});
|
|
try {
|
|
const [page] = await browser.pages();
|
|
const result = await page.evaluate(() => {
|
|
return {width: window.innerWidth, height: window.innerHeight};
|
|
});
|
|
assert.deepStrictEqual(result, {
|
|
width: 1501,
|
|
height: 801,
|
|
});
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
});
|
|
it('connects to an existing browser with userDataDir', 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(),
|
|
devtools: false,
|
|
chromeArgs: ['--remote-debugging-port=0'],
|
|
});
|
|
try {
|
|
const connectedBrowser = await ensureBrowserConnected({
|
|
userDataDir: folderPath,
|
|
devtools: false,
|
|
});
|
|
assert.ok(connectedBrowser);
|
|
assert.ok(connectedBrowser.connected);
|
|
connectedBrowser.disconnect();
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
});
|
|
});
|