Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .claude-plugin/COWORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerequisites

- **Firefox** 120+ installed
- **Firefox** 153+ installed
- **Node.js 20.19.0+** (includes npm) — required to run the MCP server. Download from [nodejs.org](https://nodejs.org).

## Installation Steps
Expand Down
4 changes: 2 additions & 2 deletions .claude-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ The plugin works automatically when you ask about browser tasks:

The plugin enables the following by default:

- **`--enable-script`** — enables JavaScript evaluation and debugging tools (`evaluate_script`, logpoints, script inspection). Requires Firefox 153+.
- **`--enable-script`** — enables JavaScript evaluation and debugging tools (`evaluate_script`, logpoints, script inspection).
- **`remote.prefs.recommended=false`** — skips WebDriver's automation preferences so Firefox behaves closer to a regular browser session. See [RecommendedPreferences](https://searchfox.org/firefox-main/source/remote/shared/RecommendedPreferences.sys.mjs) for what those preferences do.

## Requirements

- Firefox 153+ (for script tools) or Firefox 120+ (without script tools)
- Firefox 153+
- Node.js 20.19.0+

## Links
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ See [SECURITY.md](SECURITY.md) for a full breakdown of risks and how to report v
## Requirements

- Node.js ≥ 20.19.0
- Firefox 100+ installed (auto‑detected, or pass `--firefox-path`)
- Firefox 153+ installed (auto‑detected, or pass `--firefox-path`)

## Install and use with Claude Code or Codex (npx)

Expand Down
6 changes: 3 additions & 3 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ accepted paths.
- [profiler](#profiler): Start, stop, and query the performance profiler.
- [screencast](#screencast): Record screencasts of the page viewport (Firefox 154+).
- [script](#script): Evaluate arbitrary JavaScript in the page context.
- [debugging](#debugging): Inspect scripts and set logpoints (Firefox 153+).
- [debugging](#debugging): Inspect scripts and set logpoints.
- [prefs](#prefs): Get and set Firefox preferences.
- [privileged](#privileged): Access privileged ("chrome") browsing contexts.
- [bidi](#bidi): Send raw WebDriver BiDi commands.
Expand Down Expand Up @@ -607,11 +607,11 @@ Parameters:

## debugging

Inspect scripts and set logpoints (Firefox 153+).
Inspect scripts and set logpoints.

### `enable_debugger`

Enable the JS debugger for the current page. Required before set_logpoint works. Requires Firefox 153+.
Enable the JS debugger for the current page. Required before set_logpoint works.

No parameters.

Expand Down
3 changes: 1 addition & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ export const cliOptions = {
},
enableScript: {
type: 'boolean',
description:
'Deprecated: use --tools/--tool-preset. Enable the script and debugging tools (Firefox 153+ required).',
description: 'Deprecated: use --tools/--tool-preset. Enable the script and debugging tools.',
default: (process.env.ENABLE_SCRIPT ?? 'false') === 'true',
},
enablePrivilegedContext: {
Expand Down
5 changes: 4 additions & 1 deletion src/firefox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { PageManagement } from './pages.js';
import { CacheManagement, type CacheBehavior } from './cache.js';
import { SnapshotManager, type Snapshot, type SnapshotOptions } from './snapshot/index.js';
import type { ResolvedElement } from './snapshot/resolver.js';
import { assertSupportedFirefoxVersion } from '../utils/version.js';

/**
* Main Firefox Client facade
Expand Down Expand Up @@ -77,7 +78,9 @@ export class FirefoxClient {
* Connect and initialize all modules
*/
async connect(): Promise<void> {
this.bidi = new BiDiFacade(await this.core.connect());
const driver = await this.core.connect();
assertSupportedFirefoxVersion(this.core.getFirefoxVersion());
this.bidi = new BiDiFacade(driver);
// Firefox creates a dedicated user context for sessions started at runtime,
// and reports it with this capability.
const userContext = this.core.getCapabilities().get('moz:userContext') as string | undefined;
Expand Down
23 changes: 2 additions & 21 deletions src/tools/debugging.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import { successResponse, errorResponse } from '../utils/response-helpers.js';
import { compareVersions } from '../utils/version.js';
import { remoteValueToNative } from '../utils/remote-value.js';
import { defineModule, defineToolHandler, type ToolDefinition } from './module.js';
import type { McpToolResponse } from '../types/common.js';

const MIN_VERSION = '153';

function requireDebuggingSupport(firefox: { getFirefoxVersion(): string | null }): void {
const version = firefox.getFirefoxVersion();
if (version !== null && compareVersions(version, MIN_VERSION) < 0) {
throw new Error(
`moz:debugging requires Firefox ${MIN_VERSION}+, current version is ${version}`
);
}
}

function requireContext(contextId: string | null): string {
if (!contextId) {
throw new Error('No active browsing context');
Expand All @@ -28,8 +16,7 @@ function requireContext(contextId: string | null): string {

export const enableDebuggerTool = {
name: 'enable_debugger',
description:
'Enable the JS debugger for the current page. Required before set_logpoint works. Requires Firefox 153+.',
description: 'Enable the JS debugger for the current page. Required before set_logpoint works.',
annotations: {
readOnlyHint: false,
},
Expand Down Expand Up @@ -121,7 +108,6 @@ export const handleEnableDebugger = defineToolHandler<typeof enableDebuggerTool>
async (_args): Promise<McpToolResponse> => {
const { getFirefox } = await import('../index.js');
const firefox = await getFirefox();
requireDebuggingSupport(firefox);
await firefox.sendBiDiCommand('moz:debugging.setDebuggerEnabled', { enabled: true });
return successResponse('Debugger enabled');
},
Expand All @@ -132,7 +118,6 @@ export const handleListScripts = defineToolHandler<typeof listScriptsTool>(
async (_args): Promise<McpToolResponse> => {
const { getFirefox } = await import('../index.js');
const firefox = await getFirefox();
requireDebuggingSupport(firefox);
const contextId = requireContext(firefox.getCurrentContextId());
const result = await firefox.sendBiDiCommand('moz:debugging.listScripts', {
context: contextId,
Expand All @@ -151,7 +136,6 @@ export const handleGetScriptSource = defineToolHandler<typeof getScriptSourceToo
const { scriptUrl } = args;
const { getFirefox } = await import('../index.js');
const firefox = await getFirefox();
requireDebuggingSupport(firefox);
const contextId = requireContext(firefox.getCurrentContextId());
const result = await firefox.sendBiDiCommand('moz:debugging.getScriptSource', {
context: contextId,
Expand All @@ -167,7 +151,6 @@ export const handleSetLogpoint = defineToolHandler<typeof setLogpointTool>(
const { url, line, expression } = args;
const { getFirefox } = await import('../index.js');
const firefox = await getFirefox();
requireDebuggingSupport(firefox);
const logpointId = await firefox.setLogpoint(url, line, expression);
return successResponse(`Logpoint set (id: ${logpointId})`);
},
Expand All @@ -179,7 +162,6 @@ export const handleRemoveLogpoint = defineToolHandler<typeof removeLogpointTool>
const { logpoint } = args;
const { getFirefox } = await import('../index.js');
const firefox = await getFirefox();
requireDebuggingSupport(firefox);
await firefox.removeLogpoint(logpoint);
return successResponse('Logpoint removed');
},
Expand All @@ -191,7 +173,6 @@ export const handleGetLogpointResults = defineToolHandler<typeof getLogpointResu
const { logpoint } = args;
const { getFirefox } = await import('../index.js');
const firefox = await getFirefox();
requireDebuggingSupport(firefox);
const results = firefox.getLogpointResults(logpoint);
if (results === null) {
return errorResponse(new Error(`Logpoint ${logpoint} not found`));
Expand All @@ -212,7 +193,7 @@ export const handleGetLogpointResults = defineToolHandler<typeof getLogpointResu

export const module = defineModule({
name: 'debugging',
description: 'Inspect scripts and set logpoints (Firefox 153+).',
description: 'Inspect scripts and set logpoints.',
unavailableInRestrictedSession: true,
tools: [
[enableDebuggerTool, handleEnableDebugger],
Expand Down
14 changes: 14 additions & 0 deletions src/utils/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ export function compareVersions(versionA: string, versionB: string): number {
}
return 0;
}

export const MIN_SUPPORTED_FIREFOX_VERSION = '153';

/**
* Throw if the version is older than the oldest supported Firefox. A null
* version is accepted, since it cannot be checked.
*/
export function assertSupportedFirefoxVersion(version: string | null): void {
if (version !== null && compareVersions(version, MIN_SUPPORTED_FIREFOX_VERSION) < 0) {
throw new Error(
`Firefox ${version} is not supported. Firefox MCP requires Firefox ${MIN_SUPPORTED_FIREFOX_VERSION} or later.`
);
}
}
15 changes: 14 additions & 1 deletion tests/unit/utils/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { describe, it, expect } from 'vitest';
import { compareVersions } from '../../../src/utils/version.js';
import { assertSupportedFirefoxVersion, compareVersions } from '../../../src/utils/version.js';

describe('Version helpers', () => {
describe('compareVersions', () => {
Expand All @@ -30,4 +30,17 @@ describe('Version helpers', () => {
expect(() => compareVersions('153.0', '')).toThrow('Unable to parse Firefox version');
});
});

describe('assertSupportedFirefoxVersion', () => {
it('should throw for a version older than 153', () => {
expect(() => assertSupportedFirefoxVersion('152.0.1')).toThrow(
'Firefox 152.0.1 is not supported. Firefox MCP requires Firefox 153 or later.'
);
});
it('should accept 153 and later, or an unknown version', () => {
expect(() => assertSupportedFirefoxVersion('153.0esr')).not.toThrow();
expect(() => assertSupportedFirefoxVersion('161.0a1')).not.toThrow();
expect(() => assertSupportedFirefoxVersion(null)).not.toThrow();
});
});
});