mcp-browser-dev-tools 0.0.1-beta.1 → 0.0.1-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,10 +9,11 @@ It is designed for a local trust boundary:
9
9
  ## What You Get
10
10
 
11
11
  - A stdio MCP server for local desktop and terminal clients
12
- - Browser discovery and attach/detach for Chromium-family browsers and Firefox
13
- - Read-oriented tools for DOM inspection, element lookup, console messages, network requests, screenshots, tab listing, and buffered events
12
+ - Browser discovery and attach/detach for Chrome, Edge, other Chromium-family browsers, and Firefox
13
+ - Inspection tools for DOM lookup, richer element details, console messages, network requests, screenshots, tab listing, and buffered events
14
+ - Page interaction tools for navigation, reload, click, hover, type, select, key presses, scroll, and viewport overrides
14
15
  - Optional JavaScript evaluation behind an explicit environment flag
15
- - Helper commands to check browser connectivity and launch a debug-enabled browser
16
+ - Helper commands to check browser connectivity, launch a debug-enabled browser, and relay CDP traffic across a local machine boundary
16
17
 
17
18
  ## Requirements
18
19
 
@@ -22,6 +23,10 @@ It is designed for a local trust boundary:
22
23
 
23
24
  ## Install
24
25
 
26
+ If you are trying the prerelease from npm, replace `mcp-browser-dev-tools` below with `mcp-browser-dev-tools@beta`.
27
+
28
+ The published package name stays `mcp-browser-dev-tools`. The preferred installed CLI command is `mbdt`.
29
+
25
30
  One-off execution with `npx`:
26
31
 
27
32
  ```bash
@@ -32,19 +37,135 @@ Global install:
32
37
 
33
38
  ```bash
34
39
  npm install -g mcp-browser-dev-tools
35
- mcp-browser-dev-tools serve
40
+ mbdt serve
36
41
  ```
37
42
 
38
43
  Project-local install:
39
44
 
40
45
  ```bash
41
46
  npm install mcp-browser-dev-tools
42
- npx mcp-browser-dev-tools serve
47
+ npx mbdt serve
48
+ ```
49
+
50
+ ## Try It Locally
51
+
52
+ You can smoke-test the broker before wiring it into an MCP client.
53
+
54
+ For Windows, WSL, macOS, and Linux-specific setup paths, see [docs/setup.md](docs/setup.md).
55
+
56
+ Quick Chromium flow:
57
+
58
+ ```bash
59
+ # Launch a local browser with remote debugging enabled.
60
+ # open waits for the debug endpoint and prints the doctor summary automatically.
61
+ npx -y mcp-browser-dev-tools@beta open about:blank --family chromium
62
+ ```
63
+
64
+ If you want to verify a specific app URL too:
65
+
66
+ ```bash
67
+ npx -y mcp-browser-dev-tools@beta doctor --url http://127.0.0.1:3000
68
+ ```
69
+
70
+ Then start the MCP server in a dedicated terminal:
71
+
72
+ ```bash
73
+ npx -y mcp-browser-dev-tools@beta serve
74
+ ```
75
+
76
+ `serve` stays attached to stdio because MCP clients talk to it over standard input and output. Run it in its own terminal or let your MCP client spawn it directly.
77
+
78
+ If you want one broker to handle Chromium and Firefox at the same time, run it in `auto` mode and point each adapter at its own endpoint:
79
+
80
+ ```bash
81
+ MCP_BROWSER_FAMILY=auto \
82
+ CDP_BASE_URL=http://127.0.0.1:9222 \
83
+ FIREFOX_BIDI_WS_URL=ws://127.0.0.1:9333 \
84
+ npx -y mcp-browser-dev-tools@beta serve
43
85
  ```
44
86
 
87
+ If you already have a browser listening on `http://127.0.0.1:9222`, `doctor` is enough to confirm that the broker can reach it:
88
+
89
+ ```bash
90
+ CDP_BASE_URL=http://127.0.0.1:9222 npx -y mcp-browser-dev-tools@beta doctor
91
+ ```
92
+
93
+ If you need to bridge Windows Chrome into WSL without changing WSL networking mode, run the relay on Windows and point WSL at the relay port instead. The full procedure is in [docs/setup.md](docs/setup.md).
94
+
45
95
  ## MCP Client Configuration
