browser-cdp 0.1.0 → 0.2.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 +10 -10
- package/cli.js +2 -2
- package/nav.js +8 -3
- package/package.json +1 -1
- package/start.js +21 -29
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ npm install -g browser-cdp
|
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
# Start browser with CDP enabled
|
|
15
|
-
browser-cdp start [browser] [--
|
|
15
|
+
browser-cdp start [browser] [--isolated] [--port=PORT]
|
|
16
16
|
|
|
17
17
|
# Navigate to URL
|
|
18
18
|
browser-cdp nav <url> [--new]
|
|
@@ -38,8 +38,8 @@ browser-cdp pick '<message>'
|
|
|
38
38
|
## Examples
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
# Start Brave with
|
|
42
|
-
browser-cdp start brave
|
|
41
|
+
# Start Brave with real profile
|
|
42
|
+
browser-cdp start brave
|
|
43
43
|
|
|
44
44
|
# Start Chrome on custom port
|
|
45
45
|
DEBUG_PORT=9333 browser-cdp start
|
|
@@ -74,12 +74,12 @@ browser-cdp nav https://example.com
|
|
|
74
74
|
|
|
75
75
|
## Supported Browsers
|
|
76
76
|
|
|
77
|
-
| Browser | Command |
|
|
78
|
-
|
|
79
|
-
| Chrome | `chrome` (default) |
|
|
80
|
-
| Brave | `brave` |
|
|
81
|
-
| Comet | `comet` |
|
|
82
|
-
| Edge | `edge` |
|
|
77
|
+
| Browser | Command |
|
|
78
|
+
|---------|---------|
|
|
79
|
+
| Chrome | `chrome` (default) |
|
|
80
|
+
| Brave | `brave` |
|
|
81
|
+
| Comet | `comet` |
|
|
82
|
+
| Edge | `edge` |
|
|
83
83
|
|
|
84
84
|
## Platform Support
|
|
85
85
|
|
|
@@ -97,7 +97,7 @@ Use `BROWSER_PATH` env var to override if your browser is installed elsewhere.
|
|
|
97
97
|
| Aspect | browser-cdp | Playwright Test Mode |
|
|
98
98
|
|--------|-------------|---------------------|
|
|
99
99
|
| Browser | Your installed Chrome/Brave/etc | Bundled Chromium |
|
|
100
|
-
| Profile |
|
|
100
|
+
| Profile | Real cookies/logins by default | Fresh test profile |
|
|
101
101
|
| Detection | Not detectable as automation | Automation flags present |
|
|
102
102
|
| Use case | Real-world testing, scraping | Isolated E2E tests |
|
|
103
103
|
|
package/cli.js
CHANGED
|
@@ -17,7 +17,7 @@ function printUsage() {
|
|
|
17
17
|
console.log("Usage: browser-cdp <command> [options]");
|
|
18
18
|
console.log("");
|
|
19
19
|
console.log("Commands:");
|
|
20
|
-
console.log(" start [browser] Start browser with CDP
|
|
20
|
+
console.log(" start [browser] Start browser with CDP (uses real profile)");
|
|
21
21
|
console.log(" nav <url> Navigate to URL");
|
|
22
22
|
console.log(" eval '<code>' Evaluate JavaScript in page");
|
|
23
23
|
console.log(" screenshot Take screenshot of current page");
|
|
@@ -29,7 +29,7 @@ function printUsage() {
|
|
|
29
29
|
console.log(" BROWSER_PATH Custom browser executable path");
|
|
30
30
|
console.log("");
|
|
31
31
|
console.log("Examples:");
|
|
32
|
-
console.log(" browser-cdp start brave
|
|
32
|
+
console.log(" browser-cdp start brave");
|
|
33
33
|
console.log(" browser-cdp nav https://google.com");
|
|
34
34
|
console.log(" browser-cdp eval 'document.title'");
|
|
35
35
|
console.log(" browser-cdp screenshot");
|
package/nav.js
CHANGED
|
@@ -4,14 +4,19 @@ import { chromium } from "playwright";
|
|
|
4
4
|
|
|
5
5
|
const DEFAULT_PORT = process.env.DEBUG_PORT || 9222;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
let url = process.argv[2];
|
|
8
8
|
const newTab = process.argv[3] === "--new";
|
|
9
9
|
|
|
10
|
+
// Add protocol if missing
|
|
11
|
+
if (url && !url.match(/^https?:\/\//i)) {
|
|
12
|
+
url = "https://" + url;
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
if (!url) {
|
|
11
16
|
console.log("Usage: nav.js <url> [--new]");
|
|
12
17
|
console.log("\nExamples:");
|
|
13
|
-
console.log(" nav.js
|
|
14
|
-
console.log(" nav.js
|
|
18
|
+
console.log(" nav.js example.com # Navigate current tab");
|
|
19
|
+
console.log(" nav.js example.com --new # Open in new tab");
|
|
15
20
|
process.exit(1);
|
|
16
21
|
}
|
|
17
22
|
|
package/package.json
CHANGED
package/start.js
CHANGED
|
@@ -51,23 +51,23 @@ const BROWSERS = {
|
|
|
51
51
|
const DEFAULT_PORT = 9222;
|
|
52
52
|
|
|
53
53
|
function printUsage() {
|
|
54
|
-
console.log("Usage: start.js [browser] [--
|
|
54
|
+
console.log("Usage: start.js [browser] [--isolated] [--port=PORT]");
|
|
55
55
|
console.log("\nBrowsers:");
|
|
56
56
|
console.log(" chrome - Google Chrome (default)");
|
|
57
57
|
console.log(" brave - Brave Browser");
|
|
58
58
|
console.log(" comet - Comet Browser");
|
|
59
59
|
console.log(" edge - Microsoft Edge");
|
|
60
60
|
console.log("\nOptions:");
|
|
61
|
-
console.log(" --
|
|
62
|
-
console.log(" --port=N
|
|
61
|
+
console.log(" --isolated Use isolated profile (default: real profile)");
|
|
62
|
+
console.log(" --port=N Use custom debugging port (default: 9222)");
|
|
63
63
|
console.log("\nEnvironment variables:");
|
|
64
64
|
console.log(" BROWSER Default browser (chrome, brave, comet, edge)");
|
|
65
65
|
console.log(" BROWSER_PATH Custom browser executable path");
|
|
66
66
|
console.log(" DEBUG_PORT Custom debugging port");
|
|
67
67
|
console.log("\nExamples:");
|
|
68
|
-
console.log(" start.js # Start Chrome with
|
|
69
|
-
console.log(" start.js brave
|
|
70
|
-
console.log(" start.js comet
|
|
68
|
+
console.log(" start.js # Start Chrome with real profile");
|
|
69
|
+
console.log(" start.js brave # Start Brave with real profile");
|
|
70
|
+
console.log(" start.js comet --isolated # Start Comet with isolated profile");
|
|
71
71
|
console.log(" start.js --port=9333 # Start Chrome on port 9333");
|
|
72
72
|
process.exit(1);
|
|
73
73
|
}
|
|
@@ -75,14 +75,14 @@ function printUsage() {
|
|
|
75
75
|
// Parse arguments
|
|
76
76
|
const args = process.argv.slice(2);
|
|
77
77
|
let browserName = process.env.BROWSER || "chrome";
|
|
78
|
-
let
|
|
78
|
+
let isolated = false;
|
|
79
79
|
let port = parseInt(process.env.DEBUG_PORT) || DEFAULT_PORT;
|
|
80
80
|
|
|
81
81
|
for (const arg of args) {
|
|
82
82
|
if (arg === "--help" || arg === "-h") {
|
|
83
83
|
printUsage();
|
|
84
|
-
} else if (arg === "--
|
|
85
|
-
|
|
84
|
+
} else if (arg === "--isolated") {
|
|
85
|
+
isolated = true;
|
|
86
86
|
} else if (arg.startsWith("--port=")) {
|
|
87
87
|
port = parseInt(arg.split("=")[1]);
|
|
88
88
|
} else if (BROWSERS[arg]) {
|
|
@@ -137,28 +137,22 @@ try {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
//
|
|
141
|
-
const
|
|
142
|
-
? `${process.env.HOME}/Library/Caches`
|
|
143
|
-
: `${process.env.HOME}/.cache`;
|
|
144
|
-
const profileDir = `${cacheBase}/browser-cdp/${browserName}`;
|
|
145
|
-
execFileSync("mkdir", ["-p", profileDir], { stdio: "ignore" });
|
|
140
|
+
// Build browser arguments
|
|
141
|
+
const browserArgs = [`--remote-debugging-port=${port}`];
|
|
146
142
|
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
console.warn("Warning: Could not sync profile, using fresh profile");
|
|
155
|
-
}
|
|
143
|
+
if (isolated) {
|
|
144
|
+
const cacheBase = isMac
|
|
145
|
+
? `${process.env.HOME}/Library/Caches`
|
|
146
|
+
: `${process.env.HOME}/.cache`;
|
|
147
|
+
const profileDir = `${cacheBase}/browser-cdp/${browserName}`;
|
|
148
|
+
execFileSync("mkdir", ["-p", profileDir], { stdio: "ignore" });
|
|
149
|
+
browserArgs.push(`--user-data-dir=${profileDir}`);
|
|
156
150
|
}
|
|
157
151
|
|
|
158
152
|
// Start browser
|
|
159
|
-
console.log(`Starting ${browserConfig.name} on port ${port}...`);
|
|
153
|
+
console.log(`Starting ${browserConfig.name} on port ${port}${isolated ? " (isolated)" : ""}...`);
|
|
160
154
|
|
|
161
|
-
spawn(browserPath,
|
|
155
|
+
spawn(browserPath, browserArgs, {
|
|
162
156
|
detached: true,
|
|
163
157
|
stdio: "ignore",
|
|
164
158
|
}).unref();
|
|
@@ -181,6 +175,4 @@ if (!connected) {
|
|
|
181
175
|
process.exit(1);
|
|
182
176
|
}
|
|
183
177
|
|
|
184
|
-
console.log(
|
|
185
|
-
`${browserConfig.name} started on :${port}${useProfile ? " with your profile" : ""}`
|
|
186
|
-
);
|
|
178
|
+
console.log(`${browserConfig.name} started on :${port}${isolated ? " (isolated)" : ""}`);
|