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
Add WebDriver BiDi support for real-time browser diagnostics
Automatically enables BiDi when starting a browser session to passively
capture console logs, JavaScript errors, and network activity in the
background. Falls back silently if the browser/driver doesn't support it.
New tools:
- get_console_logs: retrieve captured console messages (log, warn, error)
- get_page_errors: retrieve JS errors/exceptions with stack traces
- get_network_logs: retrieve network responses and failed requests
Design decisions:
- No opt-in flag — BiDi is an implementation detail, not a user choice
- Graceful fallback — older browsers work exactly as before
- All BiDi event callbacks wrapped in try/catch to prevent server crashes
- Per-session log buffers, cleaned up automatically on close
Closes#55
Copy file name to clipboardExpand all lines: README.md
+65Lines changed: 65 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,67 @@ 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) |
837
+
838
+
**Example:**
839
+
```json
840
+
{
841
+
"tool": "get_network_logs",
842
+
"parameters": {}
843
+
}
844
+
```
845
+
846
+
---
847
+
848
+
## Diagnostics (WebDriver BiDi)
849
+
850
+
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.
851
+
852
+
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.
853
+
854
+
-**Automatic**: BiDi is enabled by default when the browser supports it
855
+
-**Graceful fallback**: If the browser or driver doesn't support BiDi, the session starts normally and the diagnostic tools return a helpful message
856
+
-**No performance impact**: Logs are passively captured via event listeners — no polling or extra requests
857
+
-**Per-session**: Each browser session has its own log buffers, cleaned up automatically on session close
"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.",
1111
+
{
1112
+
clear: z.boolean().optional().describe("Clear the errors after returning them (default: false)")
1113
+
},
1114
+
async({ clear =false})=>{
1115
+
try{
1116
+
getDriver();// ensure active session
1117
+
constsessionId=state.currentSession;
1118
+
if(!state.bidiAvailable.get(sessionId)){
1119
+
return{
1120
+
content: [{type: 'text',text: 'Page error capture is not available (BiDi not supported by this browser/driver)'}]
"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.",
1145
+
{
1146
+
clear: z.boolean().optional().describe("Clear the logs after returning them (default: false)")
1147
+
},
1148
+
async({ clear =false})=>{
1149
+
try{
1150
+
getDriver();// ensure active session
1151
+
constsessionId=state.currentSession;
1152
+
if(!state.bidiAvailable.get(sessionId)){
1153
+
return{
1154
+
content: [{type: 'text',text: 'Network log capture is not available (BiDi not supported by this browser/driver)'}]
0 commit comments