46
96
 
47
- Generic stdio client configuration:
97
+ Use the same server command across MCP clients:
98
+
99
+ ```bash
100
+ npx -y mcp-browser-dev-tools@beta serve
101
+ ```
102
+
103
+ If you installed the package already, the shorter equivalent is:
104
+
105
+ ```bash
106
+ mbdt serve
107
+ ```
108
+
109
+ ### Codex
110
+
111
+ Add the server with the Codex CLI:
112
+
113
+ ```bash
114
+ codex mcp add browser-devtools \
115
+ --env MCP_BROWSER_FAMILY=chromium \
116
+ --env CDP_BASE_URL=http://127.0.0.1:9222 \
117
+ -- npx -y mcp-browser-dev-tools@beta serve
118
+ ```
119
+
120
+ Equivalent `~/.codex/config.toml` entry:
121
+
122
+ ```toml
123
+ [mcp_servers.browser-devtools]
124
+ command = "npx"
125
+ args = ["-y", "mcp-browser-dev-tools@beta", "serve"]
126
+
127
+ [mcp_servers.browser-devtools.env]
128
+ MCP_BROWSER_FAMILY = "chromium"
129
+ CDP_BASE_URL = "http://127.0.0.1:9222"
130
+ ```
131
+
132
+ ### Claude Code
133
+
134
+ Add the server with Claude Code:
135
+
136
+ ```bash
137
+ claude mcp add browser-devtools --scope user \
138
+ --env MCP_BROWSER_FAMILY=chromium \
139
+ --env CDP_BASE_URL=http://127.0.0.1:9222 \
140
+ -- npx -y mcp-browser-dev-tools@beta serve
141
+ ```
142
+
143
+ On native Windows, wrap `npx` with `cmd /c`:
144
+
145
+ ```powershell
146
+ claude mcp add browser-devtools --scope user --env MCP_BROWSER_FAMILY=chromium --env CDP_BASE_URL=http://127.0.0.1:9222 -- cmd /c npx -y mcp-browser-dev-tools@beta serve
147
+ ```
148
+
149
+ Equivalent `.mcp.json` shape:
150
+
151
+ ```json
152
+ {
153
+ "mcpServers": {
154
+ "browser-devtools": {
155
+ "command": "npx",
156
+ "args": ["-y", "mcp-browser-dev-tools@beta", "serve"],
157
+ "env": {
158
+ "MCP_BROWSER_FAMILY": "chromium",
159
+ "CDP_BASE_URL": "http://127.0.0.1:9222"
160
+ }
161
+ }
162
+ }
163
+ }
164
+ ```
165
+
166
+ ### Cursor
167
+
168
+ Cursor reads MCP servers from `mcp.json`:
48
169
 
49
170
  ```json
50
171
  {
@@ -61,29 +182,78 @@ Generic stdio client configuration:
61
182
  }
62
183
  ```
63
184
 
64
- For Firefox, switch `MCP_BROWSER_FAMILY` to `firefox` and set `FIREFOX_BIDI_WS_URL`.
185
+ ### Common Variants
186
+
187
+ Auto mode with both browsers attached to one MCP server:
188
+
189
+ ```json
190
+ {
191
+ "MCP_BROWSER_FAMILY": "auto",
192
+ "CDP_BASE_URL": "http://127.0.0.1:9222",
193
+ "FIREFOX_BIDI_WS_URL": "ws://127.0.0.1:9333"
194
+ }
195
+ ```
196
+
197
+ Firefox:
198
+
199
+ ```json
200
+ {
201
+ "MCP_BROWSER_FAMILY": "firefox",
202
+ "FIREFOX_BIDI_WS_URL": "ws://127.0.0.1:9222"
203
+ }
204
+ ```
205
+
206
+ Microsoft Edge:
207
+
208
+ ```json
209
+ {
210
+ "MCP_BROWSER_FAMILY": "edge",
211
+ "CDP_BASE_URL": "http://127.0.0.1:9222"
212
+ }
213
+ ```
214
+
215
+ Windows browser bridged into WSL through the relay:
216
+
217
+ ```json
218
+ {
219
+ "MCP_BROWSER_FAMILY": "chromium",
220
+ "MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS": "1",
221
+ "CDP_BASE_URL": "http://<windows-host-ip>:9223"
222
+ }
223
+ ```
224
+
225
+ Enable `evaluate_js`:
226
+
227
+ ```json
228
+ {
229
+ "MCP_BROWSER_ENABLE_EVAL": "1"
230
+ }
231
+ ```
65
232
 
