feat(daemon): add WebSocket relay with console/network monitoring

- Add ws-relay.ts: WebSocket server at /ws with broadcast function
- Add network event types (request/response/failed) to core ws.ts types
- Add ConsoleEntry and NetworkEntry types
- Add consoleLog and networkLog buffers to PageRegistry (100/200 max)
- Add console listener in createPage: broadcasts page:console events
- Add network listeners (request/response/requestfailed) in createPage
- Add page crash handler broadcasting page:crashed events
- Add history endpoints: GET /pages/:id/console and GET /pages/:id/network
- Integrate createWsRelay in server.ts startup
- Bump ws from devDependency to full dependency
This commit is contained in:
2026-08-12 21:28:02 +08:00
parent b843eea9ae
commit e79590a6d8
10 changed files with 220 additions and 13 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
export { type PageInfo } from './types/page.js';
export { type ApiResponse, ErrorCode } from './types/api.js';
export { type WsEvent } from './types/ws.js';
export { type WsEvent, type ConsoleEntry, type NetworkEntry } from './types/ws.js';
export {
type FingerprintProfile,
type FingerprintPermissions,
+19
View File
@@ -1,10 +1,29 @@
// WebSocket event type definitions / WebSocket 事件类型定义
import type { PageInfo } from './page.js';
export interface ConsoleEntry {
level: string;
text: string;
timestamp: number;
}
export interface NetworkEntry {
type: 'request' | 'response' | 'failed';
url: string;
method?: string;
status?: number;
headers?: Record<string, string>;
failure?: string;
timestamp: number;
}
export type WsEvent =
| { type: 'page:created'; data: PageInfo }
| { type: 'page:closed'; data: { id: string } }
| { type: 'page:navigated'; data: { id: string; url: string; title: string } }
| { type: 'page:crashed'; data: { id: string; error: string } }
| { type: 'page:console'; data: { id: string; level: string; text: string } }
| { type: 'page:network:request'; data: { id: string; url: string; method: string; headers: Record<string, string> } }
| { type: 'page:network:response'; data: { id: string; url: string; status: number; headers: Record<string, string> } }
| { type: 'page:network:failed'; data: { id: string; url: string; failure: string } }
| { type: 'page:detection:warning'; data: { id: string; level: string; detail: string } };