electron-dev-bridge 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.
@@ -79,6 +79,9 @@ export function createLifecycleTools(ctx) {
79
79
  },
80
80
  handler: async ({ port } = {}) => {
81
81
  const targetPort = port || appConfig.debugPort || 9229;
82
+ if (bridge.connected) {
83
+ return toolResult({ connected: true, port: targetPort, message: 'Already connected' });
84
+ }
82
85
  bridge.setPort(targetPort);
83
86
  await bridge.connect();
84
87
  attachDevtoolsStore(bridge, state);
@@ -12,6 +12,8 @@ export class CdpBridge {
12
12
  this.port = port;
13
13
  }
14
14
  async connect(maxRetries = 10) {
15
+ if (this.client)
16
+ return;
15
17
  let lastError;
16
18
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
17
19
  try {
@@ -20,17 +22,19 @@ export class CdpBridge {
20
22
  if (!page)
21
23
  throw new Error('No page target found among CDP targets');
22
24
  this.client = await CDP({ target: page, port: this.port });
23
- await this.client.Runtime.enable();
24
- await this.client.DOM.enable();
25
- await this.client.Page.enable();
26
- await this.client.Network.enable();
25
+ await Promise.all([
26
+ this.client.Runtime.enable(),
27
+ this.client.DOM.enable(),
28
+ this.client.Page.enable(),
29
+ this.client.Network.enable(),
30
+ ]);
27
31
  this.client.on('disconnect', () => { this.client = null; });
28
32
  return;
29
33
  }
30
34
  catch (err) {
31
35
  lastError = err;
32
36
  if (attempt < maxRetries) {
33
- await new Promise(r => setTimeout(r, 1000));
37
+ await new Promise(r => setTimeout(r, 300));
34
38
  }
35
39
  }
36
40
  }
@@ -128,8 +128,16 @@ export async function startServer(config) {
128
128
  cdpToolDefs = cdpToolDefs.filter(t => allowed.has(t.definition.name));
129
129
  }
130
130
  }
131
+ if (config.cdpTools) {
132
+ try {
133
+ await bridge.connect();
134
+ }
135
+ catch {
136
+ // App may not be running yet — tools will prompt to connect
137
+ }
138
+ }
131
139
  const resources = buildResources(config);
132
- const server = new Server({ name: config.app.name, version: '0.1.0' }, { capabilities: {
140
+ const server = new Server({ name: config.app.name, version: '0.2.0' }, { capabilities: {
133
141
  tools: {},
134
142
  ...(resources.length > 0 ? { resources: {} } : {}),
135
143
  } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-dev-bridge",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Expose Electron IPC handlers as MCP tools for Claude Code, with 22 built-in CDP tools for DOM automation",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",