chrome-cdp-cli 1.5.0 → 1.6.0
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 +12 -0
- package/dist/cli/CLIApplication.js +21 -0
- package/dist/cli/CLIInterface.js +65 -1
- package/dist/cli/CommandRouter.js +1 -0
- package/dist/client/ProxyClient.js +254 -0
- package/dist/client/index.js +1 -0
- package/dist/handlers/EvaluateScriptHandler.js +126 -1
- package/dist/handlers/GetConsoleMessageHandler.js +80 -10
- package/dist/handlers/GetNetworkRequestHandler.js +68 -10
- package/dist/handlers/ListConsoleMessagesHandler.js +83 -12
- package/dist/handlers/ListNetworkRequestsHandler.js +67 -11
- package/dist/monitors/ConsoleMonitor.js +47 -0
- package/dist/proxy/ProxyManager.js +267 -0
- package/dist/proxy/index.js +60 -0
- package/dist/proxy/server/CDPEventMonitor.js +263 -0
- package/dist/proxy/server/CDPProxyServer.js +436 -0
- package/dist/proxy/server/ConnectionPool.js +430 -0
- package/dist/proxy/server/FileSystemSecurity.js +358 -0
- package/dist/proxy/server/HealthMonitor.js +242 -0
- package/dist/proxy/server/MessageStore.js +360 -0
- package/dist/proxy/server/PerformanceMonitor.js +277 -0
- package/dist/proxy/server/ProxyAPIServer.js +909 -0
- package/dist/proxy/server/SecurityManager.js +337 -0
- package/dist/proxy/server/WSProxy.js +456 -0
- package/dist/proxy/types/ProxyTypes.js +2 -0
- package/dist/utils/logger.js +256 -18
- package/package.json +7 -1
|
@@ -2,19 +2,44 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GetConsoleMessageHandler = void 0;
|
|
4
4
|
const ConsoleMonitor_1 = require("../monitors/ConsoleMonitor");
|
|
5
|
+
const ProxyClient_1 = require("../client/ProxyClient");
|
|
5
6
|
class GetConsoleMessageHandler {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.name = 'get_console_message';
|
|
8
9
|
this.consoleMonitor = null;
|
|
10
|
+
this.proxyClient = null;
|
|
9
11
|
}
|
|
10
12
|
async execute(client, args) {
|
|
11
13
|
try {
|
|
12
14
|
const params = args;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const proxyResult = await this.tryProxyExecution(params);
|
|
16
|
+
if (proxyResult) {
|
|
17
|
+
return proxyResult;
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
return await this.executeDirectCDP(client, params);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async tryProxyExecution(params) {
|
|
29
|
+
try {
|
|
30
|
+
if (!this.proxyClient) {
|
|
31
|
+
this.proxyClient = new ProxyClient_1.ProxyClient();
|
|
32
|
+
}
|
|
33
|
+
const isProxyAvailable = await this.proxyClient.isProxyAvailable();
|
|
34
|
+
if (!isProxyAvailable) {
|
|
35
|
+
console.warn('⚠️ Proxy server unavailable. Falling back to direct CDP connection.');
|
|
36
|
+
console.warn('⚠️ Note: Direct connection only captures NEW console messages, not historical data.');
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (!this.proxyClient.getConnectionId()) {
|
|
40
|
+
const host = params.host || 'localhost';
|
|
41
|
+
const port = params.port || 9222;
|
|
42
|
+
await this.proxyClient.connect(host, port, params.targetId);
|
|
18
43
|
}
|
|
19
44
|
const filter = {};
|
|
20
45
|
if (params.type) {
|
|
@@ -23,11 +48,15 @@ class GetConsoleMessageHandler {
|
|
|
23
48
|
if (params.textPattern) {
|
|
24
49
|
filter.textPattern = params.textPattern;
|
|
25
50
|
}
|
|
26
|
-
|
|
51
|
+
filter.maxMessages = 1;
|
|
52
|
+
const messages = await this.proxyClient.getConsoleMessages(filter);
|
|
53
|
+
const latestMessage = messages.length > 0 ? messages[messages.length - 1] : null;
|
|
27
54
|
if (!latestMessage) {
|
|
28
55
|
return {
|
|
29
56
|
success: true,
|
|
30
|
-
data: null
|
|
57
|
+
data: null,
|
|
58
|
+
dataSource: 'proxy',
|
|
59
|
+
hasHistoricalData: true
|
|
31
60
|
};
|
|
32
61
|
}
|
|
33
62
|
return {
|
|
@@ -38,15 +67,52 @@ class GetConsoleMessageHandler {
|
|
|
38
67
|
args: latestMessage.args,
|
|
39
68
|
timestamp: latestMessage.timestamp,
|
|
40
69
|
stackTrace: latestMessage.stackTrace
|
|
41
|
-
}
|
|
70
|
+
},
|
|
71
|
+
dataSource: 'proxy',
|
|
72
|
+
hasHistoricalData: true
|
|
42
73
|
};
|
|
43
74
|
}
|
|
44
75
|
catch (error) {
|
|
76
|
+
console.warn('⚠️ Proxy execution failed, falling back to direct CDP:', error instanceof Error ? error.message : error);
|
|
77
|
+
console.warn('⚠️ Note: Direct connection only captures NEW console messages, not historical data.');
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async executeDirectCDP(client, params) {
|
|
82
|
+
if (!this.consoleMonitor) {
|
|
83
|
+
this.consoleMonitor = new ConsoleMonitor_1.ConsoleMonitor(client);
|
|
84
|
+
}
|
|
85
|
+
if (params.startMonitoring || !this.consoleMonitor.isActive()) {
|
|
86
|
+
await this.consoleMonitor.startMonitoring();
|
|
87
|
+
}
|
|
88
|
+
const filter = {};
|
|
89
|
+
if (params.type) {
|
|
90
|
+
filter.types = [params.type];
|
|
91
|
+
}
|
|
92
|
+
if (params.textPattern) {
|
|
93
|
+
filter.textPattern = params.textPattern;
|
|
94
|
+
}
|
|
95
|
+
const latestMessage = this.consoleMonitor.getLatestMessage(filter);
|
|
96
|
+
if (!latestMessage) {
|
|
45
97
|
return {
|
|
46
|
-
success:
|
|
47
|
-
|
|
98
|
+
success: true,
|
|
99
|
+
data: null,
|
|
100
|
+
dataSource: 'direct',
|
|
101
|
+
hasHistoricalData: false
|
|
48
102
|
};
|
|
49
103
|
}
|
|
104
|
+
return {
|
|
105
|
+
success: true,
|
|
106
|
+
data: {
|
|
107
|
+
type: latestMessage.type,
|
|
108
|
+
text: latestMessage.text,
|
|
109
|
+
args: latestMessage.args,
|
|
110
|
+
timestamp: latestMessage.timestamp,
|
|
111
|
+
stackTrace: latestMessage.stackTrace
|
|
112
|
+
},
|
|
113
|
+
dataSource: 'direct',
|
|
114
|
+
hasHistoricalData: false
|
|
115
|
+
};
|
|
50
116
|
}
|
|
51
117
|
validateArgs(args) {
|
|
52
118
|
if (!args || typeof args !== 'object') {
|
|
@@ -85,7 +151,11 @@ Examples:
|
|
|
85
151
|
get_console_message
|
|
86
152
|
get_console_message --type error
|
|
87
153
|
get_console_message --textPattern "API"
|
|
88
|
-
get_console_message --startMonitoring
|
|
154
|
+
get_console_message --startMonitoring
|
|
155
|
+
|
|
156
|
+
Note: This command now uses the proxy server when available, providing access to
|
|
157
|
+
historical console messages from connection establishment. When proxy is unavailable,
|
|
158
|
+
falls back to direct CDP connection (captures only new messages).`;
|
|
89
159
|
}
|
|
90
160
|
}
|
|
91
161
|
exports.GetConsoleMessageHandler = GetConsoleMessageHandler;
|
|
@@ -2,43 +2,101 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GetNetworkRequestHandler = void 0;
|
|
4
4
|
const NetworkMonitor_1 = require("../monitors/NetworkMonitor");
|
|
5
|
+
const ProxyClient_1 = require("../client/ProxyClient");
|
|
5
6
|
class GetNetworkRequestHandler {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.name = 'get_network_request';
|
|
8
9
|
this.networkMonitor = null;
|
|
10
|
+
this.proxyClient = null;
|
|
9
11
|
}
|
|
10
12
|
async execute(client, args) {
|
|
11
13
|
try {
|
|
12
14
|
const params = args;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const proxyResult = await this.tryProxyExecution(params);
|
|
16
|
+
if (proxyResult) {
|
|
17
|
+
return proxyResult;
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
return await this.executeDirectCDP(client, params);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async tryProxyExecution(params) {
|
|
29
|
+
try {
|
|
30
|
+
if (!this.proxyClient) {
|
|
31
|
+
this.proxyClient = new ProxyClient_1.ProxyClient();
|
|
32
|
+
}
|
|
33
|
+
const isProxyAvailable = await this.proxyClient.isProxyAvailable();
|
|
34
|
+
if (!isProxyAvailable) {
|
|
35
|
+
console.warn('⚠️ Proxy server unavailable. Falling back to direct CDP connection.');
|
|
36
|
+
console.warn('⚠️ Note: Direct connection only captures NEW network requests, not historical data.');
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (!this.proxyClient.getConnectionId()) {
|
|
40
|
+
const host = params.host || 'localhost';
|
|
41
|
+
const port = params.port || 9222;
|
|
42
|
+
await this.proxyClient.connect(host, port, params.targetId);
|
|
18
43
|
}
|
|
19
44
|
const filter = params.filter ? {
|
|
20
45
|
methods: params.filter.methods,
|
|
21
46
|
urlPattern: params.filter.urlPattern,
|
|
22
47
|
statusCodes: params.filter.statusCodes,
|
|
23
|
-
|
|
24
|
-
|
|
48
|
+
maxRequests: 1,
|
|
49
|
+
} : { maxRequests: 1 };
|
|
50
|
+
const requests = await this.proxyClient.getNetworkRequests(filter);
|
|
51
|
+
const latestRequest = requests.length > 0 ? requests[requests.length - 1] : null;
|
|
25
52
|
if (!latestRequest) {
|
|
26
53
|
return {
|
|
27
54
|
success: true,
|
|
28
|
-
data: null
|
|
55
|
+
data: null,
|
|
56
|
+
dataSource: 'proxy',
|
|
57
|
+
hasHistoricalData: true
|
|
29
58
|
};
|
|
30
59
|
}
|
|
31
60
|
return {
|
|
32
61
|
success: true,
|
|
33
|
-
data: latestRequest
|
|
62
|
+
data: latestRequest,
|
|
63
|
+
dataSource: 'proxy',
|
|
64
|
+
hasHistoricalData: true
|
|
34
65
|
};
|
|
35
66
|
}
|
|
36
67
|
catch (error) {
|
|
68
|
+
console.warn('⚠️ Proxy execution failed, falling back to direct CDP:', error instanceof Error ? error.message : error);
|
|
69
|
+
console.warn('⚠️ Note: Direct connection only captures NEW network requests, not historical data.');
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async executeDirectCDP(client, params) {
|
|
74
|
+
if (!this.networkMonitor) {
|
|
75
|
+
this.networkMonitor = new NetworkMonitor_1.NetworkMonitor(client);
|
|
76
|
+
}
|
|
77
|
+
if (!this.networkMonitor.isActive()) {
|
|
78
|
+
await this.networkMonitor.startMonitoring();
|
|
79
|
+
}
|
|
80
|
+
const filter = params.filter ? {
|
|
81
|
+
methods: params.filter.methods,
|
|
82
|
+
urlPattern: params.filter.urlPattern,
|
|
83
|
+
statusCodes: params.filter.statusCodes,
|
|
84
|
+
} : undefined;
|
|
85
|
+
const latestRequest = this.networkMonitor.getLatestRequest(filter);
|
|
86
|
+
if (!latestRequest) {
|
|
37
87
|
return {
|
|
38
|
-
success:
|
|
39
|
-
|
|
88
|
+
success: true,
|
|
89
|
+
data: null,
|
|
90
|
+
dataSource: 'direct',
|
|
91
|
+
hasHistoricalData: false
|
|
40
92
|
};
|
|
41
93
|
}
|
|
94
|
+
return {
|
|
95
|
+
success: true,
|
|
96
|
+
data: latestRequest,
|
|
97
|
+
dataSource: 'direct',
|
|
98
|
+
hasHistoricalData: false
|
|
99
|
+
};
|
|
42
100
|
}
|
|
43
101
|
getNetworkMonitor() {
|
|
44
102
|
return this.networkMonitor;
|
|
@@ -2,19 +2,44 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ListConsoleMessagesHandler = void 0;
|
|
4
4
|
const ConsoleMonitor_1 = require("../monitors/ConsoleMonitor");
|
|
5
|
+
const ProxyClient_1 = require("../client/ProxyClient");
|
|
5
6
|
class ListConsoleMessagesHandler {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.name = 'list_console_messages';
|
|
8
9
|
this.consoleMonitor = null;
|
|
10
|
+
this.proxyClient = null;
|
|
9
11
|
}
|
|
10
12
|
async execute(client, args) {
|
|
11
13
|
try {
|
|
12
14
|
const params = args;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const proxyResult = await this.tryProxyExecution(params);
|
|
16
|
+
if (proxyResult) {
|
|
17
|
+
return proxyResult;
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
return await this.executeDirectCDP(client, params);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async tryProxyExecution(params) {
|
|
29
|
+
try {
|
|
30
|
+
if (!this.proxyClient) {
|
|
31
|
+
this.proxyClient = new ProxyClient_1.ProxyClient();
|
|
32
|
+
}
|
|
33
|
+
const isProxyAvailable = await this.proxyClient.isProxyAvailable();
|
|
34
|
+
if (!isProxyAvailable) {
|
|
35
|
+
console.warn('⚠️ Proxy server unavailable. Falling back to direct CDP connection.');
|
|
36
|
+
console.warn('⚠️ Note: Direct connection only captures NEW console messages, not historical data.');
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (!this.proxyClient.getConnectionId()) {
|
|
40
|
+
const host = params.host || 'localhost';
|
|
41
|
+
const port = params.port || 9222;
|
|
42
|
+
await this.proxyClient.connect(host, port, params.targetId);
|
|
18
43
|
}
|
|
19
44
|
const filter = {};
|
|
20
45
|
if (params.types && params.types.length > 0) {
|
|
@@ -32,7 +57,7 @@ class ListConsoleMessagesHandler {
|
|
|
32
57
|
if (params.endTime) {
|
|
33
58
|
filter.endTime = params.endTime;
|
|
34
59
|
}
|
|
35
|
-
const messages = this.
|
|
60
|
+
const messages = await this.proxyClient.getConsoleMessages(filter);
|
|
36
61
|
return {
|
|
37
62
|
success: true,
|
|
38
63
|
data: {
|
|
@@ -44,16 +69,58 @@ class ListConsoleMessagesHandler {
|
|
|
44
69
|
stackTrace: msg.stackTrace
|
|
45
70
|
})),
|
|
46
71
|
totalCount: messages.length,
|
|
47
|
-
isMonitoring:
|
|
48
|
-
}
|
|
72
|
+
isMonitoring: true
|
|
73
|
+
},
|
|
74
|
+
dataSource: 'proxy',
|
|
75
|
+
hasHistoricalData: true
|
|
49
76
|
};
|
|
50
77
|
}
|
|
51
78
|
catch (error) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
console.warn('⚠️ Proxy execution failed, falling back to direct CDP:', error instanceof Error ? error.message : error);
|
|
80
|
+
console.warn('⚠️ Note: Direct connection only captures NEW console messages, not historical data.');
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async executeDirectCDP(client, params) {
|
|
85
|
+
if (!this.consoleMonitor) {
|
|
86
|
+
this.consoleMonitor = new ConsoleMonitor_1.ConsoleMonitor(client);
|
|
87
|
+
}
|
|
88
|
+
if (params.startMonitoring || !this.consoleMonitor.isActive()) {
|
|
89
|
+
await this.consoleMonitor.startMonitoring();
|
|
90
|
+
}
|
|
91
|
+
const filter = {};
|
|
92
|
+
if (params.types && params.types.length > 0) {
|
|
93
|
+
filter.types = params.types;
|
|
94
|
+
}
|
|
95
|
+
if (params.textPattern) {
|
|
96
|
+
filter.textPattern = params.textPattern;
|
|
97
|
+
}
|
|
98
|
+
if (params.maxMessages && params.maxMessages > 0) {
|
|
99
|
+
filter.maxMessages = params.maxMessages;
|
|
100
|
+
}
|
|
101
|
+
if (params.startTime) {
|
|
102
|
+
filter.startTime = params.startTime;
|
|
103
|
+
}
|
|
104
|
+
if (params.endTime) {
|
|
105
|
+
filter.endTime = params.endTime;
|
|
56
106
|
}
|
|
107
|
+
const messages = this.consoleMonitor.getMessages(filter);
|
|
108
|
+
return {
|
|
109
|
+
success: true,
|
|
110
|
+
data: {
|
|
111
|
+
messages: messages.map(msg => ({
|
|
112
|
+
type: msg.type,
|
|
113
|
+
text: msg.text,
|
|
114
|
+
args: msg.args,
|
|
115
|
+
timestamp: msg.timestamp,
|
|
116
|
+
stackTrace: msg.stackTrace
|
|
117
|
+
})),
|
|
118
|
+
totalCount: messages.length,
|
|
119
|
+
isMonitoring: this.consoleMonitor.isActive()
|
|
120
|
+
},
|
|
121
|
+
dataSource: 'direct',
|
|
122
|
+
hasHistoricalData: false
|
|
123
|
+
};
|
|
57
124
|
}
|
|
58
125
|
validateArgs(args) {
|
|
59
126
|
if (!args || typeof args !== 'object') {
|
|
@@ -108,7 +175,11 @@ Examples:
|
|
|
108
175
|
list_console_messages
|
|
109
176
|
list_console_messages --types error,warn
|
|
110
177
|
list_console_messages --textPattern "API" --maxMessages 10
|
|
111
|
-
list_console_messages --startTime 1640995200000
|
|
178
|
+
list_console_messages --startTime 1640995200000
|
|
179
|
+
|
|
180
|
+
Note: This command now uses the proxy server when available, providing access to
|
|
181
|
+
historical console messages from connection establishment. When proxy is unavailable,
|
|
182
|
+
falls back to direct CDP connection (captures only new messages).`;
|
|
112
183
|
}
|
|
113
184
|
}
|
|
114
185
|
exports.ListConsoleMessagesHandler = ListConsoleMessagesHandler;
|
|
@@ -2,19 +2,47 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ListNetworkRequestsHandler = void 0;
|
|
4
4
|
const NetworkMonitor_1 = require("../monitors/NetworkMonitor");
|
|
5
|
+
const ProxyClient_1 = require("../client/ProxyClient");
|
|
5
6
|
class ListNetworkRequestsHandler {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.name = 'list_network_requests';
|
|
8
9
|
this.networkMonitor = null;
|
|
10
|
+
this.proxyClient = null;
|
|
9
11
|
}
|
|
10
12
|
async execute(client, args) {
|
|
11
13
|
try {
|
|
12
14
|
const params = args;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const proxyResult = await this.tryProxyExecution(params);
|
|
16
|
+
if (proxyResult) {
|
|
17
|
+
return proxyResult;
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
return await this.executeDirectCDP(client, params);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async tryProxyExecution(params) {
|
|
29
|
+
try {
|
|
30
|
+
if (!this.proxyClient) {
|
|
31
|
+
this.proxyClient = new ProxyClient_1.ProxyClient();
|
|
32
|
+
}
|
|
33
|
+
const isProxyAvailable = await this.proxyClient.isProxyAvailable();
|
|
34
|
+
if (!isProxyAvailable) {
|
|
35
|
+
const proxyStarted = await this.proxyClient.ensureProxyRunning();
|
|
36
|
+
if (!proxyStarted) {
|
|
37
|
+
console.warn('⚠️ Proxy server unavailable. Falling back to direct CDP connection.');
|
|
38
|
+
console.warn('⚠️ Note: Direct connection only captures NEW network requests, not historical data.');
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!this.proxyClient.getConnectionId()) {
|
|
43
|
+
const host = params.host || 'localhost';
|
|
44
|
+
const port = params.port || 9222;
|
|
45
|
+
await this.proxyClient.connect(host, port, params.targetId);
|
|
18
46
|
}
|
|
19
47
|
const filter = params.filter ? {
|
|
20
48
|
methods: params.filter.methods,
|
|
@@ -24,22 +52,50 @@ class ListNetworkRequestsHandler {
|
|
|
24
52
|
startTime: params.filter.startTime,
|
|
25
53
|
endTime: params.filter.endTime,
|
|
26
54
|
} : undefined;
|
|
27
|
-
const requests = this.
|
|
55
|
+
const requests = await this.proxyClient.getNetworkRequests(filter);
|
|
28
56
|
return {
|
|
29
57
|
success: true,
|
|
30
58
|
data: {
|
|
31
59
|
requests,
|
|
32
60
|
count: requests.length,
|
|
33
|
-
isMonitoring:
|
|
34
|
-
}
|
|
61
|
+
isMonitoring: true
|
|
62
|
+
},
|
|
63
|
+
dataSource: 'proxy',
|
|
64
|
+
hasHistoricalData: true
|
|
35
65
|
};
|
|
36
66
|
}
|
|
37
67
|
catch (error) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
68
|
+
console.warn('⚠️ Proxy execution failed, falling back to direct CDP:', error instanceof Error ? error.message : error);
|
|
69
|
+
console.warn('⚠️ Note: Direct connection only captures NEW network requests, not historical data.');
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async executeDirectCDP(client, params) {
|
|
74
|
+
if (!this.networkMonitor) {
|
|
75
|
+
this.networkMonitor = new NetworkMonitor_1.NetworkMonitor(client);
|
|
76
|
+
}
|
|
77
|
+
if (!this.networkMonitor.isActive()) {
|
|
78
|
+
await this.networkMonitor.startMonitoring();
|
|
42
79
|
}
|
|
80
|
+
const filter = params.filter ? {
|
|
81
|
+
methods: params.filter.methods,
|
|
82
|
+
urlPattern: params.filter.urlPattern,
|
|
83
|
+
statusCodes: params.filter.statusCodes,
|
|
84
|
+
maxRequests: params.filter.maxRequests,
|
|
85
|
+
startTime: params.filter.startTime,
|
|
86
|
+
endTime: params.filter.endTime,
|
|
87
|
+
} : undefined;
|
|
88
|
+
const requests = this.networkMonitor.getRequests(filter);
|
|
89
|
+
return {
|
|
90
|
+
success: true,
|
|
91
|
+
data: {
|
|
92
|
+
requests,
|
|
93
|
+
count: requests.length,
|
|
94
|
+
isMonitoring: this.networkMonitor.isActive()
|
|
95
|
+
},
|
|
96
|
+
dataSource: 'direct',
|
|
97
|
+
hasHistoricalData: false
|
|
98
|
+
};
|
|
43
99
|
}
|
|
44
100
|
getNetworkMonitor() {
|
|
45
101
|
return this.networkMonitor;
|
|
@@ -13,10 +13,19 @@ class ConsoleMonitor {
|
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
await this.client.send('Runtime.enable');
|
|
16
|
+
try {
|
|
17
|
+
await this.client.send('Log.enable');
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.warn('Log domain not available:', error);
|
|
21
|
+
}
|
|
16
22
|
this.messageHandler = (params) => {
|
|
17
23
|
this.handleConsoleMessage(params);
|
|
18
24
|
};
|
|
19
25
|
this.client.on('Runtime.consoleAPICalled', this.messageHandler);
|
|
26
|
+
this.client.on('Log.entryAdded', (params) => {
|
|
27
|
+
this.handleLogEntry(params);
|
|
28
|
+
});
|
|
20
29
|
this.isMonitoring = true;
|
|
21
30
|
}
|
|
22
31
|
async stopMonitoring() {
|
|
@@ -82,6 +91,31 @@ class ConsoleMonitor {
|
|
|
82
91
|
console.error('Error handling console message:', error);
|
|
83
92
|
}
|
|
84
93
|
}
|
|
94
|
+
handleLogEntry(params) {
|
|
95
|
+
try {
|
|
96
|
+
const logParams = params;
|
|
97
|
+
const entry = logParams.entry;
|
|
98
|
+
const message = {
|
|
99
|
+
type: this.mapLogLevel(entry.level),
|
|
100
|
+
text: entry.text,
|
|
101
|
+
args: [entry.text],
|
|
102
|
+
timestamp: entry.timestamp,
|
|
103
|
+
stackTrace: entry.url && entry.lineNumber ? [{
|
|
104
|
+
functionName: '<unknown>',
|
|
105
|
+
url: entry.url,
|
|
106
|
+
lineNumber: entry.lineNumber,
|
|
107
|
+
columnNumber: 0
|
|
108
|
+
}] : undefined
|
|
109
|
+
};
|
|
110
|
+
this.messages.push(message);
|
|
111
|
+
if (this.messages.length > 1000) {
|
|
112
|
+
this.messages = this.messages.slice(-1000);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error('Error handling log entry:', error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
85
119
|
mapConsoleType(cdpType) {
|
|
86
120
|
switch (cdpType) {
|
|
87
121
|
case 'log':
|
|
@@ -98,6 +132,19 @@ class ConsoleMonitor {
|
|
|
98
132
|
return 'log';
|
|
99
133
|
}
|
|
100
134
|
}
|
|
135
|
+
mapLogLevel(logLevel) {
|
|
136
|
+
switch (logLevel.toLowerCase()) {
|
|
137
|
+
case 'verbose':
|
|
138
|
+
case 'info':
|
|
139
|
+
return 'info';
|
|
140
|
+
case 'warning':
|
|
141
|
+
return 'warn';
|
|
142
|
+
case 'error':
|
|
143
|
+
return 'error';
|
|
144
|
+
default:
|
|
145
|
+
return 'log';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
101
148
|
formatConsoleArgs(args) {
|
|
102
149
|
return args.map(arg => {
|
|
103
150
|
if (arg.value !== undefined) {
|