Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ import {puppeteer} from './third_party/index.js';

let browser: Browser | undefined;

// Heavy pages (e.g. dev bundles >100MB) cannot ack `Network.enable` and
// other auto-attached domain calls within puppeteer's default 180s.
// Once that fires, the CDP connection is marked dead and every
// subsequent call throws — only daemon restart recovers. Bumping the
// ceiling to 10min covers realistic loads; override via env for power
// users.
const PROTOCOL_TIMEOUT_MS = parseInt(
process.env.CHROME_DEVTOOLS_PROTOCOL_TIMEOUT_MS ?? '600000',
10,
);

function makeTargetFilter(enableExtensions = false) {
const ignoredPrefixes = new Set(['chrome://', 'chrome-untrusted://']);
if (!enableExtensions) {
Expand Down Expand Up @@ -61,6 +72,7 @@ export async function ensureBrowserConnected(options: {
targetFilter: makeTargetFilter(enableExtensions),
defaultViewport: null,
handleDevToolsAsPage: true,
protocolTimeout: PROTOCOL_TIMEOUT_MS,
};

let autoConnect = false;
Expand Down Expand Up @@ -228,6 +240,7 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
ignoreDefaultArgs: ignoreDefaultArgs,
acceptInsecureCerts: options.acceptInsecureCerts,
handleDevToolsAsPage: true,
protocolTimeout: PROTOCOL_TIMEOUT_MS,
enableExtensions: options.enableExtensions,
});
if (options.logFile) {
Expand Down