browser-cdp 0.2.0 → 0.2.1
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/cli.js +13 -1
- package/package.json +1 -1
- package/start.js +24 -0
package/cli.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8"));
|
|
9
|
+
|
|
3
10
|
const command = process.argv[2];
|
|
4
11
|
const args = process.argv.slice(3);
|
|
5
12
|
|
|
@@ -12,7 +19,7 @@ const commands = {
|
|
|
12
19
|
};
|
|
13
20
|
|
|
14
21
|
function printUsage() {
|
|
15
|
-
console.log(
|
|
22
|
+
console.log(`browser-cdp v${pkg.version} - Browser automation via Chrome DevTools Protocol`);
|
|
16
23
|
console.log("");
|
|
17
24
|
console.log("Usage: browser-cdp <command> [options]");
|
|
18
25
|
console.log("");
|
|
@@ -36,6 +43,11 @@ function printUsage() {
|
|
|
36
43
|
process.exit(0);
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
if (command === "--version" || command === "-v") {
|
|
47
|
+
console.log(pkg.version);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
|
|
39
51
|
if (!command || command === "--help" || command === "-h") {
|
|
40
52
|
printUsage();
|
|
41
53
|
}
|
package/package.json
CHANGED
package/start.js
CHANGED
|
@@ -137,6 +137,30 @@ try {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
// Check if browser is already running without CDP (only matters for real profile)
|
|
141
|
+
if (!isolated && browserConfig.process) {
|
|
142
|
+
try {
|
|
143
|
+
const pgrepArgs = isMac
|
|
144
|
+
? ["-x", browserConfig.process]
|
|
145
|
+
: ["-f", browserConfig.path];
|
|
146
|
+
const result = execFileSync("pgrep", pgrepArgs, { encoding: "utf8" }).trim();
|
|
147
|
+
if (result) {
|
|
148
|
+
console.error(`Error: ${browserConfig.name} is already running without CDP enabled.`);
|
|
149
|
+
console.error("");
|
|
150
|
+
console.error("When a browser is already open, launching it again just opens a new");
|
|
151
|
+
console.error("window in the existing process - the CDP flag is ignored.");
|
|
152
|
+
console.error("");
|
|
153
|
+
console.error("Options:");
|
|
154
|
+
console.error(` 1. Quit ${browserConfig.name} and run this command again`);
|
|
155
|
+
console.error(` 2. Use --isolated flag: browser-cdp start ${browserName} --isolated`);
|
|
156
|
+
console.error(" (creates separate instance, but without your cookies/logins)");
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
// pgrep returns non-zero if no match - browser not running, proceed
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
140
164
|
// Build browser arguments
|
|
141
165
|
const browserArgs = [`--remote-debugging-port=${port}`];
|
|
142
166
|
|