You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Session IDs** are formatted as `{browser}_{Date.now()}` (e.g., `chrome_1708531200000`)
90
93
- Only one session is "current" at a time (set by `start_browser`, cleared by `close_session`)
91
94
- Multiple sessions can exist in the `drivers` Map, but tools always operate on `currentSession`
95
+
-**BiDi state** is a single Map of per-session objects — cleanup is one `state.bidi.delete(sessionId)` call
92
96
93
97
### Helper Functions
94
98
95
99
| Function | Purpose |
96
100
|----------|---------|
97
101
|`getDriver()`| Returns the WebDriver for `state.currentSession`. Throws if no active session. |
98
102
|`getLocator(by, value)`| Converts a locator strategy string (`"id"`, `"css"`, `"xpath"`, `"name"`, `"tag"`, `"class"`) to a Selenium `By` object. |
103
+
|`newBidiState()`| Returns a fresh `{ available, consoleLogs, pageErrors, networkLogs }` object for a new session. |
104
+
|`setupBidi(driver, sessionId)`| Wires up BiDi event listeners (console, JS errors, network) for a session. Called from `start_browser`. |
105
+
|`registerBidiTool(name, description, logKey, emptyMessage, unavailableMessage)`| Factory that registers a diagnostic tool. All three BiDi tools (`get_console_logs`, `get_page_errors`, `get_network_logs`) use this — don't copy-paste a new handler, call this instead. |
106
+
107
+
### Diagnostics (WebDriver BiDi)
108
+
109
+
The server automatically enables [WebDriver BiDi](https://w3c.github.io/webdriver-bidi/) when starting a browser session. BiDi provides real-time, passive capture of browser diagnostics — console messages, JavaScript errors, and network activity are collected in the background without any extra configuration.
110
+
111
+
This is especially useful for AI agents: when something goes wrong on a page, the agent can check `get_console_logs` and `get_page_errors` to understand *why*, rather than relying solely on screenshots.
112
+
113
+
-**Automatic**: BiDi is enabled by default when the browser supports it
114
+
-**Graceful fallback**: If the browser or driver doesn't support BiDi, the session starts normally and the diagnostic tools return a helpful message
115
+
-**No performance impact**: Logs are passively captured via event listeners — no polling or extra requests
116
+
-**Per-session**: Each browser session has its own log buffers, cleaned up automatically on session close
117
+
-**BiDi modules are dynamically imported** at the top of `server.js` — if the selenium-webdriver version doesn't include them, `LogInspector` and `Network` are set to `null` and all BiDi code is skipped
99
118
100
119
### Cleanup
101
120
@@ -232,6 +251,7 @@ Tests talk to the real MCP server over stdio using JSON-RPC 2.0. No mocking.
Copy file name to clipboardExpand all lines: README.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,10 @@ A Model Context Protocol (MCP) server implementation for Selenium WebDriver, ena
23
23
- Upload files
24
24
- Support for headless mode
25
25
- Manage browser cookies (add, get, delete)
26
+
-**Real-time diagnostics** via WebDriver BiDi:
27
+
- Console log capture (info, warn, error)
28
+
- JavaScript error detection with stack traces
29
+
- Network request monitoring (successes and failures)
26
30
27
31
## Supported Browsers
28
32
@@ -791,6 +795,54 @@ Deletes cookies from the current browser session. Deletes a specific cookie by n
791
795
}
792
796
```
793
797
798
+
### get_console_logs
799
+
Retrieves captured browser console messages (log, warn, error, etc.). Console logs are automatically captured in the background via WebDriver BiDi when the browser supports it — no configuration needed.
800
+
801
+
**Parameters:**
802
+
| Parameter | Type | Required | Description |
803
+
|-----------|------|----------|-------------|
804
+
| clear | boolean | No | Clear the captured logs after retrieving them (default: false) |
805
+
806
+
**Example:**
807
+
```json
808
+
{
809
+
"tool": "get_console_logs",
810
+
"parameters": {}
811
+
}
812
+
```
813
+
814
+
### get_page_errors
815
+
Retrieves captured JavaScript errors and uncaught exceptions with full stack traces. Errors are automatically captured in the background via WebDriver BiDi.
816
+
817
+
**Parameters:**
818
+
| Parameter | Type | Required | Description |
819
+
|-----------|------|----------|-------------|
820
+
| clear | boolean | No | Clear the captured errors after retrieving them (default: false) |
821
+
822
+
**Example:**
823
+
```json
824
+
{
825
+
"tool": "get_page_errors",
826
+
"parameters": {}
827
+
}
828
+
```
829
+
830
+
### get_network_logs
831
+
Retrieves captured network activity including successful responses and failed requests. Network logs are automatically captured in the background via WebDriver BiDi.
832
+
833
+
**Parameters:**
834
+
| Parameter | Type | Required | Description |
835
+
|-----------|------|----------|-------------|
836
+
| clear | boolean | No | Clear the captured logs after retrieving them (default: false) |
'returns browser console messages (log, warn, info, debug) captured via WebDriver BiDi. Useful for debugging page behavior, seeing application output, and catching warnings.',
1076
+
'consoleLogs',
1077
+
'No console logs captured',
1078
+
'Console log capture is not available (BiDi not supported by this browser/driver)'
1079
+
);
1080
+
1081
+
registerBidiTool(
1082
+
'get_page_errors',
1083
+
'returns JavaScript errors and exceptions captured via WebDriver BiDi. Includes stack traces when available. Essential for diagnosing why a page is broken or a feature isn\'t working.',
1084
+
'pageErrors',
1085
+
'No page errors captured',
1086
+
'Page error capture is not available (BiDi not supported by this browser/driver)'
1087
+
);
1088
+
1089
+
registerBidiTool(
1090
+
'get_network_logs',
1091
+
'returns network activity (completed responses and failed requests) captured via WebDriver BiDi. Shows HTTP status codes, URLs, methods, and error details. Useful for diagnosing failed API calls and broken resources.',
1092
+
'networkLogs',
1093
+
'No network activity captured',
1094
+
'Network log capture is not available (BiDi not supported by this browser/driver)'
0 commit comments