chrome-cdp-cli 2.1.3 → 2.1.4
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.
|
@@ -568,7 +568,7 @@ class CommandSchemaRegistry {
|
|
|
568
568
|
name: "log",
|
|
569
569
|
aliases: ["console"],
|
|
570
570
|
description: "Follow console messages in real-time",
|
|
571
|
-
usage: "cdp log [options]",
|
|
571
|
+
usage: "cdp log [PATTERN] [options]",
|
|
572
572
|
examples: [
|
|
573
573
|
{ command: "cdp log", description: "Follow all console messages" },
|
|
574
574
|
{
|
|
@@ -576,8 +576,20 @@ class CommandSchemaRegistry {
|
|
|
576
576
|
description: "Follow only errors and warnings",
|
|
577
577
|
},
|
|
578
578
|
{
|
|
579
|
-
command:
|
|
580
|
-
description: "Follow messages matching /
|
|
579
|
+
command: "cdp log '\\[AI'",
|
|
580
|
+
description: "Follow messages matching regex /\\[AI/i",
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
command: "cdp log -e error -e warn",
|
|
584
|
+
description: "Follow messages matching 'error' OR 'warn'",
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
command: "cdp log -F '[AI'",
|
|
588
|
+
description: "Follow messages containing literal string '[AI'",
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
command: "cdp log -v 'debug'",
|
|
592
|
+
description: "Follow messages NOT matching 'debug'",
|
|
581
593
|
},
|
|
582
594
|
{
|
|
583
595
|
command: "cdp log --format json",
|
|
@@ -592,9 +604,28 @@ class CommandSchemaRegistry {
|
|
|
592
604
|
type: "string",
|
|
593
605
|
},
|
|
594
606
|
{
|
|
595
|
-
name: "
|
|
596
|
-
|
|
607
|
+
name: "expression",
|
|
608
|
+
short: "e",
|
|
609
|
+
description: "Pattern to match (regex by default). May be specified multiple times (OR logic).",
|
|
597
610
|
type: "string",
|
|
611
|
+
multiple: true,
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
name: "fixed-strings",
|
|
615
|
+
short: "F",
|
|
616
|
+
description: "Treat pattern(s) as literal strings, not regexps",
|
|
617
|
+
type: "boolean",
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
name: "invert-match",
|
|
621
|
+
short: "v",
|
|
622
|
+
description: "Output messages that do NOT match the pattern",
|
|
623
|
+
type: "boolean",
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
name: "case-sensitive",
|
|
627
|
+
description: "Match is case-sensitive (default: case-insensitive)",
|
|
628
|
+
type: "boolean",
|
|
598
629
|
},
|
|
599
630
|
{
|
|
600
631
|
name: "follow",
|
|
@@ -609,7 +640,14 @@ class CommandSchemaRegistry {
|
|
|
609
640
|
choices: ["text", "json", "pretty"],
|
|
610
641
|
},
|
|
611
642
|
],
|
|
612
|
-
arguments: [
|
|
643
|
+
arguments: [
|
|
644
|
+
{
|
|
645
|
+
name: "pattern",
|
|
646
|
+
description: "Pattern to match (regex by default, case-insensitive)",
|
|
647
|
+
type: "string",
|
|
648
|
+
required: false,
|
|
649
|
+
},
|
|
650
|
+
],
|
|
613
651
|
});
|
|
614
652
|
this.registerCommand({
|
|
615
653
|
name: "network",
|
|
@@ -20,21 +20,44 @@ class ListConsoleMessagesHandler {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
buildMatcher(params) {
|
|
24
|
+
const rawExpressions = params.expression
|
|
25
|
+
? Array.isArray(params.expression)
|
|
26
|
+
? params.expression
|
|
27
|
+
: [params.expression]
|
|
28
|
+
: [];
|
|
29
|
+
const patterns = [
|
|
30
|
+
...(params.pattern ? [params.pattern] : []),
|
|
31
|
+
...rawExpressions,
|
|
32
|
+
];
|
|
33
|
+
if (patterns.length === 0)
|
|
34
|
+
return () => true;
|
|
35
|
+
const fixedStrings = params.fixedStrings ?? params["fixed-strings"] ?? false;
|
|
36
|
+
const caseSensitive = params.caseSensitive ?? params["case-sensitive"] ?? false;
|
|
37
|
+
const invertMatch = params.invertMatch ?? params["invert-match"] ?? false;
|
|
38
|
+
const flags = caseSensitive ? "" : "i";
|
|
39
|
+
const tests = patterns.map((p) => {
|
|
40
|
+
if (fixedStrings) {
|
|
41
|
+
return caseSensitive
|
|
42
|
+
? (text) => text.includes(p)
|
|
43
|
+
: (text) => text.toLowerCase().includes(p.toLowerCase());
|
|
44
|
+
}
|
|
45
|
+
const re = new RegExp(p, flags);
|
|
46
|
+
return (text) => re.test(text);
|
|
47
|
+
});
|
|
48
|
+
const anyMatch = (text) => tests.some((t) => t(text));
|
|
49
|
+
return invertMatch ? (text) => !anyMatch(text) : anyMatch;
|
|
50
|
+
}
|
|
23
51
|
async executeFollowMode(client, params) {
|
|
24
52
|
if (!this.consoleMonitor) {
|
|
25
53
|
this.consoleMonitor = new ConsoleMonitor_1.ConsoleMonitor(client);
|
|
26
54
|
}
|
|
27
55
|
await this.consoleMonitor.startMonitoring();
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
filter.types = params.types;
|
|
31
|
-
}
|
|
32
|
-
if (params.textPattern) {
|
|
33
|
-
filter.textPattern = params.textPattern;
|
|
34
|
-
}
|
|
56
|
+
const typeFilter = params.types && params.types.length > 0 ? params.types : null;
|
|
57
|
+
const matchText = this.buildMatcher(params);
|
|
35
58
|
const outputFormat = params.format || "text";
|
|
36
59
|
const messageCallback = (message) => {
|
|
37
|
-
if (!this.shouldOutputMessage(message,
|
|
60
|
+
if (!this.shouldOutputMessage(message, typeFilter, matchText)) {
|
|
38
61
|
return;
|
|
39
62
|
}
|
|
40
63
|
this.outputMessage(message, outputFormat);
|
|
@@ -69,19 +92,11 @@ class ListConsoleMessagesHandler {
|
|
|
69
92
|
isLongRunning: true,
|
|
70
93
|
};
|
|
71
94
|
}
|
|
72
|
-
shouldOutputMessage(message,
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (filter.textPattern) {
|
|
79
|
-
const pattern = new RegExp(filter.textPattern, "i");
|
|
80
|
-
if (!pattern.test(message.text)) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
95
|
+
shouldOutputMessage(message, typeFilter, matchText) {
|
|
96
|
+
if (typeFilter && !typeFilter.includes(message.type)) {
|
|
97
|
+
return false;
|
|
83
98
|
}
|
|
84
|
-
return
|
|
99
|
+
return matchText(message.text);
|
|
85
100
|
}
|
|
86
101
|
outputMessage(message, format) {
|
|
87
102
|
switch (format) {
|
|
@@ -142,10 +157,16 @@ class ListConsoleMessagesHandler {
|
|
|
142
157
|
return false;
|
|
143
158
|
}
|
|
144
159
|
}
|
|
145
|
-
if (params.
|
|
146
|
-
typeof params.textPattern !== "string") {
|
|
160
|
+
if (params.pattern !== undefined && typeof params.pattern !== "string") {
|
|
147
161
|
return false;
|
|
148
162
|
}
|
|
163
|
+
if (params.expression !== undefined) {
|
|
164
|
+
const exprs = Array.isArray(params.expression)
|
|
165
|
+
? params.expression
|
|
166
|
+
: [params.expression];
|
|
167
|
+
if (!exprs.every((e) => typeof e === "string"))
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
149
170
|
if (params.format !== undefined) {
|
|
150
171
|
const validFormats = ["text", "json", "pretty"];
|
|
151
172
|
if (typeof params.format !== "string" ||
|
|
@@ -159,21 +180,30 @@ class ListConsoleMessagesHandler {
|
|
|
159
180
|
return `log - Follow console messages in real-time
|
|
160
181
|
|
|
161
182
|
Usage:
|
|
162
|
-
cdp log [options]
|
|
183
|
+
cdp log [PATTERN] [options]
|
|
184
|
+
|
|
185
|
+
Arguments:
|
|
186
|
+
PATTERN Pattern to match (regex, case-insensitive by default)
|
|
163
187
|
|
|
164
188
|
Options:
|
|
165
|
-
--
|
|
166
|
-
--
|
|
167
|
-
--
|
|
189
|
+
-e, --expression <pat> Pattern to match; may be used multiple times (OR logic)
|
|
190
|
+
-F, --fixed-strings Treat pattern(s) as literal strings, not regexps
|
|
191
|
+
-v, --invert-match Output messages that do NOT match the pattern
|
|
192
|
+
--case-sensitive Case-sensitive matching (default: case-insensitive)
|
|
193
|
+
--types <types> Filter by message types (log,info,warn,error,debug)
|
|
194
|
+
--format <format> Output format: text, json, or pretty (default: text)
|
|
168
195
|
-f, --follow Alias flag (follow mode is always active)
|
|
169
196
|
|
|
170
197
|
Examples:
|
|
171
|
-
cdp log
|
|
172
|
-
cdp log
|
|
173
|
-
cdp log
|
|
174
|
-
cdp log
|
|
175
|
-
cdp log
|
|
176
|
-
cdp log
|
|
198
|
+
cdp log # Follow all console messages
|
|
199
|
+
cdp log '\\[AI' # Messages matching regex /\\[AI/i
|
|
200
|
+
cdp log -e error -e warn # Messages containing 'error' OR 'warn'
|
|
201
|
+
cdp log -F '[AI' # Messages containing literal '[AI'
|
|
202
|
+
cdp log -v debug # Messages NOT containing 'debug'
|
|
203
|
+
cdp log '404' --case-sensitive # Case-sensitive match
|
|
204
|
+
cdp log --types error,warn # Filter by type
|
|
205
|
+
cdp log --format json # Output as JSON (one object per line)
|
|
206
|
+
cdp log --format pretty # Colorized output
|
|
177
207
|
|
|
178
208
|
Note:
|
|
179
209
|
This command runs continuously and streams console messages in real-time.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrome-cdp-cli",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "Browser automation CLI via Chrome DevTools Protocol. Designed for developers and AI assistants - combines dedicated commands for common tasks with flexible JavaScript execution for complex scenarios. Features: element interaction, screenshots, DOM snapshots, console/network monitoring. Built-in IDE integration for Cursor and Claude.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|