browser-ipc-cdp 2.0.1 → 2.1.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.
@@ -31,12 +31,24 @@ const HOME = process.env.USERPROFILE || process.env.HOME || '';
31
31
  const LOCALAPPDATA = process.env.LOCALAPPDATA || path.join(HOME, 'AppData', 'Local');
32
32
 
33
33
  const USER_DATA_DIRS = [
34
- { name: 'brave', path: path.join(LOCALAPPDATA, 'BraveSoftware', 'Brave-Browser', 'User Data') },
35
- { name: 'chrome', path: path.join(LOCALAPPDATA, 'Google', 'Chrome', 'User Data') },
36
- { name: 'edge', path: path.join(LOCALAPPDATA, 'Microsoft', 'Edge', 'User Data') },
37
- { name: 'chromium', path: path.join(LOCALAPPDATA, 'Chromium', 'User Data') },
34
+ { name: 'brave', path: path.join(LOCALAPPDATA, 'BraveSoftware', 'Brave-Browser', 'User Data') },
35
+ { name: 'chrome', path: path.join(LOCALAPPDATA, 'Google', 'Chrome', 'User Data') },
36
+ { name: 'edge', path: path.join(LOCALAPPDATA, 'Microsoft', 'Edge', 'User Data') },
37
+ { name: 'chromium', path: path.join(LOCALAPPDATA, 'Chromium', 'User Data') },
38
+ // Profiles custom usados por skills CDP (--user-data-dir=...)
39
+ { name: 'brave-cdp', path: path.join(HOME, 'brave-cdp-profile') },
40
+ { name: 'browser-cdp', path: path.join(HOME, 'browser-cdp-profile') },
41
+ { name: 'chrome-debug', path: path.join(HOME, 'chrome-debug') },
38
42
  ];
39
43
 
44
+ // Permite agregar profiles via env var: BROWSER_CDP_EXTRA_PROFILES="C:/path1;C:/path2"
45
+ if (process.env.BROWSER_CDP_EXTRA_PROFILES) {
46
+ for (const extra of process.env.BROWSER_CDP_EXTRA_PROFILES.split(/[;:,]/)) {
47
+ const trimmed = extra.trim();
48
+ if (trimmed) USER_DATA_DIRS.push({ name: 'env-extra', path: trimmed });
49
+ }
50
+ }
51
+
40
52
  function resolveChromeDevtoolsMcpBin() {
41
53
  try {
42
54
  return require.resolve('chrome-devtools-mcp/build/src/bin/chrome-devtools-mcp.js');
@@ -91,14 +103,64 @@ function readDevToolsActivePort(userDataDir) {
91
103
  return null;
92
104
  }
93
105
 
106
+ function discoverProfilesDynamically() {
107
+ // Escanea HOME y LOCALAPPDATA buscando dirs con DevToolsActivePort
108
+ const found = [];
109
+ const seen = new Set();
110
+
111
+ function addIfHasFile(dirPath, name) {
112
+ if (!dirPath || seen.has(dirPath)) return;
113
+ seen.add(dirPath);
114
+ try {
115
+ if (fs.existsSync(path.join(dirPath, 'DevToolsActivePort'))) {
116
+ found.push({ name, path: dirPath });
117
+ }
118
+ } catch {}
119
+ }
120
+
121
+ // 1. Profiles hardcoded conocidos
122
+ for (const ud of USER_DATA_DIRS) addIfHasFile(ud.path, ud.name);
123
+
124
+ // 2. Escanear HOME por dirs *-profile, *-cdp*, *-debug
125
+ try {
126
+ for (const entry of fs.readdirSync(HOME, { withFileTypes: true })) {
127
+ if (!entry.isDirectory()) continue;
128
+ if (/profile|cdp|debug|chromium/i.test(entry.name)) {
129
+ addIfHasFile(path.join(HOME, entry.name), `home/${entry.name}`);
130
+ }
131
+ }
132
+ } catch {}
133
+
134
+ // 3. Escanear LOCALAPPDATA niveles 1-2 buscando "User Data"
135
+ try {
136
+ for (const entry of fs.readdirSync(LOCALAPPDATA, { withFileTypes: true })) {
137
+ if (!entry.isDirectory()) continue;
138
+ const sub = path.join(LOCALAPPDATA, entry.name);
139
+ addIfHasFile(path.join(sub, 'User Data'), `local/${entry.name}/User Data`);
140
+ try {
141
+ for (const sub2 of fs.readdirSync(sub, { withFileTypes: true })) {
142
+ if (!sub2.isDirectory()) continue;
143
+ addIfHasFile(path.join(sub, sub2.name, 'User Data'), `local/${entry.name}/${sub2.name}/User Data`);
144
+ }
145
+ } catch {}
146
+ }
147
+ } catch {}
148
+
149
+ return found;
150
+ }
151
+
94
152
  async function tryDevToolsActivePort() {
95
- for (const ud of USER_DATA_DIRS) {
153
+ const profiles = discoverProfilesDynamically();
154
+ log(`Profiles con DevToolsActivePort: ${profiles.length}`);
155
+ for (const ud of profiles) {
96
156
  const port = readDevToolsActivePort(ud.path);
97
157
  if (!port) continue;
98
158
  const version = await testCdp(`http://127.0.0.1:${port}`, 1500);
99
159
  if (version) {
100
160
  log(`DevToolsActivePort hit: ${ud.name} -> :${port}`);
101
161
  return { port, version };
162
+ } else {
163
+ log(`Stale port :${port} en ${ud.name}`);
102
164
  }
103
165
  }
104
166
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-ipc-cdp",
3
- "version": "2.0.1",
3
+ "version": "2.1.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",