n8n-nodes-smart-browser-automation 1.1.13 → 1.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.
@@ -75,14 +75,14 @@ class BrowserSessionManager {
75
75
  throw new Error('MCP client not initialized. Please configure credentials first.');
76
76
  }
77
77
  try {
78
- // Only log in development/debug mode
79
- if (process.env.NODE_ENV !== 'production' && process.env.DEBUG) {
80
- console.log(`[MCP] Calling tool "${toolName}" with args:`, JSON.stringify(toolArgs || {}));
81
- }
78
+ // Log tool call for debugging
79
+ console.log(`[MCP] Calling tool "${toolName}" with args:`, JSON.stringify(toolArgs || {}));
82
80
  const result = await this.mcpClient.callTool({
83
81
  name: toolName,
84
82
  arguments: toolArgs || {}
85
83
  });
84
+ // Log the response for debugging
85
+ console.log(`[MCP] Tool "${toolName}" response:`, JSON.stringify(result, null, 2));
86
86
  return result;
87
87
  }
88
88
  catch (error) {
@@ -27,81 +27,11 @@ class SmartBrowserAutomation {
27
27
  ],
28
28
  usableAsTool: true,
29
29
  properties: [
30
- {
31
- displayName: 'Mode',
32
- name: 'mode',
33
- type: 'options',
34
- noDataExpression: true,
35
- options: [
36
- {
37
- name: 'AI Agent (Auto)',
38
- value: 'aiAgent',
39
- description: 'Let AI decide which tools to use - use this with AI Agent node',
40
- },
41
- {
42
- name: 'Manual',
43
- value: 'manual',
44
- description: 'Manually select tool and provide arguments',
45
- },
46
- ],
47
- default: 'aiAgent',
48
- description: 'How to execute browser automation',
49
- },
50
- {
51
- displayName: 'Tool Name or ID',
52
- name: 'toolName',
53
- type: 'options',
54
- typeOptions: {
55
- loadOptionsMethod: 'getAvailableTools',
56
- },
57
- displayOptions: {
58
- show: {
59
- mode: ['manual'],
60
- },
61
- },
62
- default: 'browser_connect_cdp',
63
- description: 'Select the browser automation tool to execute. Choose "Connect to Browser (CDP)" to initialize/switch browser sessions. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
64
- required: true,
65
- },
66
- {
67
- displayName: 'CDP Endpoint',
68
- name: 'cdpUrl',
69
- type: 'string',
70
- displayOptions: {
71
- show: {
72
- mode: ['manual'],
73
- toolName: ['browser_connect_cdp'],
74
- },
75
- },
76
- default: '',
77
- placeholder: 'wss://gridnew.doingerp.com/devtools/...',
78
- description: 'The wss:// or http:// endpoint for the browser CDP connection',
79
- },
80
- {
81
- displayName: 'Tool Arguments',
82
- name: 'toolArgs',
83
- type: 'json',
84
- displayOptions: {
85
- show: {
86
- mode: ['manual'],
87
- },
88
- hide: {
89
- toolName: ['browser_connect_cdp'],
90
- },
91
- },
92
- default: '{}',
93
- description: 'Arguments for the selected tool in JSON format',
94
- },
95
30
  {
96
31
  displayName: 'Operation',
97
32
  name: 'operation',
98
33
  type: 'options',
99
34
  noDataExpression: true,
100
- displayOptions: {
101
- show: {
102
- mode: ['aiAgent'],
103
- },
104
- },
105
35
  options: [
106
36
  {
107
37
  name: 'Initialize Session',
@@ -124,11 +54,6 @@ class SmartBrowserAutomation {
124
54
  type: 'collection',
125
55
  placeholder: 'Add Option',
126
56
  default: {},
127
- displayOptions: {
128
- show: {
129
- mode: ['aiAgent'],
130
- },
131
- },
132
57
  options: [
133
58
  {
134
59
  displayName: 'CDP Endpoint',
@@ -198,17 +123,27 @@ class SmartBrowserAutomation {
198
123
  const routerTool = {
199
124
  name: 'browser_tool',
200
125
  displayName: 'Browser Action',
201
- description: `Perform browser automation actions.
202
- USAGE EXAMPLES:
203
- - Navigate: action='navigate', params={ "url": "https://..." }
204
- - Click: action='click', params={ "selector": "button.submit" }
205
- - Type: action='type', params={ "selector": "#input", "text": "hello" }
206
- - Scroll: action='scroll_to', params={ "selector": "footer" }
207
- - Get Text: action='get_text', params={ "selector": ".content" }
208
- - Screenshot: action='take_screenshot', params={}
209
-
210
- Available actions: navigate, click, type, press_key, scroll_to, get_text, take_screenshot, evaluate, etc.
211
- Supported Params depend on the action.`,
126
+ description: `Execute browser automation actions. ALWAYS use this tool for browser interactions.
127
+
128
+ WHEN TO USE:
129
+ User wants to visit/open/go to a website → action='navigate'
130
+ User wants to click something action='click'
131
+ User wants to type/enter text → action='type'
132
+ User wants to read/get text from page → action='snapshot' or action='get_text'
133
+ User wants a screenshot → action='take_screenshot'
134
+
135
+ REQUIRED PARAMETERS:
136
+ action: The action name (navigate, click, type, snapshot, take_screenshot, etc.)
137
+ • params: JSON object with action-specific parameters
138
+
139
+ EXAMPLES:
140
+ 1. Navigate: { "action": "navigate", "params": { "url": "https://example.com" } }
141
+ 2. Click: { "action": "click", "params": { "element": "button text", "ref": "..." } }
142
+ 3. Type: { "action": "type", "params": { "element": "input field", "ref": "...", "text": "hello" } }
143
+ 4. Snapshot: { "action": "snapshot", "params": {} }
144
+ 5. Screenshot: { "action": "take_screenshot", "params": {} }
145
+
146
+ IMPORTANT: For navigate action, params must include "url" key.`,
212
147
  properties: [
213
148
  {
214
149
  displayName: 'Action Name',
@@ -234,6 +169,7 @@ class SmartBrowserAutomation {
234
169
  if (input.action === 'connect_cdp' || input.action === 'browser_connect_cdp') {
235
170
  const endpoint = input.params?.endpoint;
236
171
  if (endpoint) {
172
+ console.log(`[Router] Connecting to CDP: ${endpoint}`);
237
173
  await sessionManager.initialize(credentials.mcpEndpoint, true, endpoint);
238
174
  return {
239
175
  content: [{ type: 'text', text: `Connected to browser at ${endpoint}.` }],
@@ -243,10 +179,10 @@ class SmartBrowserAutomation {
243
179
  };
244
180
  }
245
181
  }
246
- // Auto-initialize if possible (blindly)
247
- await sessionManager.initialize(credentials.mcpEndpoint, credentials.browserMode === 'cdp', credentials.cdpEndpoint);
248
- }
249
- // Normalize action name
182
+ // Session not ready and no explicit connection requested
183
+ // This shouldn't happen - session should be initialized first
184
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Browser session not initialized. Please connect to browser first using Initialize Session or connect_cdp action.');
185
+ } // Normalize action name
250
186
  let toolName = input.action;
251
187
  if (!toolName.startsWith('browser_') && toolName !== 'connect_cdp') {
252
188
  toolName = `browser_${toolName}`;
@@ -314,106 +250,58 @@ class SmartBrowserAutomation {
314
250
  const returnData = [];
315
251
  const credentials = await this.getCredentials('smartBrowserAutomationApi');
316
252
  const sessionManager = BrowserSessionManager_1.default.getInstance();
317
- const mode = this.getNodeParameter('mode', 0);
318
253
  for (let i = 0; i < items.length; i++) {
319
254
  try {
320
255
  const options = this.getNodeParameter('options', i, {});
321
256
  const verbose = options.verbose || false;
322
- if (mode === 'manual') {
323
- // Manual mode: User selects tool and provides arguments
324
- const toolName = this.getNodeParameter('toolName', i);
325
- // Special case: Manual Browser Connection
326
- if (toolName === 'browser_connect_cdp') {
327
- const endpoint = this.getNodeParameter('cdpUrl', i);
328
- if (!endpoint) {
329
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'CDP Endpoint URL is required for browser_connect_cdp');
330
- }
257
+ const operation = this.getNodeParameter('operation', i);
258
+ if (operation === 'initialize') {
259
+ const cdpUrl = credentials.cdpEndpoint;
260
+ await sessionManager.initialize(credentials.mcpEndpoint, true, cdpUrl);
261
+ // New logic: Auto-call browser_connect_cdp tool if a URL is provided
262
+ if (options.cdpUrl) {
331
263
  if (verbose) {
332
- console.log(`Connecting to browser CDP: ${endpoint}`);
264
+ console.log(`Auto-calling 'browser_connect_cdp' with endpoint: ${options.cdpUrl}`);
333
265
  }
334
- await sessionManager.initialize(credentials.mcpEndpoint, true, endpoint);
335
- returnData.push({
336
- json: {
337
- success: true,
338
- message: `Connected to browser at ${endpoint}`,
339
- timestamp: new Date().toISOString()
340
- },
341
- pairedItem: i,
342
- });
343
- continue;
344
- }
345
- const toolArgsStr = this.getNodeParameter('toolArgs', i);
346
- let toolArgs;
347
- try {
348
- toolArgs = JSON.parse(toolArgsStr);
349
- }
350
- catch (error) {
351
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid JSON in Tool Arguments: ${error.message}`);
352
- }
353
- // Initialize session if not ready
354
- if (!sessionManager.isReady()) {
355
- await sessionManager.initialize(credentials.mcpEndpoint, credentials.browserMode === 'cdp', credentials.cdpEndpoint);
356
- }
357
- if (verbose) {
358
- console.log(`Executing tool: ${toolName} with args:`, toolArgs);
359
- }
360
- const result = await sessionManager.callTool(toolName, toolArgs);
361
- returnData.push({
362
- json: result,
363
- pairedItem: i,
364
- });
365
- }
366
- else {
367
- // AI Agent mode: Just initialize or close
368
- const operation = this.getNodeParameter('operation', i);
369
- if (operation === 'initialize') {
370
- const cdpUrl = credentials.cdpEndpoint;
371
- await sessionManager.initialize(credentials.mcpEndpoint, true, cdpUrl);
372
- // New logic: Auto-call browser_connect_cdp tool if a URL is provided
373
- if (options.cdpUrl) {
374
- if (verbose) {
375
- console.log(`Auto-calling 'browser_connect_cdp' with endpoint: ${options.cdpUrl}`);
376
- }
377
- try {
378
- const connectionResult = await sessionManager.callTool('browser_connect_cdp', { endpoint: options.cdpUrl });
379
- // Return only the connection result, no extra messages
380
- returnData.push({
381
- json: connectionResult,
382
- pairedItem: i,
383
- });
384
- }
385
- catch (error) {
386
- returnData.push({
387
- json: {
388
- success: false,
389
- error: `Failed to connect: ${error.message}`
390
- },
391
- pairedItem: i,
392
- });
393
- }
266
+ try {
267
+ const connectionResult = await sessionManager.callTool('browser_connect_cdp', { endpoint: options.cdpUrl });
268
+ // Return only the connection result, no extra messages
269
+ returnData.push({
270
+ json: connectionResult,
271
+ pairedItem: i,
272
+ });
394
273
  }
395
- else {
396
- // No CDP URL provided
274
+ catch (error) {
397
275
  returnData.push({
398
276
  json: {
399
- success: true,
400
- message: 'MCP session initialized (no browser connection)'
277
+ success: false,
278
+ error: `Failed to connect: ${error.message}`
401
279
  },
402
280
  pairedItem: i,
403
281
  });
404
282
  }
405
283
  }
406
- else if (operation === 'close') {
407
- await sessionManager.close();
284
+ else {
285
+ // No CDP URL provided
408
286
  returnData.push({
409
287
  json: {
410
288
  success: true,
411
- message: 'Browser session closed',
289
+ message: 'MCP session initialized (no browser connection)'
412
290
  },
413
291
  pairedItem: i,
414
292
  });
415
293
  }
416
294
  }
295
+ else if (operation === 'close') {
296
+ await sessionManager.close();
297
+ returnData.push({
298
+ json: {
299
+ success: true,
300
+ message: 'Browser session closed',
301
+ },
302
+ pairedItem: i,
303
+ });
304
+ }
417
305
  }
418
306
  catch (error) {
419
307
  if (this.continueOnFail()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-smart-browser-automation",
3
- "version": "1.1.13",
3
+ "version": "1.2.0",
4
4
  "description": "n8n node for AI-driven browser automation using MCP",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",