66
233
  ## Commands
67
234
 
68
235
  - `serve` runs the MCP broker over stdio
69
236
  - `doctor [--url URL]` checks browser reachability, local display state, and optional page access
70
237
  - `open <url>` launches a local browser with remote debugging enabled
238
+ - `relay` forwards TCP traffic, useful for Windows-to-WSL DevTools bridging
71
239
  - `--help` and `help` print usage
72
240
  - `--version` and `version` print the package version
73
241
 
74
242
  Examples:
75
243
 
76
244
  ```bash
77
- mcp-browser-dev-tools doctor
78
- mcp-browser-dev-tools doctor --url http://127.0.0.1:3000
79
- mcp-browser-dev-tools open http://127.0.0.1:3000 --family chromium
245
+ mbdt doctor
246
+ mbdt doctor --url http://127.0.0.1:3000
247
+ mbdt open http://127.0.0.1:3000 --family chromium
248
+ mbdt open about:blank --family firefox --user-data-dir /tmp/mbdt-firefox
249
+ mbdt relay --wsl
80
250
  ```
81
251
 
82
252
  ## Configuration
83
253
 
84
- - `MCP_BROWSER_FAMILY` defaults to `chromium`; set `firefox` for Firefox BiDi
254
+ - `MCP_BROWSER_FAMILY` defaults to `chromium`; set `edge` for Microsoft Edge, `firefox` for Firefox BiDi, or `auto` to multiplex both adapters
85
255
  - `CDP_BASE_URL` defaults to `http://127.0.0.1:9222`
86
- - `FIREFOX_BIDI_WS_URL` defaults to `ws://127.0.0.1:9222`
256
+ - `FIREFOX_BIDI_WS_URL` defaults to `ws://127.0.0.1:9222`; when pointed at the root Firefox remote debugging port, the broker connects to the `/session` websocket and creates a BiDi session there
87
257
  - `MCP_BROWSER_EVENT_BUFFER_SIZE` sets the per-session buffered event limit
88
258
  - `MCP_BROWSER_ENABLE_EVAL=1` enables `evaluate_js`
89
259
  - `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1` allows non-loopback CDP or BiDi endpoints
@@ -92,13 +262,28 @@ mcp-browser-dev-tools open http://127.0.0.1:3000 --family chromium
92
262
 
93
263
  The `open` command also requires `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1` before it will bind Chromium remote debugging to a non-loopback address.
94
264
 
265
+ The `relay` command defaults to `127.0.0.1:9223 -> 127.0.0.1:9222`. Non-loopback relay binds require either `--wsl` on Windows or `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1`.
266
+
95
267
  ## Exposed Tools
96
268
 
97
- - `browser_status`
269
+ - `browser_status` returns broker metadata too: `serverName` and `serverVersion`
270
+ In `auto` mode it also includes per-browser adapter status under `browsers`
98
271
  - `list_tabs`
272
+ In `auto` mode each `targetId` is namespaced as `chromium:<id>` or `firefox:<id>`
99
273
  - `list_sessions`
274
+ In `auto` mode each `sessionId` is namespaced the same way
100
275
  - `attach_tab`
101
276
  - `detach_tab`
277
+ - `get_page_state`
278
+ - `navigate`
279
+ - `reload`
280
+ - `click`
281
+ - `hover`
282
+ - `type`
283
+ - `select`
284
+ - `press_key`
285
+ - `scroll`
286
+ - `set_viewport`
102
287
  - `get_console_messages`
