browser-ipc-cdp 1.4.0 → 1.5.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/lib/browser.js +10 -6
- package/lib/mcp.js +43 -5
- package/package.json +1 -1
package/lib/browser.js
CHANGED
|
@@ -396,13 +396,16 @@ function launchBrowser(browser, { port = 0, clean = false } = {}) {
|
|
|
396
396
|
|
|
397
397
|
// Wait for process to die
|
|
398
398
|
setTimeout(() => {
|
|
399
|
+
const defaultUserData = browser.userData || getBrowserPaths(browser.name).userData || '';
|
|
399
400
|
const userData = clean
|
|
400
|
-
? path.join(process.env.USERPROFILE || '', 'browser-cdp-profile')
|
|
401
|
-
:
|
|
401
|
+
? path.join(process.env.USERPROFILE || process.env.HOME || '', 'browser-cdp-profile')
|
|
402
|
+
: defaultUserData;
|
|
402
403
|
|
|
403
404
|
// Clean DevToolsActivePort
|
|
404
|
-
|
|
405
|
-
|
|
405
|
+
if (userData) {
|
|
406
|
+
const portFile = path.join(userData, 'DevToolsActivePort');
|
|
407
|
+
try { if (fs.existsSync(portFile)) fs.unlinkSync(portFile); } catch (e) {}
|
|
408
|
+
}
|
|
406
409
|
|
|
407
410
|
const args = [
|
|
408
411
|
`--remote-debugging-port=${port}`,
|
|
@@ -434,14 +437,15 @@ function launchBrowser(browser, { port = 0, clean = false } = {}) {
|
|
|
434
437
|
|
|
435
438
|
// Wait for DevToolsActivePort
|
|
436
439
|
if (port === 0) {
|
|
440
|
+
const activePortFile = userData ? path.join(userData, 'DevToolsActivePort') : null;
|
|
437
441
|
const deadline = Date.now() + 30000;
|
|
438
442
|
const check = () => {
|
|
439
443
|
if (Date.now() > deadline) {
|
|
440
444
|
return reject(new Error('Timeout esperando DevToolsActivePort'));
|
|
441
445
|
}
|
|
442
|
-
if (fs.existsSync(
|
|
446
|
+
if (activePortFile && fs.existsSync(activePortFile)) {
|
|
443
447
|
try {
|
|
444
|
-
const lines = fs.readFileSync(
|
|
448
|
+
const lines = fs.readFileSync(activePortFile, 'utf-8').trim().split('\n');
|
|
445
449
|
const detected = parseInt(lines[0].trim());
|
|
446
450
|
if (detected > 0) {
|
|
447
451
|
return resolve({ port: detected, pid: child.pid });
|
package/lib/mcp.js
CHANGED
|
@@ -52,12 +52,44 @@ function updateMcpJson(port, wslIp) {
|
|
|
52
52
|
args: ['-y', 'chrome-devtools-mcp@latest', '--browserUrl', `http://${wslIp}:${port}`],
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
//
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
];
|
|
55
|
+
// Rutas base donde buscar .mcp.json
|
|
56
|
+
const home = process.env.USERPROFILE || process.env.HOME || '';
|
|
57
|
+
const cwd = process.cwd();
|
|
58
|
+
const scriptDir = path.join(__dirname, '..');
|
|
60
59
|
|
|
60
|
+
// 1. Rutas fijas conocidas
|
|
61
|
+
const mcpPaths = new Set([
|
|
62
|
+
path.join(home, '.mcp.json'), // Home del usuario
|
|
63
|
+
path.join(cwd, '.mcp.json'), // Donde ejecuto npx
|
|
64
|
+
path.join(scriptDir, '.mcp.json'), // Carpeta del paquete IPC
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
// 2. Buscar .mcp.json existentes en subdirectorios del home (1 nivel)
|
|
68
|
+
try {
|
|
69
|
+
const homeItems = fs.readdirSync(home);
|
|
70
|
+
for (const item of homeItems) {
|
|
71
|
+
const candidate = path.join(home, item, '.mcp.json');
|
|
72
|
+
if (fs.existsSync(candidate)) {
|
|
73
|
+
mcpPaths.add(candidate);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} catch (e) {}
|
|
77
|
+
|
|
78
|
+
// 3. En Windows: buscar en Desktop y sus subcarpetas
|
|
79
|
+
const desktop = path.join(home, 'Desktop');
|
|
80
|
+
try {
|
|
81
|
+
if (fs.existsSync(desktop)) {
|
|
82
|
+
const desktopItems = fs.readdirSync(desktop);
|
|
83
|
+
for (const item of desktopItems) {
|
|
84
|
+
const candidate = path.join(desktop, item, '.mcp.json');
|
|
85
|
+
if (fs.existsSync(candidate)) {
|
|
86
|
+
mcpPaths.add(candidate);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch (e) {}
|
|
91
|
+
|
|
92
|
+
// 4. Actualizar todos los .mcp.json encontrados
|
|
61
93
|
let updated = 0;
|
|
62
94
|
for (const mcpPath of mcpPaths) {
|
|
63
95
|
try {
|
|
@@ -66,9 +98,15 @@ function updateMcpJson(port, wslIp) {
|
|
|
66
98
|
data = JSON.parse(fs.readFileSync(mcpPath, 'utf-8'));
|
|
67
99
|
}
|
|
68
100
|
if (!data.mcpServers) data.mcpServers = {};
|
|
101
|
+
|
|
102
|
+
// Solo actualizar si el archivo existe o es el home
|
|
103
|
+
const isHome = mcpPath === path.join(home, '.mcp.json');
|
|
104
|
+
if (!fs.existsSync(mcpPath) && !isHome) continue;
|
|
105
|
+
|
|
69
106
|
data.mcpServers.brave = braveEntry;
|
|
70
107
|
fs.writeFileSync(mcpPath, JSON.stringify(data, null, 2));
|
|
71
108
|
updated++;
|
|
109
|
+
log(` -> ${mcpPath}`);
|
|
72
110
|
} catch (e) {}
|
|
73
111
|
}
|
|
74
112
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-ipc-cdp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Control remoto de navegadores Chromium (Brave, Chrome, Edge) via IPC + CDP dinamico. Un comando para conectar Claude Code a tu navegador real.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"browser-ipc-cdp": "bin/cli.js"
|