103
288
  - `get_network_requests`
104
289
  - `get_document`
@@ -110,11 +295,46 @@ The `open` command also requires `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1` before i
110
295
 
111
296
  For tools that take `sessionId`, call `attach_tab` first and reuse the returned session.
112
297
 
298
+ ### Locator Syntax
299
+
300
+ Interaction and inspection tools accept these locator forms:
301
+
302
+ - CSS selectors such as `#app button.primary` or `css=.modal button`
303
+ - visible-text lookup such as `text=Open settings`
304
+ - role plus accessible name such as `role=button[name="Open settings"]`
305
+ - accessible-name lookup such as `name=Open settings`
306
+
307
+ `inspect_element` returns layout and accessibility-focused metadata including bounding box, visibility flags, interactivity flags, accessible name, inferred role, and a subset of computed styles. Invalid CSS selectors now return an explicit locator error instead of a generic DOM failure.
308
+
309
+ ### Screenshot Output
310
+
311
+ `take_screenshot` returns base64 image data plus metadata such as `mimeType`, `byteLength`, and `scope`. Pass `selector` to capture a single element instead of the full page.
312
+
113
313
  ## Browser Notes
114
314
 
115
315
  - Chromium uses the standard DevTools endpoints at `/json/version` and `/json/list`
116
316
  - Firefox support expects a direct BiDi websocket endpoint
117
317
  - In WSL, Linux browser executables are preferred before Windows fallback paths
318
+ - For Windows Chrome + WSL, prefer the `relay` command over changing Chrome's remote debugging bind
319
+
320
+ ## Why Not Playwright?
321
+
322
+ Playwright is still the stronger choice for deterministic browser automation and end-to-end tests. It has a more mature locator model, assertions, waiting semantics, tracing, and CI story.
323
+
324
+ `mcp-browser-dev-tools` solves a different problem:
325
+
326
+ - it is MCP-native, so AI clients call a bounded tool surface instead of generating and executing Playwright scripts
327
+ - it attaches to an already-open browser tab and inspects the current session state, cookies, login state, extensions, console, and network history
328
+ - it is designed for local AI debugging workflows, including loopback-only defaults, opt-in evaluation, and the Windows-to-WSL relay path
329
+ - it presents one MCP interface across Chromium CDP and Firefox BiDi instead of requiring the AI client to know browser protocol details
330
+
331
+ Use Playwright when you want reproducible automation. Use this project when you want an AI assistant to inspect and manipulate a live browser session through MCP.
332
+
333
+ ## Debugging Notes
334
+
335
+ - `attach_tab` now seeds network history from the Performance API so already-loaded pages still show useful requests
336
+ - console buffers include source URL, line and column where the browser reports them, plus stack frames when available
337
+ - `get_page_state` reports the current URL, title, viewport, and scroll position without enabling `evaluate_js`
118
338
 
119
339
  ## Safety Defaults
120
340
 
@@ -137,5 +357,6 @@ The repository uses `pnpm` for local development and CI. End-user installation a
137
357
  Additional docs:
138
358
 
139
359
  - [Architecture](docs/architecture.md)
360
+ - [Setup Guide](docs/setup.md)
140
361
  - [Repository Settings](docs/repository-settings.md)
141
362
  - [Publishing](PUBLISHING.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-browser-dev-tools",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.10",
4
4
  "description": "Local MCP server for Chromium DevTools Protocol and Firefox WebDriver BiDi",
5
5
  "author": "Hinaser <rindo.hinase@gmail.com>",
6
6
  "type": "module",
@@ -31,12 +31,15 @@
31
31
  "src/index.mjs",
32
32
  "src/json-rpc-stdio.mjs",
33
33
  "src/mcp-server.mjs",
34
+ "src/page-context.mjs",
34
35
  "src/package-info.mjs",
35
36
  "src/session-events.mjs",
36
37
  "src/server.mjs",
38
+ "src/tcp-relay.mjs",
37
39
  "README.md"
38
40
  ],
39
41
  "bin": {
42
+ "mbdt": "cli.mjs",
40
43
  "mcp-browser-dev-tools": "cli.mjs"
41
44
  },
42
45
  "keywords": [
@@ -1,10 +1,285 @@
1
1
  import { CdpSessionManager } from "./cdp-client.mjs";
2
2
  import { FirefoxBidiSessionManager } from "./firefox-bidi-client.mjs";
3
3
 
4
+ const SUPPORTED_FAMILIES = ["chromium", "firefox"];
5
+
6
+ function prefixId(browserFamily, value) {
7
+ return `${browserFamily}:${value}`;
8
+ }
9
+
10
+ function resolvePrefixedId(value, kind) {
11
+ if (typeof value !== "string") {
12
+ throw new Error(`${kind} must be a string`);
13
+ }
14
+
15
+ for (const browserFamily of SUPPORTED_FAMILIES) {
16
+ const prefix = `${browserFamily}:`;
17
+ if (value.startsWith(prefix)) {
18
+ return {
19
+ browserFamily,
20
+ localId: value.slice(prefix.length),
21
+ };
22
+ }
23
+ }
24
+
25
+ throw new Error(
26
+ `${kind} must include a browser prefix (${SUPPORTED_FAMILIES.join(", ")})`,
27
+ );
28
+ }
29
+
30
+ function mapPrefixedFields(value, browserFamily) {
31
+ if (Array.isArray(value)) {
32
+ return value.map((entry) => mapPrefixedFields(entry, browserFamily));
33
+ }
34
+
35
+ if (!value || typeof value !== "object") {
36
+ return value;
37
+ }
38
+
39
+ return Object.fromEntries(
40
+ Object.entries(value).map(([key, entry]) => {
41
+ if (key === "sessionId" && typeof entry === "string") {
42
+ return [key, prefixId(browserFamily, entry)];
43
+ }
44
+
45
+ if (key === "targetId" && typeof entry === "string") {
46
+ return [key, prefixId(browserFamily, entry)];
47
+ }
48
+
49
+ return [key, mapPrefixedFields(entry, browserFamily)];
50
+ }),
51
+ );
52
+ }
53
+
54
+ function mergeStatusError(statuses) {
55
+ const failures = Object.entries(statuses)
56
+ .filter(([, status]) => !status.available)
57
+ .map(([browserFamily, status]) => `${browserFamily}: ${status.error}`);
58
+
59
+ return failures.length > 0 ? failures.join("; ") : null;
60
+ }
61
+
62
+ export class MultiBrowserAdapter {
63
+ constructor(adapters) {
64
+ this.adapters = adapters;
65
+ }
66
+
67
+ getAdapter(browserFamily) {
68
+ const adapter = this.adapters[browserFamily];
69
+ if (!adapter) {
70
+ throw new Error(`Unsupported browser family: ${browserFamily}`);
71
+ }
72
+
73
+ return adapter;
74
+ }
75
+
76
+ async getBrowserStatus() {
77
+ const entries = await Promise.all(
78
+ Object.entries(this.adapters).map(async ([browserFamily, adapter]) => [
79
+ browserFamily,
80
+ await adapter.getBrowserStatus(),
81
+ ]),
82
+ );
83
+ const browsers = Object.fromEntries(entries);
84
+ const availableBrowsers = Object.entries(browsers)
85
+ .filter(([, status]) => status.available)
86
+ .map(([browserFamily]) => browserFamily);
87
+
88
+ return {
89
+ available: availableBrowsers.length > 0,
90
+ browserFamily: "auto",
91
+ sessionCount: Object.values(browsers).reduce(
92
+ (total, status) => total + (status.sessionCount ?? 0),
93
+ 0,
94
+ ),
95
+ availableBrowsers,
96
+ browsers,
97
+ error:
98
+ availableBrowsers.length > 0
99
+ ? null
100
+ : (mergeStatusError(browsers) ?? "No browser endpoints available"),
101
+ };
102
+ }
103
+
104
+ async listTargets() {
105
+ const results = await Promise.all(
106
+ Object.entries(this.adapters).map(async ([browserFamily, adapter]) => {
107
+ try {
108
+ return (await adapter.listTargets()).map((target) => ({
109
+ ...target,
110
+ browserFamily,
111
+ targetId: prefixId(browserFamily, target.targetId),
112
+ }));
113
+ } catch {
114
+ return [];
115
+ }
116
+ }),
117
+ );
118
+
119
+ return results.flat();
120
+ }
121
+
122
+ listSessions() {
123
+ return Object.entries(this.adapters).flatMap(([browserFamily, adapter]) =>
124
+ adapter.listSessions().map((session) => ({
125
+ ...session,
126
+ browserFamily,
127
+ sessionId: prefixId(browserFamily, session.sessionId),
128
+ targetId:
129
+ typeof session.targetId === "string"
130
+ ? prefixId(browserFamily, session.targetId)
131
+ : session.targetId,
132
+ })),
133
+ );
134
+ }
135
+
136
+ async attachToTarget(targetId) {
137
+ const { browserFamily, localId } = resolvePrefixedId(targetId, "targetId");
138
+ const session =
139
+ await this.getAdapter(browserFamily).attachToTarget(localId);
140
+
141
+ return {
142
+ ...session,
143
+ browserFamily,
144
+ sessionId: prefixId(browserFamily, session.sessionId),
145
+ targetId:
146
+ typeof session.targetId === "string"
147
+ ? prefixId(browserFamily, session.targetId)
148
+ : targetId,
149
+ };
150
+ }
151
+
152
+ async detachSession(sessionId) {
153
+ const { browserFamily, localId } = resolvePrefixedId(
154
+ sessionId,
155
+ "sessionId",
156
+ );
157
+
158
+ return mapPrefixedFields(
159
+ await this.getAdapter(browserFamily).detachSession(localId),
160
+ browserFamily,
161
+ );
162
+ }
163
+
164
+ async delegateSession(sessionId, methodName, args = []) {
165
+ const { browserFamily, localId } = resolvePrefixedId(
166
+ sessionId,
167
+ "sessionId",
168
+ );
169
+ const adapter = this.getAdapter(browserFamily);
170
+ const result = await adapter[methodName](localId, ...args);
171
+
172
+ if (result === undefined) {
173
+ return result;
174
+ }
175
+
176
+ if (methodName === "getConsoleMessages" || methodName === "getEvents") {
177
+ return mapPrefixedFields(result, browserFamily);
178
+ }
179
+
180
+ if (methodName === "getNetworkRequests") {
181
+ return mapPrefixedFields(result, browserFamily);
182
+ }
183
+
184
+ return mapPrefixedFields(result, browserFamily);
185
+ }
186
+
187
+ getPageState(sessionId) {
188
+ return this.delegateSession(sessionId, "getPageState");
189
+ }
190
+
191
+ navigate(sessionId, url, options) {
192
+ return this.delegateSession(sessionId, "navigate", [url, options]);
193
+ }
194
+
195
+ reload(sessionId, options) {
196
+ return this.delegateSession(sessionId, "reload", [options]);
197
+ }
198
+
199
+ click(sessionId, selector) {
200
+ return this.delegateSession(sessionId, "click", [selector]);
201
+ }
202
+
203
+ hover(sessionId, selector) {
204
+ return this.delegateSession(sessionId, "hover", [selector]);
205
+ }
206
+
207
+ type(sessionId, selector, text, options) {
208
+ return this.delegateSession(sessionId, "type", [selector, text, options]);
209
+ }
210
+
211
+ select(sessionId, selector, options) {
212
+ return this.delegateSession(sessionId, "select", [selector, options]);
213
+ }
214
+
215
+ pressKey(sessionId, key, selector) {
216
+ return this.delegateSession(sessionId, "pressKey", [key, selector]);
217
+ }
218
+
219
+ scroll(sessionId, options) {
220
+ return this.delegateSession(sessionId, "scroll", [options]);
221
+ }
222
+
223
+ setViewport(sessionId, options) {
224
+ return this.delegateSession(sessionId, "setViewport", [options]);
225
+ }
226
+
227
+ evaluate(sessionId, expression) {
228
+ return this.delegateSession(sessionId, "evaluate", [expression]);
229
+ }
230
+
231
+ getDocument(sessionId, depth) {
232
+ return this.delegateSession(sessionId, "getDocument", [depth]);
233
+ }
234
+
235
+ getConsoleMessages(sessionId, limit) {
236
+ return this.delegateSession(sessionId, "getConsoleMessages", [limit]);
237
+ }
238
+
239
+ getNetworkRequests(sessionId, limit) {
240
+ return this.delegateSession(sessionId, "getNetworkRequests", [limit]);
241
+ }
242
+
243
+ inspectElement(sessionId, selector) {
244
+ return this.delegateSession(sessionId, "inspectElement", [selector]);
245
+ }
246
+
247
+ takeScreenshot(sessionId, format, options) {
248
+ return this.delegateSession(sessionId, "takeScreenshot", [format, options]);
249
+ }
250
+
251
+ getEvents(sessionId, limit) {
252
+ return this.delegateSession(sessionId, "getEvents", [limit]);
253
+ }
254
+
255
+ async closeAll() {
256
+ await Promise.all(
257
+ Object.values(this.adapters).map((adapter) => adapter.closeAll()),
258
+ );
259
+ }
260
+ }
261
+
4
262
  export function createBrowserAdapter(config) {
5
263
  if (config.browserFamily === "firefox") {
6
264
  return new FirefoxBidiSessionManager(config);
7
265
  }
8
266
 
267
+ if (config.browserFamily === "auto") {
268
+ return new MultiBrowserAdapter({
269
+ chromium: new CdpSessionManager({
270
+ ...config,
271
+ browserFamily: "chromium",
272
+ }),
273
+ firefox: new FirefoxBidiSessionManager({
274
+ ...config,
275
+ browserFamily: "firefox",
276
+ }),
277
+ });
278
+ }
279
+
280
+ if (config.browserFamily === "edge") {
281
+ return new CdpSessionManager(config);
282
+ }
283
+
9
284
  return new CdpSessionManager(config);
10
285
  }
@@ -37,6 +37,36 @@ export function getBrowserCandidates(
37
37
  env = process.env,
38
38
  platform = detectPlatform(env),
39
39
  ) {
40
+ if (family === "edge") {
41
+ if (platform === "darwin") {
42
+ return [
43
+ "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
44
+ "microsoft-edge",
45
+ ];
46
+ }
47
+
48
+ if (platform === "wsl") {
49
+ return [
50
+ "microsoft-edge",
51
+ "microsoft-edge-stable",
52
+ "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
53
+ "/mnt/c/Program Files/Microsoft/Edge/Application/msedge.exe",
54
+ "msedge.exe",
55
+ ];
56
+ }
57
+
58
+ if (platform === "win32") {
59
+ return [
60
+ "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
61
+ "C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe",
62
+ "msedge.exe",
63
+ "microsoft-edge",
64
+ ];
65
+ }
66
+
67
+ return ["microsoft-edge", "microsoft-edge-stable", "msedge"];
68
+ }
69
+
40
70
  if (family === "firefox") {
41
71
  if (platform === "darwin") {
42
72
  return ["/Applications/Firefox.app/Contents/MacOS/firefox", "firefox"];
@@ -128,10 +158,12 @@ export async function findBrowserExecutable(family, env = process.env) {
128
158
 
129
159
  export async function detectInstalledBrowsers(env = process.env) {
130
160
  const chromium = await findBrowserExecutable("chromium", env);
161
+ const edge = await findBrowserExecutable("edge", env);
131
162
  const firefox = await findBrowserExecutable("firefox", env);
132
163
 
133
164
  return {
134
165
  chromium,
166
+ edge,
135
167
  firefox,
136
168
  };
137
169
  }
@@ -149,6 +181,9 @@ export function buildBrowserLaunchArgs({
149
181
 
150
182
  const args = [];
151
183
  if (family === "firefox") {
184
+ if (userDataDir) {
185
+ args.push("-new-instance", "-profile", userDataDir);
186
+ }
152
187
  if (remoteDebuggingPort) {
153
188
  args.push(`--remote-debugging-port=${remoteDebuggingPort}`);
154
189
  }